##// END OF EJS Templates
test traceback offset for %run and script
MinRK -
Show More
@@ -28,6 +28,7 b' from nose import SkipTest'
28 28 from IPython.testing import decorators as dec
29 29 from IPython.testing import tools as tt
30 30 from IPython.utils import py3compat
31 from IPython.utils.io import capture_output
31 32 from IPython.utils.tempdir import TemporaryDirectory
32 33 from IPython.core import debugger
33 34
@@ -474,3 +475,40 b' def test_run__name__():'
474 475
475 476 _ip.magic('run -n {}'.format(path))
476 477 nt.assert_equal(_ip.user_ns.pop('q'), 'foo')
478
479 def test_run_tb():
480 """Test traceback offset in %run"""
481 with TemporaryDirectory() as td:
482 path = pjoin(td, 'foo.py')
483 with open(path, 'w') as f:
484 f.write('\n'.join([
485 "def foo():",
486 " return bar()",
487 "def bar():",
488 " raise RuntimeError('hello!')",
489 "foo()",
490 ]))
491 with capture_output() as io:
492 _ip.magic('run {}'.format(path))
493 out = io.stdout
494 nt.assert_not_in("execfile", out)
495 nt.assert_in("RuntimeError", out)
496 nt.assert_equal(out.count("---->"), 3)
497
498 def test_script_tb():
499 """Test traceback offset in `ipython script.py`"""
500 with TemporaryDirectory() as td:
501 path = pjoin(td, 'foo.py')
502 with open(path, 'w') as f:
503 f.write('\n'.join([
504 "def foo():",
505 " return bar()",
506 "def bar():",
507 " raise RuntimeError('hello!')",
508 "foo()",
509 ]))
510 out, err = tt.ipexec(path)
511 nt.assert_not_in("execfile", out)
512 nt.assert_in("RuntimeError", out)
513 nt.assert_equal(out.count("---->"), 3)
514
General Comments 0
You need to be logged in to leave comments. Login now