Show More
@@ -2533,7 +2533,8 b' class InteractiveShell(SingletonConfigurable):' | |||||
2533 | except: |
|
2533 | except: | |
2534 | if kw['raise_exceptions']: |
|
2534 | if kw['raise_exceptions']: | |
2535 | raise |
|
2535 | raise | |
2536 | self.showtraceback() |
|
2536 | # tb offset is 2 because we wrap execfile | |
|
2537 | self.showtraceback(tb_offset=2) | |||
2537 |
|
2538 | |||
2538 | def safe_execfile_ipy(self, fname): |
|
2539 | def safe_execfile_ipy(self, fname): | |
2539 | """Like safe_execfile, but for .ipy or .ipynb files with IPython syntax. |
|
2540 | """Like safe_execfile, but for .ipy or .ipynb files with IPython syntax. |
@@ -28,6 +28,7 b' from nose import SkipTest' | |||||
28 | from IPython.testing import decorators as dec |
|
28 | from IPython.testing import decorators as dec | |
29 | from IPython.testing import tools as tt |
|
29 | from IPython.testing import tools as tt | |
30 | from IPython.utils import py3compat |
|
30 | from IPython.utils import py3compat | |
|
31 | from IPython.utils.io import capture_output | |||
31 | from IPython.utils.tempdir import TemporaryDirectory |
|
32 | from IPython.utils.tempdir import TemporaryDirectory | |
32 | from IPython.core import debugger |
|
33 | from IPython.core import debugger | |
33 |
|
34 | |||
@@ -474,3 +475,40 b' def test_run__name__():' | |||||
474 |
|
475 | |||
475 | _ip.magic('run -n {}'.format(path)) |
|
476 | _ip.magic('run -n {}'.format(path)) | |
476 | nt.assert_equal(_ip.user_ns.pop('q'), 'foo') |
|
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 |
@@ -181,9 +181,6 b' else:' | |||||
181 | def MethodType(func, instance): |
|
181 | def MethodType(func, instance): | |
182 | return types.MethodType(func, instance, type(instance)) |
|
182 | return types.MethodType(func, instance, type(instance)) | |
183 |
|
183 | |||
184 | # don't override system execfile on 2.x: |
|
|||
185 | execfile = execfile |
|
|||
186 |
|
||||
187 | def doctest_refactor_print(func_or_str): |
|
184 | def doctest_refactor_print(func_or_str): | |
188 | return func_or_str |
|
185 | return func_or_str | |
189 |
|
186 |
General Comments 0
You need to be logged in to leave comments.
Login now