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