|
3 | 3 |
|
4 | 4 |
|
5 | 5 | def test_space_can_access_user_namespace_references(ip): |
6 | | - ip.run_cell(raw_cell='x = 100') |
7 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='x') |
| 6 | + ip.run_cell(raw_cell="x = 100") |
| 7 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x") |
8 | 8 |
|
9 | 9 |
|
10 | 10 | def test_space_references_prioritized_over_user_namespace_references(ip): |
11 | | - ip.run_cell(raw_cell='x = 100') |
12 | | - ip.run_cell_magic(magic_name='space', line='tomato', |
13 | | - cell='x = 99; assert x == 99') |
| 11 | + ip.run_cell(raw_cell="x = 100") |
| 12 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99; assert x == 99") |
14 | 13 |
|
15 | 14 |
|
16 | 15 | def test_space_cannot_alter_user_namespace_immutable_references(ip): |
17 | | - ip.run_cell(raw_cell='x = 100') |
18 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99') |
19 | | - assert ip.user_global_ns['x'] == 100 |
| 16 | + ip.run_cell(raw_cell="x = 100") |
| 17 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99") |
| 18 | + assert ip.user_global_ns["x"] == 100 |
20 | 19 |
|
21 | 20 |
|
22 | 21 | def test_space_can_alter_user_namespace_mutable_references(ip): |
23 | | - ip.run_cell(raw_cell='x = [1, 2, 3]') |
24 | | - ip.run_cell_magic(magic_name='space', line='tomato', |
25 | | - cell='x[-1] = 10') |
26 | | - assert ip.user_global_ns['x'] == [1, 2, 10] |
| 22 | + ip.run_cell(raw_cell="x = [1, 2, 3]") |
| 23 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x[-1] = 10") |
| 24 | + assert ip.user_global_ns["x"] == [1, 2, 10] |
27 | 25 |
|
28 | 26 |
|
29 | 27 | def test_space_cannot_alter_user_namespace_references_using_global(ip): |
30 | | - ip.run_cell(raw_cell='x = 100') |
31 | | - ip.run_cell_magic(magic_name='space', line='tomato', |
32 | | - cell='global x; x = 99') |
33 | | - assert ip.user_global_ns['x'] == 100 |
| 28 | + ip.run_cell(raw_cell="x = 100") |
| 29 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="global x; x = 99") |
| 30 | + assert ip.user_global_ns["x"] == 100 |
34 | 31 |
|
35 | 32 |
|
36 | 33 | def test_space_cannot_remove_user_namespace_references(ip): |
37 | | - ip.run_cell(raw_cell='x = 100') |
| 34 | + ip.run_cell(raw_cell="x = 100") |
38 | 35 | with raises(NameError): |
39 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='del x') |
40 | | - assert ip.user_global_ns['x'] == 100 |
| 36 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="del x") |
| 37 | + assert ip.user_global_ns["x"] == 100 |
41 | 38 |
|
42 | 39 |
|
43 | 40 | def test_space_cannot_remove_user_namespace_references_using_global(ip): |
44 | | - ip.run_cell(raw_cell='x = 100') |
| 41 | + ip.run_cell(raw_cell="x = 100") |
45 | 42 | with raises(NameError): |
46 | | - ip.run_cell_magic(magic_name='space', line='tomato', |
47 | | - cell='global x; del x') |
48 | | - assert 'x' in ip.user_global_ns |
| 43 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="global x; del x") |
| 44 | + assert "x" in ip.user_global_ns |
49 | 45 |
|
50 | 46 |
|
51 | 47 | def test_space_cannot_add_user_namespace_references(ip): |
52 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99') |
53 | | - assert 'x' not in ip.user_global_ns |
| 48 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99") |
| 49 | + assert "x" not in ip.user_global_ns |
54 | 50 |
|
55 | 51 |
|
56 | 52 | def test_space_cannot_add_user_namespace_references_using_global(ip): |
57 | | - ip.run_cell_magic(magic_name='space', line='tomato', |
58 | | - cell='global x; x = 99') |
59 | | - assert 'x' not in ip.user_global_ns |
| 53 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="global x; x = 99") |
| 54 | + assert "x" not in ip.user_global_ns |
60 | 55 |
|
61 | 56 |
|
62 | 57 | def test_space_reference_assignments_persist_in_new_magic_call(ip): |
63 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99') |
64 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='assert x == 99') |
| 58 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99") |
| 59 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="assert x == 99") |
65 | 60 |
|
66 | 61 |
|
67 | 62 | def test_space_reference_deletions_persist_in_new_magic_call(ip): |
68 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99') |
69 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='del x') |
| 63 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99") |
| 64 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="del x") |
70 | 65 | with raises(NameError): |
71 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='x') |
| 66 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x") |
72 | 67 |
|
73 | 68 |
|
74 | 69 | def test_space_references_assignments_are_confined_in_one_space_only(ip): |
75 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99') |
76 | | - ip.run_cell_magic(magic_name='space', line='potato', cell='x = 100') |
77 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='assert x == 99') |
| 70 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99") |
| 71 | + ip.run_cell_magic(magic_name="space", line="potato", cell="x = 100") |
| 72 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="assert x == 99") |
78 | 73 |
|
79 | 74 |
|
80 | 75 | def test_space_references_deletions_are_confined_in_one_space_only(ip): |
81 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99') |
| 76 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99") |
82 | 77 | with raises(NameError): |
83 | | - ip.run_cell_magic(magic_name='space', line='potato', cell='del x') |
84 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='assert x == 99') |
| 78 | + ip.run_cell_magic(magic_name="space", line="potato", cell="del x") |
| 79 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="assert x == 99") |
85 | 80 |
|
86 | 81 |
|
87 | 82 | def test_space_can_execute_newly_defined_lambda_functions(ip): |
88 | | - ip.run_cell_magic(magic_name='space', line='tomato', |
89 | | - cell='f = lambda x: x + 1; y = f(x=2); assert y == 3') |
| 83 | + ip.run_cell_magic( |
| 84 | + magic_name="space", |
| 85 | + line="tomato", |
| 86 | + cell="f = lambda x: x + 1; y = f(x=2); assert y == 3", |
| 87 | + ) |
90 | 88 |
|
91 | 89 |
|
92 | 90 | def test_space_can_execute_newly_defined_functions(ip): |
93 | | - ip.run_cell_magic(magic_name='space', line='tomato', |
94 | | - cell='def f(x): return x + 1; y = f(x=2); assert y == 3') |
| 91 | + ip.run_cell_magic( |
| 92 | + magic_name="space", |
| 93 | + line="tomato", |
| 94 | + cell="def f(x): return x + 1; y = f(x=2); assert y == 3", |
| 95 | + ) |
95 | 96 |
|
96 | 97 |
|
97 | 98 | def test_space_can_execute_top_level_non_closure_functions(ip): |
98 | | - ip.run_cell_magic(magic_name='space', line='tomato', |
99 | | - cell=('def f(x): return x + 1\n' |
100 | | - 'def g(x): return f(x=x) * 2\n' |
101 | | - 'y = g(x=3)')) |
102 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='assert y == 8') |
| 99 | + ip.run_cell_magic( |
| 100 | + magic_name="space", |
| 101 | + line="tomato", |
| 102 | + cell="def f(x): return x + 1\ndef g(x): return f(x=x) * 2\ny = g(x=3)", |
| 103 | + ) |
| 104 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="assert y == 8") |
103 | 105 |
|
104 | 106 |
|
105 | 107 | def test_get_spaces_can_access_space_references(ip): |
106 | | - ip.run_cell(raw_cell='from jupyter_spaces import get_spaces') |
107 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99') |
108 | | - ip.run_cell(raw_cell='spaces = get_spaces()') |
109 | | - assert ip.user_global_ns['spaces']['tomato'].namespace['x'] == 99 |
| 108 | + ip.run_cell(raw_cell="from jupyter_spaces import get_spaces") |
| 109 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99") |
| 110 | + ip.run_cell(raw_cell="spaces = get_spaces()") |
| 111 | + assert ip.user_global_ns["spaces"]["tomato"].namespace["x"] == 99 |
110 | 112 |
|
111 | 113 |
|
112 | 114 | def test_get_spaces_can_alter_space_references(ip): |
113 | | - ip.run_cell(raw_cell='from jupyter_spaces import get_spaces') |
114 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99') |
115 | | - ip.run_cell(raw_cell='spaces = get_spaces()') |
| 115 | + ip.run_cell(raw_cell="from jupyter_spaces import get_spaces") |
| 116 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99") |
| 117 | + ip.run_cell(raw_cell="spaces = get_spaces()") |
116 | 118 | ip.run_cell(raw_cell='spaces["tomato"].namespace["x"] = 101') |
117 | | - assert ip.user_global_ns['spaces']['tomato'].namespace['x'] == 101 |
| 119 | + assert ip.user_global_ns["spaces"]["tomato"].namespace["x"] == 101 |
118 | 120 |
|
119 | 121 |
|
120 | 122 | def test_get_spaces_can_remove_space_references(ip): |
121 | | - ip.run_cell(raw_cell='from jupyter_spaces import get_spaces') |
122 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99') |
123 | | - ip.run_cell(raw_cell='spaces = get_spaces()') |
| 123 | + ip.run_cell(raw_cell="from jupyter_spaces import get_spaces") |
| 124 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99") |
| 125 | + ip.run_cell(raw_cell="spaces = get_spaces()") |
124 | 126 | ip.run_cell(raw_cell='del spaces["tomato"].namespace["x"]') |
125 | | - assert 'x' not in ip.user_global_ns['spaces']['tomato'].namespace |
| 127 | + assert "x" not in ip.user_global_ns["spaces"]["tomato"].namespace |
126 | 128 |
|
127 | 129 |
|
128 | 130 | def test_get_spaces_reflects_space_references_changes(ip): |
129 | | - ip.run_cell(raw_cell='from jupyter_spaces import get_spaces') |
130 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99') |
131 | | - ip.run_cell(raw_cell='spaces = get_spaces()') |
| 131 | + ip.run_cell(raw_cell="from jupyter_spaces import get_spaces") |
| 132 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99") |
| 133 | + ip.run_cell(raw_cell="spaces = get_spaces()") |
132 | 134 | ip.run_cell(raw_cell='spaces["tomato"].namespace["x"] = 101') |
133 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 11') |
134 | | - assert ip.user_global_ns['spaces']['tomato'].namespace['x'] == 11 |
| 135 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 11") |
| 136 | + assert ip.user_global_ns["spaces"]["tomato"].namespace["x"] == 11 |
135 | 137 |
|
136 | 138 |
|
137 | 139 | def test_get_spaces_reflects_space_removal(ip): |
138 | | - ip.run_cell(raw_cell='from jupyter_spaces import get_spaces') |
139 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99') |
140 | | - ip.run_cell(raw_cell='spaces = get_spaces()') |
141 | | - ip.run_line_magic(magic_name='remove_space', line='tomato') |
142 | | - assert 'tomato' not in ip.user_global_ns['spaces'] |
| 140 | + ip.run_cell(raw_cell="from jupyter_spaces import get_spaces") |
| 141 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99") |
| 142 | + ip.run_cell(raw_cell="spaces = get_spaces()") |
| 143 | + ip.run_line_magic(magic_name="remove_space", line="tomato") |
| 144 | + assert "tomato" not in ip.user_global_ns["spaces"] |
143 | 145 |
|
144 | 146 |
|
145 | 147 | def test_get_spaces_reflects_extension_reload(ip): |
146 | | - ip.run_cell(raw_cell='from jupyter_spaces import get_spaces') |
147 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99') |
148 | | - ip.run_cell(raw_cell='spaces = get_spaces()') |
149 | | - ip.run_line_magic(magic_name='reload_ext', line='jupyter_spaces') |
150 | | - assert not ip.user_global_ns['spaces'] |
| 148 | + ip.run_cell(raw_cell="from jupyter_spaces import get_spaces") |
| 149 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99") |
| 150 | + ip.run_cell(raw_cell="spaces = get_spaces()") |
| 151 | + ip.run_line_magic(magic_name="reload_ext", line="jupyter_spaces") |
| 152 | + assert not ip.user_global_ns["spaces"] |
151 | 153 |
|
152 | 154 |
|
153 | 155 | def test_space_can_print_to_console(ip): |
154 | 156 | with capture_output() as captured: |
155 | | - ip.run_cell_magic(magic_name='space', line='tomato', cell='print(100)') |
156 | | - assert captured.stdout == '100\n' |
| 157 | + ip.run_cell_magic(magic_name="space", line="tomato", cell="print(100)") |
| 158 | + assert captured.stdout == "100\n" |
0 commit comments