##// END OF EJS Templates
Fix state leakage and speedup in test-suite...
Matthias Bussonnier -
Show More
@@ -35,7 +35,6 b' from IPython.utils.io import capture_output'
35 35 from IPython.utils.tempdir import TemporaryDirectory
36 36 from IPython.core import debugger
37 37
38
39 38 def doctest_refbug():
40 39 """Very nasty problem with references held by multiple runs of a script.
41 40 See: https://github.com/ipython/ipython/issues/141
@@ -537,6 +536,8 b' def test_run_tb():'
537 536 nt.assert_not_in("execfile", out)
538 537 nt.assert_in("RuntimeError", out)
539 538 nt.assert_equal(out.count("---->"), 3)
539 del ip.user_ns['bar']
540 del ip.user_ns['foo']
540 541
541 542 @dec.knownfailureif(sys.platform == 'win32', "writes to io.stdout aren't captured on Windows")
542 543 def test_script_tb():
@@ -10,7 +10,8 b' import traceback'
10 10 import unittest
11 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 17 from IPython.testing import tools as tt
@@ -18,8 +19,6 b' from IPython.testing.decorators import onlyif_unicode_paths'
18 19 from IPython.utils.syspathcontext import prepended_to_syspath
19 20 from IPython.utils.tempdir import TemporaryDirectory
20 21
21 ip = get_ipython()
22
23 22 file_1 = """1
24 23 2
25 24 3
@@ -31,6 +30,30 b' file_2 = """def f():'
31 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 57 class ChangedPyFileTest(unittest.TestCase):
35 58 def test_changing_py_file(self):
36 59 """Traceback produced if the line where the error occurred is missing?
@@ -200,6 +223,8 b' bar()'
200 223 # Assert syntax error during runtime generate stacktrace
201 224 with tt.AssertPrints(["foo()", "bar()"]):
202 225 ip.run_cell(syntax_error_at_runtime)
226 del ip.user_ns['bar']
227 del ip.user_ns['foo']
203 228
204 229 def test_changing_py_file(self):
205 230 with TemporaryDirectory() as td:
@@ -302,14 +327,17 b' def r3o2():'
302 327 with tt.AssertNotPrints("frames repeated"):
303 328 ip.run_cell("non_recurs()")
304 329
330 @recursionlimit(65)
305 331 def test_recursion_one_frame(self):
306 332 with tt.AssertPrints("1 frames repeated"):
307 333 ip.run_cell("r1()")
308 334
335 @recursionlimit(65)
309 336 def test_recursion_three_frames(self):
310 337 with tt.AssertPrints("3 frames repeated"):
311 338 ip.run_cell("r3o2()")
312 339
340 @recursionlimit(65)
313 341 def test_find_recursion(self):
314 342 captured = []
315 343 def capture_exc(*args, **kwargs):
@@ -137,6 +137,12 b' INDENT_SIZE = 8'
137 137 # to users of ultratb who are NOT running inside ipython.
138 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 147 # Code begins
142 148
@@ -431,7 +437,7 b' def is_recursion_error(etype, value, records):'
431 437 # a recursion error.
432 438 return (etype is recursion_error_type) \
433 439 and "recursion" in str(value).lower() \
434 and len(records) > 500
440 and len(records) > _FRAME_RECURSION_LIMIT
435 441
436 442 def find_recursion(etype, value, records):
437 443 """Identify the repeating stack frames from a RecursionError traceback
@@ -3,10 +3,13 b' import tempfile, os'
3 3 from traitlets.config.loader import Config
4 4 import nose.tools as nt
5 5
6 ip = get_ipython()
6
7 def setup_module():
7 8 ip.magic('load_ext storemagic')
8 9
9 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 13 ip.user_ns['foo'] = 78
11 14 ip.magic('alias bar echo "hello"')
12 15 tmpd = tempfile.mkdtemp()
General Comments 0
You need to be logged in to leave comments. Login now