##// END OF EJS Templates
capture_output does not respect trailing semicolon (#13940)...
Matthias Bussonnier -
r28128:75ecfe93 merge
parent child Browse files
Show More
@@ -47,6 +47,7 b' from IPython.utils.ipstruct import Struct'
47 from IPython.utils.module_paths import find_mod
47 from IPython.utils.module_paths import find_mod
48 from IPython.utils.path import get_py_filename, shellglob
48 from IPython.utils.path import get_py_filename, shellglob
49 from IPython.utils.timing import clock, clock2
49 from IPython.utils.timing import clock, clock2
50 from IPython.core.displayhook import DisplayHook
50
51
51 #-----------------------------------------------------------------------------
52 #-----------------------------------------------------------------------------
52 # Magic implementation classes
53 # Magic implementation classes
@@ -1461,7 +1462,10 b' class ExecutionMagics(Magics):'
1461 disp = not args.no_display
1462 disp = not args.no_display
1462 with capture_output(out, err, disp) as io:
1463 with capture_output(out, err, disp) as io:
1463 self.shell.run_cell(cell)
1464 self.shell.run_cell(cell)
1464 if args.output:
1465 if DisplayHook.semicolon_at_end_of_expression(cell):
1466 if args.output in self.shell.user_ns:
1467 del self.shell.user_ns[args.output]
1468 elif args.output:
1465 self.shell.user_ns[args.output] = io
1469 self.shell.user_ns[args.output] = io
1466
1470
1467 def parse_breakpoint(text, current_file):
1471 def parse_breakpoint(text, current_file):
@@ -530,6 +530,25 b' def test_time_local_ns():'
530 del ip.user_ns["myvar"]
530 del ip.user_ns["myvar"]
531
531
532
532
533 # Test %%capture magic. Added to test issue #13926
534 def test_capture():
535 ip = get_ipython()
536
537 # Test %%capture nominal case
538 ip.run_cell("%%capture abc\n1+2")
539 with tt.AssertPrints("True", suppress=False):
540 ip.run_cell("'abc' in locals()")
541 with tt.AssertPrints("True", suppress=False):
542 ip.run_cell("'outputs' in dir(abc)")
543 with tt.AssertPrints("3", suppress=False):
544 ip.run_cell("abc.outputs[0]")
545
546 # Test %%capture with ';' at end of expression
547 ip.run_cell("%%capture abc\n7+8;")
548 with tt.AssertPrints("False", suppress=False):
549 ip.run_cell("'abc' in locals()")
550
551
533 def test_doctest_mode():
552 def test_doctest_mode():
534 "Toggle doctest_mode twice, it should be a no-op and run without error"
553 "Toggle doctest_mode twice, it should be a no-op and run without error"
535 _ip.run_line_magic("doctest_mode", "")
554 _ip.run_line_magic("doctest_mode", "")
General Comments 0
You need to be logged in to leave comments. Login now