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