Show More
@@ -35,7 +35,6 b' from IPython.utils.io import capture_output' | |||||
35 | from IPython.utils.tempdir import TemporaryDirectory |
|
35 | from IPython.utils.tempdir import TemporaryDirectory | |
36 | from IPython.core import debugger |
|
36 | from IPython.core import debugger | |
37 |
|
37 | |||
38 |
|
||||
39 | def doctest_refbug(): |
|
38 | def doctest_refbug(): | |
40 | """Very nasty problem with references held by multiple runs of a script. |
|
39 | """Very nasty problem with references held by multiple runs of a script. | |
41 | See: https://github.com/ipython/ipython/issues/141 |
|
40 | See: https://github.com/ipython/ipython/issues/141 | |
@@ -537,6 +536,8 b' def test_run_tb():' | |||||
537 | nt.assert_not_in("execfile", out) |
|
536 | nt.assert_not_in("execfile", out) | |
538 | nt.assert_in("RuntimeError", out) |
|
537 | nt.assert_in("RuntimeError", out) | |
539 | nt.assert_equal(out.count("---->"), 3) |
|
538 | nt.assert_equal(out.count("---->"), 3) | |
|
539 | del ip.user_ns['bar'] | |||
|
540 | del ip.user_ns['foo'] | |||
540 |
|
541 | |||
541 | @dec.knownfailureif(sys.platform == 'win32', "writes to io.stdout aren't captured on Windows") |
|
542 | @dec.knownfailureif(sys.platform == 'win32', "writes to io.stdout aren't captured on Windows") | |
542 | def test_script_tb(): |
|
543 | def test_script_tb(): |
@@ -10,7 +10,8 b' import traceback' | |||||
10 | import unittest |
|
10 | import unittest | |
11 | from unittest import mock |
|
11 | from unittest import mock | |
12 |
|
12 | |||
13 | from ..ultratb import ColorTB, VerboseTB, find_recursion |
|
13 | import IPython.core.ultratb as ultratb | |
|
14 | from IPython.core.ultratb import ColorTB, VerboseTB, find_recursion | |||
14 |
|
15 | |||
15 |
|
16 | |||
16 | from IPython.testing import tools as tt |
|
17 | from IPython.testing import tools as tt | |
@@ -18,8 +19,6 b' from IPython.testing.decorators import onlyif_unicode_paths' | |||||
18 | from IPython.utils.syspathcontext import prepended_to_syspath |
|
19 | from IPython.utils.syspathcontext import prepended_to_syspath | |
19 | from IPython.utils.tempdir import TemporaryDirectory |
|
20 | from IPython.utils.tempdir import TemporaryDirectory | |
20 |
|
21 | |||
21 | ip = get_ipython() |
|
|||
22 |
|
||||
23 | file_1 = """1 |
|
22 | file_1 = """1 | |
24 | 2 |
|
23 | 2 | |
25 | 3 |
|
24 | 3 | |
@@ -31,6 +30,30 b' file_2 = """def f():' | |||||
31 | 1/0 |
|
30 | 1/0 | |
32 | """ |
|
31 | """ | |
33 |
|
32 | |||
|
33 | ||||
|
34 | def recursionlimit(frames): | |||
|
35 | """ | |||
|
36 | decorator to set the recursion limit temporarily | |||
|
37 | """ | |||
|
38 | ||||
|
39 | def inner(test_function): | |||
|
40 | def wrapper(*args, **kwargs): | |||
|
41 | _orig_rec_limit = ultratb._FRAME_RECURSION_LIMIT | |||
|
42 | ultratb._FRAME_RECURSION_LIMIT = frames - 50 | |||
|
43 | ||||
|
44 | rl = sys.getrecursionlimit() | |||
|
45 | sys.setrecursionlimit(frames) | |||
|
46 | try: | |||
|
47 | return test_function(*args, **kwargs) | |||
|
48 | finally: | |||
|
49 | sys.setrecursionlimit(rl) | |||
|
50 | ultratb._FRAME_RECURSION_LIMIT = _orig_rec_limit | |||
|
51 | ||||
|
52 | return wrapper | |||
|
53 | ||||
|
54 | return inner | |||
|
55 | ||||
|
56 | ||||
34 | class ChangedPyFileTest(unittest.TestCase): |
|
57 | class ChangedPyFileTest(unittest.TestCase): | |
35 | def test_changing_py_file(self): |
|
58 | def test_changing_py_file(self): | |
36 | """Traceback produced if the line where the error occurred is missing? |
|
59 | """Traceback produced if the line where the error occurred is missing? | |
@@ -200,6 +223,8 b' bar()' | |||||
200 | # Assert syntax error during runtime generate stacktrace |
|
223 | # Assert syntax error during runtime generate stacktrace | |
201 | with tt.AssertPrints(["foo()", "bar()"]): |
|
224 | with tt.AssertPrints(["foo()", "bar()"]): | |
202 | ip.run_cell(syntax_error_at_runtime) |
|
225 | ip.run_cell(syntax_error_at_runtime) | |
|
226 | del ip.user_ns['bar'] | |||
|
227 | del ip.user_ns['foo'] | |||
203 |
|
228 | |||
204 | def test_changing_py_file(self): |
|
229 | def test_changing_py_file(self): | |
205 | with TemporaryDirectory() as td: |
|
230 | with TemporaryDirectory() as td: | |
@@ -302,14 +327,17 b' def r3o2():' | |||||
302 | with tt.AssertNotPrints("frames repeated"): |
|
327 | with tt.AssertNotPrints("frames repeated"): | |
303 | ip.run_cell("non_recurs()") |
|
328 | ip.run_cell("non_recurs()") | |
304 |
|
329 | |||
|
330 | @recursionlimit(65) | |||
305 | def test_recursion_one_frame(self): |
|
331 | def test_recursion_one_frame(self): | |
306 | with tt.AssertPrints("1 frames repeated"): |
|
332 | with tt.AssertPrints("1 frames repeated"): | |
307 | ip.run_cell("r1()") |
|
333 | ip.run_cell("r1()") | |
308 |
|
334 | |||
|
335 | @recursionlimit(65) | |||
309 | def test_recursion_three_frames(self): |
|
336 | def test_recursion_three_frames(self): | |
310 | with tt.AssertPrints("3 frames repeated"): |
|
337 | with tt.AssertPrints("3 frames repeated"): | |
311 | ip.run_cell("r3o2()") |
|
338 | ip.run_cell("r3o2()") | |
312 |
|
339 | |||
|
340 | @recursionlimit(65) | |||
313 | def test_find_recursion(self): |
|
341 | def test_find_recursion(self): | |
314 | captured = [] |
|
342 | captured = [] | |
315 | def capture_exc(*args, **kwargs): |
|
343 | def capture_exc(*args, **kwargs): |
@@ -137,6 +137,12 b' INDENT_SIZE = 8' | |||||
137 | # to users of ultratb who are NOT running inside ipython. |
|
137 | # to users of ultratb who are NOT running inside ipython. | |
138 | DEFAULT_SCHEME = 'NoColor' |
|
138 | DEFAULT_SCHEME = 'NoColor' | |
139 |
|
139 | |||
|
140 | ||||
|
141 | # Number of frame above which we are likely to have a recursion and will | |||
|
142 | # **attempt** to detect it. Made modifiable mostly to speedup test suite | |||
|
143 | # as detecting recursion is one of our slowest test | |||
|
144 | _FRAME_RECURSION_LIMIT = 500 | |||
|
145 | ||||
140 | # --------------------------------------------------------------------------- |
|
146 | # --------------------------------------------------------------------------- | |
141 | # Code begins |
|
147 | # Code begins | |
142 |
|
148 | |||
@@ -431,7 +437,7 b' def is_recursion_error(etype, value, records):' | |||||
431 | # a recursion error. |
|
437 | # a recursion error. | |
432 | return (etype is recursion_error_type) \ |
|
438 | return (etype is recursion_error_type) \ | |
433 | and "recursion" in str(value).lower() \ |
|
439 | and "recursion" in str(value).lower() \ | |
434 |
and len(records) > |
|
440 | and len(records) > _FRAME_RECURSION_LIMIT | |
435 |
|
441 | |||
436 | def find_recursion(etype, value, records): |
|
442 | def find_recursion(etype, value, records): | |
437 | """Identify the repeating stack frames from a RecursionError traceback |
|
443 | """Identify the repeating stack frames from a RecursionError traceback |
@@ -3,10 +3,13 b' import tempfile, os' | |||||
3 | from traitlets.config.loader import Config |
|
3 | from traitlets.config.loader import Config | |
4 | import nose.tools as nt |
|
4 | import nose.tools as nt | |
5 |
|
5 | |||
6 | ip = get_ipython() |
|
6 | ||
|
7 | def setup_module(): | |||
7 | ip.magic('load_ext storemagic') |
|
8 | ip.magic('load_ext storemagic') | |
8 |
|
9 | |||
9 | def test_store_restore(): |
|
10 | def test_store_restore(): | |
|
11 | assert 'bar' not in ip.user_ns, "Error: some other test leaked `bar` in user_ns" | |||
|
12 | assert 'foo' not in ip.user_ns, "Error: some other test leaked `foo` in user_ns" | |||
10 | ip.user_ns['foo'] = 78 |
|
13 | ip.user_ns['foo'] = 78 | |
11 | ip.magic('alias bar echo "hello"') |
|
14 | ip.magic('alias bar echo "hello"') | |
12 | tmpd = tempfile.mkdtemp() |
|
15 | tmpd = tempfile.mkdtemp() |
General Comments 0
You need to be logged in to leave comments.
Login now