Show More
@@ -66,8 +66,6 b' def test_compiler_check_cache():' | |||||
66 | cp.cache('x=1', 99) |
|
66 | cp.cache('x=1', 99) | |
67 | # Ensure now that after clearing the cache, our entries survive |
|
67 | # Ensure now that after clearing the cache, our entries survive | |
68 | linecache.checkcache() |
|
68 | linecache.checkcache() | |
69 | for k in linecache.cache: |
|
69 | assert any( | |
70 |
|
|
70 | k.startswith("<ipython-input-99") for k in linecache.cache | |
71 | break |
|
71 | ), "Entry for input-99 missing from linecache" | |
72 | else: |
|
|||
73 | raise AssertionError('Entry for input-99 missing from linecache') |
|
@@ -242,10 +242,8 b' def test_interruptible_core_debugger():' | |||||
242 | """ |
|
242 | """ | |
243 | def raising_input(msg="", called=[0]): |
|
243 | def raising_input(msg="", called=[0]): | |
244 | called[0] += 1 |
|
244 | called[0] += 1 | |
245 | if called[0] == 1: |
|
245 | assert called[0] == 1, "input() should only be called once!" | |
246 |
|
|
246 | raise KeyboardInterrupt() | |
247 | else: |
|
|||
248 | raise AssertionError("input() should only be called once!") |
|
|||
249 |
|
247 | |||
250 | tracer_orig = sys.gettrace() |
|
248 | tracer_orig = sys.gettrace() | |
251 | try: |
|
249 | try: |
@@ -6,6 +6,7 b'' | |||||
6 | # Imports |
|
6 | # Imports | |
7 | #----------------------------------------------------------------------------- |
|
7 | #----------------------------------------------------------------------------- | |
8 |
|
8 | |||
|
9 | import pytest | |||
9 | from IPython.core.error import TryNext |
|
10 | from IPython.core.error import TryNext | |
10 | from IPython.core.hooks import CommandChainDispatcher |
|
11 | from IPython.core.hooks import CommandChainDispatcher | |
11 |
|
12 | |||
@@ -41,12 +42,9 b' def test_command_chain_dispatcher_ff():' | |||||
41 | fail2 = Fail("fail2") |
|
42 | fail2 = Fail("fail2") | |
42 | dp = CommandChainDispatcher([(0, fail1), (10, fail2)]) |
|
43 | dp = CommandChainDispatcher([(0, fail1), (10, fail2)]) | |
43 |
|
44 | |||
44 | try: |
|
45 | with pytest.raises(TryNext) as e: | |
45 | dp() |
|
46 | dp() | |
46 | except TryNext as e: |
|
47 | assert str(e.value) == "fail2" | |
47 | assert str(e) == "fail2" |
|
|||
48 | else: |
|
|||
49 | assert False, "Expected exception was not raised." |
|
|||
50 |
|
48 | |||
51 | assert fail1.called is True |
|
49 | assert fail1.called is True | |
52 | assert fail2.called is True |
|
50 | assert fail2.called is True |
@@ -7,12 +7,8 b' import pytest' | |||||
7 | from IPython.utils.tempdir import TemporaryDirectory |
|
7 | from IPython.utils.tempdir import TemporaryDirectory | |
8 |
|
8 | |||
9 | def test_logstart_inaccessible_file(): |
|
9 | def test_logstart_inaccessible_file(): | |
10 | try: |
|
10 | with pytest.raises(IOError): | |
11 | _ip.logger.logstart(logfname="/") # Opening that filename will fail. |
|
11 | _ip.logger.logstart(logfname="/") # Opening that filename will fail. | |
12 | except IOError: |
|
|||
13 | pass |
|
|||
14 | else: |
|
|||
15 | assert False # The try block should never pass. |
|
|||
16 |
|
12 | |||
17 | try: |
|
13 | try: | |
18 | _ip.run_cell("a=1") # Check it doesn't try to log this |
|
14 | _ip.run_cell("a=1") # Check it doesn't try to log this |
@@ -132,10 +132,10 b' def test_config_print_class():' | |||||
132 | _ip.magic('config TerminalInteractiveShell') |
|
132 | _ip.magic('config TerminalInteractiveShell') | |
133 |
|
133 | |||
134 | stdout = captured.stdout |
|
134 | stdout = captured.stdout | |
135 | if not re.match("TerminalInteractiveShell.* options", stdout.splitlines()[0]): |
|
135 | assert re.match( | |
136 | print(stdout) |
|
136 | "TerminalInteractiveShell.* options", stdout.splitlines()[0] | |
137 | raise AssertionError("1st line of stdout not like " |
|
137 | ), f"{stdout}\n\n1st line of stdout not like 'TerminalInteractiveShell.* options'" | |
138 | "'TerminalInteractiveShell.* options'") |
|
138 | ||
139 |
|
139 | |||
140 | def test_rehashx(): |
|
140 | def test_rehashx(): | |
141 | # clear up everything |
|
141 | # clear up everything | |
@@ -1219,12 +1219,9 b' def test_edit_interactive():' | |||||
1219 | n = ip.execution_count |
|
1219 | n = ip.execution_count | |
1220 | ip.run_cell("def foo(): return 1", store_history=True) |
|
1220 | ip.run_cell("def foo(): return 1", store_history=True) | |
1221 |
|
1221 | |||
1222 | try: |
|
1222 | with pytest.raises(code.InteractivelyDefined) as e: | |
1223 | _run_edit_test("foo") |
|
1223 | _run_edit_test("foo") | |
1224 | except code.InteractivelyDefined as e: |
|
1224 | assert e.value.index == n | |
1225 | assert e.index == n |
|
|||
1226 | else: |
|
|||
1227 | raise AssertionError("Should have raised InteractivelyDefined") |
|
|||
1228 |
|
1225 | |||
1229 |
|
1226 | |||
1230 | def test_edit_cell(): |
|
1227 | def test_edit_cell(): |
@@ -70,13 +70,14 b' def test_columnize_random():' | |||||
70 | out = text.columnize(items, row_first=row_first, displaywidth=displaywidth) |
|
70 | out = text.columnize(items, row_first=row_first, displaywidth=displaywidth) | |
71 | longer_line = max([len(x) for x in out.split('\n')]) |
|
71 | longer_line = max([len(x) for x in out.split('\n')]) | |
72 | longer_element = max(rand_len) |
|
72 | longer_element = max(rand_len) | |
73 |
|
|
73 | assert longer_line <= displaywidth, ( | |
74 |
|
|
74 | f"Columnize displayed something lager than displaywidth : {longer_line}\n" | |
75 |
|
|
75 | f"longer element : {longer_element}\n" | |
76 |
|
|
76 | f"displaywidth : {displaywidth}\n" | |
77 |
|
|
77 | f"number of element : {nitems}\n" | |
78 |
|
|
78 | f"size of each element : {rand_len}\n" | |
79 |
|
|
79 | f"row_first={row_first}\n" | |
|
80 | ) | |||
80 |
|
81 | |||
81 |
|
82 | |||
82 | # TODO: pytest mark.parametrize once nose removed. |
|
83 | # TODO: pytest mark.parametrize once nose removed. | |
@@ -103,9 +104,9 b' def eval_formatter_check(f):' | |||||
103 | ns = dict(n=12, pi=math.pi, stuff='hello there', os=os, u=u"cafΓ©", b="cafΓ©") |
|
104 | ns = dict(n=12, pi=math.pi, stuff='hello there', os=os, u=u"cafΓ©", b="cafΓ©") | |
104 | s = f.format("{n} {n//4} {stuff.split()[0]}", **ns) |
|
105 | s = f.format("{n} {n//4} {stuff.split()[0]}", **ns) | |
105 | assert s == "12 3 hello" |
|
106 | assert s == "12 3 hello" | |
106 |
s = f.format( |
|
107 | s = f.format(" ".join(["{n//%i}" % i for i in range(1, 8)]), **ns) | |
107 | assert s == "12 6 4 3 2 2 1" |
|
108 | assert s == "12 6 4 3 2 2 1" | |
108 |
s = f.format( |
|
109 | s = f.format("{[n//i for i in range(1,8)]}", **ns) | |
109 | assert s == "[12, 6, 4, 3, 2, 2, 1]" |
|
110 | assert s == "[12, 6, 4, 3, 2, 2, 1]" | |
110 | s = f.format("{stuff!s}", **ns) |
|
111 | s = f.format("{stuff!s}", **ns) | |
111 | assert s == ns["stuff"] |
|
112 | assert s == ns["stuff"] | |
@@ -133,9 +134,9 b' def eval_formatter_slicing_check(f):' | |||||
133 | pytest.raises(SyntaxError, f.format, "{n:x}", **ns) |
|
134 | pytest.raises(SyntaxError, f.format, "{n:x}", **ns) | |
134 |
|
135 | |||
135 | def eval_formatter_no_slicing_check(f): |
|
136 | def eval_formatter_no_slicing_check(f): | |
136 |
ns = dict(n=12, pi=math.pi, stuff= |
|
137 | ns = dict(n=12, pi=math.pi, stuff="hello there", os=os) | |
137 |
|
138 | |||
138 |
s = f.format( |
|
139 | s = f.format("{n:x} {pi**2:+f}", **ns) | |
139 | assert s == "c +9.869604" |
|
140 | assert s == "c +9.869604" | |
140 |
|
141 | |||
141 | s = f.format("{stuff[slice(1,4)]}", **ns) |
|
142 | s = f.format("{stuff[slice(1,4)]}", **ns) | |
@@ -187,10 +188,11 b' def test_strip_email():' | |||||
187 |
|
188 | |||
188 |
|
189 | |||
189 | def test_strip_email2(): |
|
190 | def test_strip_email2(): | |
190 |
src = |
|
191 | src = "> > > list()" | |
191 |
cln = |
|
192 | cln = "list()" | |
192 | assert text.strip_email_quotes(src) == cln |
|
193 | assert text.strip_email_quotes(src) == cln | |
193 |
|
194 | |||
|
195 | ||||
194 | def test_LSString(): |
|
196 | def test_LSString(): | |
195 | lss = text.LSString("abc\ndef") |
|
197 | lss = text.LSString("abc\ndef") | |
196 | assert lss.l == ["abc", "def"] |
|
198 | assert lss.l == ["abc", "def"] | |
@@ -198,6 +200,7 b' def test_LSString():' | |||||
198 | lss = text.LSString(os.getcwd()) |
|
200 | lss = text.LSString(os.getcwd()) | |
199 | assert isinstance(lss.p[0], Path) |
|
201 | assert isinstance(lss.p[0], Path) | |
200 |
|
202 | |||
|
203 | ||||
201 | def test_SList(): |
|
204 | def test_SList(): | |
202 | sl = text.SList(["a 11", "b 1", "a 2"]) |
|
205 | sl = text.SList(["a 11", "b 1", "a 2"]) | |
203 | assert sl.n == "a 11\nb 1\na 2" |
|
206 | assert sl.n == "a 11\nb 1\na 2" |
General Comments 0
You need to be logged in to leave comments.
Login now