##// END OF EJS Templates
Merge pull request #13711 from kianelbo/overrite...
Matthias Bussonnier -
r27738:f89bb706 merge
parent child Browse files
Show More
@@ -1,112 +1,112 b''
1 import sys
1 import sys
2 from IPython.testing.tools import AssertPrints, AssertNotPrints
2 from IPython.testing.tools import AssertPrints, AssertNotPrints
3 from IPython.core.displayhook import CapturingDisplayHook
3 from IPython.core.displayhook import CapturingDisplayHook
4 from IPython.utils.capture import CapturedIO
4 from IPython.utils.capture import CapturedIO
5
5
6 def test_output_displayed():
6 def test_output_displayed():
7 """Checking to make sure that output is displayed"""
7 """Checking to make sure that output is displayed"""
8
8
9 with AssertPrints('2'):
9 with AssertPrints('2'):
10 ip.run_cell('1+1', store_history=True)
10 ip.run_cell('1+1', store_history=True)
11
11
12 with AssertPrints('2'):
12 with AssertPrints('2'):
13 ip.run_cell('1+1 # comment with a semicolon;', store_history=True)
13 ip.run_cell('1+1 # comment with a semicolon;', store_history=True)
14
14
15 with AssertPrints('2'):
15 with AssertPrints('2'):
16 ip.run_cell('1+1\n#commented_out_function();', store_history=True)
16 ip.run_cell('1+1\n#commented_out_function();', store_history=True)
17
17
18
18
19 def test_output_quiet():
19 def test_output_quiet():
20 """Checking to make sure that output is quiet"""
20 """Checking to make sure that output is quiet"""
21
21
22 with AssertNotPrints('2'):
22 with AssertNotPrints('2'):
23 ip.run_cell('1+1;', store_history=True)
23 ip.run_cell('1+1;', store_history=True)
24
24
25 with AssertNotPrints('2'):
25 with AssertNotPrints('2'):
26 ip.run_cell('1+1; # comment with a semicolon', store_history=True)
26 ip.run_cell('1+1; # comment with a semicolon', store_history=True)
27
27
28 with AssertNotPrints('2'):
28 with AssertNotPrints('2'):
29 ip.run_cell('1+1;\n#commented_out_function()', store_history=True)
29 ip.run_cell('1+1;\n#commented_out_function()', store_history=True)
30
30
31 def test_underscore_no_overrite_user():
31 def test_underscore_no_overwrite_user():
32 ip.run_cell('_ = 42', store_history=True)
32 ip.run_cell('_ = 42', store_history=True)
33 ip.run_cell('1+1', store_history=True)
33 ip.run_cell('1+1', store_history=True)
34
34
35 with AssertPrints('42'):
35 with AssertPrints('42'):
36 ip.run_cell('print(_)', store_history=True)
36 ip.run_cell('print(_)', store_history=True)
37
37
38 ip.run_cell('del _', store_history=True)
38 ip.run_cell('del _', store_history=True)
39 ip.run_cell('6+6', store_history=True)
39 ip.run_cell('6+6', store_history=True)
40 with AssertPrints('12'):
40 with AssertPrints('12'):
41 ip.run_cell('_', store_history=True)
41 ip.run_cell('_', store_history=True)
42
42
43
43
44 def test_underscore_no_overrite_builtins():
44 def test_underscore_no_overwrite_builtins():
45 ip.run_cell("import gettext ; gettext.install('foo')", store_history=True)
45 ip.run_cell("import gettext ; gettext.install('foo')", store_history=True)
46 ip.run_cell('3+3', store_history=True)
46 ip.run_cell('3+3', store_history=True)
47
47
48 with AssertPrints('gettext'):
48 with AssertPrints('gettext'):
49 ip.run_cell('print(_)', store_history=True)
49 ip.run_cell('print(_)', store_history=True)
50
50
51 ip.run_cell('_ = "userset"', store_history=True)
51 ip.run_cell('_ = "userset"', store_history=True)
52
52
53 with AssertPrints('userset'):
53 with AssertPrints('userset'):
54 ip.run_cell('print(_)', store_history=True)
54 ip.run_cell('print(_)', store_history=True)
55 ip.run_cell('import builtins; del builtins._')
55 ip.run_cell('import builtins; del builtins._')
56
56
57
57
58 def test_interactivehooks_ast_modes():
58 def test_interactivehooks_ast_modes():
59 """
59 """
60 Test that ast nodes can be triggered with different modes
60 Test that ast nodes can be triggered with different modes
61 """
61 """
62 saved_mode = ip.ast_node_interactivity
62 saved_mode = ip.ast_node_interactivity
63 ip.ast_node_interactivity = 'last_expr_or_assign'
63 ip.ast_node_interactivity = 'last_expr_or_assign'
64
64
65 try:
65 try:
66 with AssertPrints('2'):
66 with AssertPrints('2'):
67 ip.run_cell('a = 1+1', store_history=True)
67 ip.run_cell('a = 1+1', store_history=True)
68
68
69 with AssertPrints('9'):
69 with AssertPrints('9'):
70 ip.run_cell('b = 1+8 # comment with a semicolon;', store_history=False)
70 ip.run_cell('b = 1+8 # comment with a semicolon;', store_history=False)
71
71
72 with AssertPrints('7'):
72 with AssertPrints('7'):
73 ip.run_cell('c = 1+6\n#commented_out_function();', store_history=True)
73 ip.run_cell('c = 1+6\n#commented_out_function();', store_history=True)
74
74
75 ip.run_cell('d = 11', store_history=True)
75 ip.run_cell('d = 11', store_history=True)
76 with AssertPrints('12'):
76 with AssertPrints('12'):
77 ip.run_cell('d += 1', store_history=True)
77 ip.run_cell('d += 1', store_history=True)
78
78
79 with AssertNotPrints('42'):
79 with AssertNotPrints('42'):
80 ip.run_cell('(u,v) = (41+1, 43-1)')
80 ip.run_cell('(u,v) = (41+1, 43-1)')
81
81
82 finally:
82 finally:
83 ip.ast_node_interactivity = saved_mode
83 ip.ast_node_interactivity = saved_mode
84
84
85 def test_interactivehooks_ast_modes_semi_suppress():
85 def test_interactivehooks_ast_modes_semi_suppress():
86 """
86 """
87 Test that ast nodes can be triggered with different modes and suppressed
87 Test that ast nodes can be triggered with different modes and suppressed
88 by semicolon
88 by semicolon
89 """
89 """
90 saved_mode = ip.ast_node_interactivity
90 saved_mode = ip.ast_node_interactivity
91 ip.ast_node_interactivity = 'last_expr_or_assign'
91 ip.ast_node_interactivity = 'last_expr_or_assign'
92
92
93 try:
93 try:
94 with AssertNotPrints('2'):
94 with AssertNotPrints('2'):
95 ip.run_cell('x = 1+1;', store_history=True)
95 ip.run_cell('x = 1+1;', store_history=True)
96
96
97 with AssertNotPrints('7'):
97 with AssertNotPrints('7'):
98 ip.run_cell('y = 1+6; # comment with a semicolon', store_history=True)
98 ip.run_cell('y = 1+6; # comment with a semicolon', store_history=True)
99
99
100 with AssertNotPrints('9'):
100 with AssertNotPrints('9'):
101 ip.run_cell('z = 1+8;\n#commented_out_function()', store_history=True)
101 ip.run_cell('z = 1+8;\n#commented_out_function()', store_history=True)
102
102
103 finally:
103 finally:
104 ip.ast_node_interactivity = saved_mode
104 ip.ast_node_interactivity = saved_mode
105
105
106 def test_capture_display_hook_format():
106 def test_capture_display_hook_format():
107 """Tests that the capture display hook conforms to the CapturedIO output format"""
107 """Tests that the capture display hook conforms to the CapturedIO output format"""
108 hook = CapturingDisplayHook(ip)
108 hook = CapturingDisplayHook(ip)
109 hook({"foo": "bar"})
109 hook({"foo": "bar"})
110 captured = CapturedIO(sys.stdout, sys.stderr, hook.outputs)
110 captured = CapturedIO(sys.stdout, sys.stderr, hook.outputs)
111 # Should not raise with RichOutput transformation error
111 # Should not raise with RichOutput transformation error
112 captured.outputs
112 captured.outputs
General Comments 0
You need to be logged in to leave comments. Login now