Show More
The requested changes are too big and content was truncated. Show full diff
@@ -0,0 +1,22 b'' | |||
|
1 | IPython can now trigger the display hook on last assignment of cells. | |
|
2 | Up until 6.0 the following code wouldn't show the value of the assigned | |
|
3 | variable:: | |
|
4 | ||
|
5 | In[1]: xyz = "something" | |
|
6 | # nothing shown | |
|
7 | ||
|
8 | You would have to actually make it the last statement:: | |
|
9 | ||
|
10 | In [2]: xyz = "something else" | |
|
11 | ... : xyz | |
|
12 | Out[2]: "something else" | |
|
13 | ||
|
14 | With the option ``InteractiveShell.ast_node_interactivity='last_expr_or_assign'`` | |
|
15 | you can now do:: | |
|
16 | ||
|
17 | In [2]: xyz = "something else" | |
|
18 | Out[2]: "something else" | |
|
19 | ||
|
20 | This option can be toggled at runtime with the ``%config`` magic, and will | |
|
21 | trigger on assignment ``a = 1``, augmented assignment ``+=``, ``-=``, ``|=`` ... | |
|
22 | as well as type annotated assignments: ``a:int = 2``. |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,55 +1,103 b'' | |||
|
1 | 1 | from IPython.testing.tools import AssertPrints, AssertNotPrints |
|
2 | 2 | |
|
3 | 3 | ip = get_ipython() |
|
4 | 4 | |
|
5 | 5 | def test_output_displayed(): |
|
6 | 6 | """Checking to make sure that output is displayed""" |
|
7 | 7 | |
|
8 | 8 | with AssertPrints('2'): |
|
9 | 9 | ip.run_cell('1+1', store_history=True) |
|
10 | 10 | |
|
11 | 11 | with AssertPrints('2'): |
|
12 | 12 | ip.run_cell('1+1 # comment with a semicolon;', store_history=True) |
|
13 | 13 | |
|
14 | 14 | with AssertPrints('2'): |
|
15 | 15 | ip.run_cell('1+1\n#commented_out_function();', store_history=True) |
|
16 | 16 | |
|
17 | 17 | |
|
18 | 18 | def test_output_quiet(): |
|
19 | 19 | """Checking to make sure that output is quiet""" |
|
20 | 20 | |
|
21 | 21 | with AssertNotPrints('2'): |
|
22 | 22 | ip.run_cell('1+1;', store_history=True) |
|
23 | 23 | |
|
24 | 24 | with AssertNotPrints('2'): |
|
25 | 25 | ip.run_cell('1+1; # comment with a semicolon', store_history=True) |
|
26 | 26 | |
|
27 | 27 | with AssertNotPrints('2'): |
|
28 | 28 | ip.run_cell('1+1;\n#commented_out_function()', store_history=True) |
|
29 | 29 | |
|
30 | 30 | def test_underscore_no_overrite_user(): |
|
31 | 31 | ip.run_cell('_ = 42', store_history=True) |
|
32 | 32 | ip.run_cell('1+1', store_history=True) |
|
33 | 33 | |
|
34 | 34 | with AssertPrints('42'): |
|
35 | 35 | ip.run_cell('print(_)', store_history=True) |
|
36 | 36 | |
|
37 | 37 | ip.run_cell('del _', store_history=True) |
|
38 | 38 | ip.run_cell('6+6', store_history=True) |
|
39 | 39 | with AssertPrints('12'): |
|
40 | 40 | ip.run_cell('_', store_history=True) |
|
41 | 41 | |
|
42 | 42 | |
|
43 | 43 | def test_underscore_no_overrite_builtins(): |
|
44 | 44 | ip.run_cell("import gettext ; gettext.install('foo')", store_history=True) |
|
45 | 45 | ip.run_cell('3+3', store_history=True) |
|
46 | 46 | |
|
47 | 47 | with AssertPrints('gettext'): |
|
48 | 48 | ip.run_cell('print(_)', store_history=True) |
|
49 | 49 | |
|
50 | 50 | ip.run_cell('_ = "userset"', store_history=True) |
|
51 | 51 | |
|
52 | 52 | with AssertPrints('userset'): |
|
53 | 53 | ip.run_cell('print(_)', store_history=True) |
|
54 | 54 | ip.run_cell('import builtins; del builtins._') |
|
55 | 55 | |
|
56 | ||
|
57 | def test_interactivehooks_ast_modes(): | |
|
58 | """ | |
|
59 | Test that ast nodes can be triggerd with different modes | |
|
60 | """ | |
|
61 | saved_mode = ip.ast_node_interactivity | |
|
62 | ip.ast_node_interactivity = 'last_expr_or_assign' | |
|
63 | ||
|
64 | try: | |
|
65 | with AssertPrints('2'): | |
|
66 | ip.run_cell('a = 1+1', store_history=True) | |
|
67 | ||
|
68 | with AssertPrints('9'): | |
|
69 | ip.run_cell('b = 1+8 # comment with a semicolon;', store_history=False) | |
|
70 | ||
|
71 | with AssertPrints('7'): | |
|
72 | ip.run_cell('c = 1+6\n#commented_out_function();', store_history=True) | |
|
73 | ||
|
74 | ip.run_cell('d = 11', store_history=True) | |
|
75 | with AssertPrints('12'): | |
|
76 | ip.run_cell('d += 1', store_history=True) | |
|
77 | ||
|
78 | with AssertNotPrints('42'): | |
|
79 | ip.run_cell('(u,v) = (41+1, 43-1)') | |
|
80 | ||
|
81 | finally: | |
|
82 | ip.ast_node_interactivity = saved_mode | |
|
83 | ||
|
84 | def test_interactivehooks_ast_modes_semi_supress(): | |
|
85 | """ | |
|
86 | Test that ast nodes can be triggerd with different modes and supressed | |
|
87 | by semicolon | |
|
88 | """ | |
|
89 | saved_mode = ip.ast_node_interactivity | |
|
90 | ip.ast_node_interactivity = 'last_expr_or_assign' | |
|
91 | ||
|
92 | try: | |
|
93 | with AssertNotPrints('2'): | |
|
94 | ip.run_cell('x = 1+1;', store_history=True) | |
|
95 | ||
|
96 | with AssertNotPrints('7'): | |
|
97 | ip.run_cell('y = 1+6; # comment with a semicolon', store_history=True) | |
|
98 | ||
|
99 | with AssertNotPrints('9'): | |
|
100 | ip.run_cell('z = 1+8;\n#commented_out_function()', store_history=True) | |
|
101 | ||
|
102 | finally: | |
|
103 | ip.ast_node_interactivity = saved_mode |
General Comments 0
You need to be logged in to leave comments.
Login now