##// END OF EJS Templates
Darker
Blazej Michalik -
Show More
@@ -38,7 +38,8 b' def test_alias_args_error():'
38 with capture_output() as cap:
38 with capture_output() as cap:
39 _ip.run_cell('parts 1')
39 _ip.run_cell('parts 1')
40
40
41 assert cap.stderr.split(':')[0] == 'UsageError'
41 assert cap.stderr.split(":")[0] == "UsageError"
42
42
43
43 def test_alias_args_commented():
44 def test_alias_args_commented():
44 """Check that alias correctly ignores 'commented out' args"""
45 """Check that alias correctly ignores 'commented out' args"""
@@ -30,13 +30,13 b' from IPython.core import compilerop'
30 def test_code_name():
30 def test_code_name():
31 code = 'x=1'
31 code = 'x=1'
32 name = compilerop.code_name(code)
32 name = compilerop.code_name(code)
33 assert name.startswith('<ipython-input-0')
33 assert name.startswith("<ipython-input-0")
34
34
35
35
36 def test_code_name2():
36 def test_code_name2():
37 code = 'x=1'
37 code = 'x=1'
38 name = compilerop.code_name(code, 9)
38 name = compilerop.code_name(code, 9)
39 assert name.startswith('<ipython-input-9')
39 assert name.startswith("<ipython-input-9")
40
40
41
41
42 def test_cache():
42 def test_cache():
@@ -17,8 +17,9 b" get_ipython().run_cell_magic('foo', 'arg', 'body 1\\\\nbody 2\\\\n')"
17
17
18 def test_cell_magic():
18 def test_cell_magic():
19 for sample, expected in [CELL_MAGIC]:
19 for sample, expected in [CELL_MAGIC]:
20 assert (ipt2.cell_magic(sample.splitlines(keepends=True)) ==
20 assert ipt2.cell_magic(sample.splitlines(keepends=True)) == expected.splitlines(
21 expected.splitlines(keepends=True))
21 keepends=True
22 )
22
23
23 CLASSIC_PROMPT = ("""\
24 CLASSIC_PROMPT = ("""\
24 >>> for a in range(5):
25 >>> for a in range(5):
@@ -40,8 +41,9 b' for a in range(5):'
40
41
41 def test_classic_prompt():
42 def test_classic_prompt():
42 for sample, expected in [CLASSIC_PROMPT, CLASSIC_PROMPT_L2]:
43 for sample, expected in [CLASSIC_PROMPT, CLASSIC_PROMPT_L2]:
43 assert (ipt2.classic_prompt(sample.splitlines(keepends=True)) ==
44 assert ipt2.classic_prompt(
44 expected.splitlines(keepends=True))
45 sample.splitlines(keepends=True)
46 ) == expected.splitlines(keepends=True)
45
47
46 IPYTHON_PROMPT = ("""\
48 IPYTHON_PROMPT = ("""\
47 In [1]: for a in range(5):
49 In [1]: for a in range(5):
@@ -100,9 +102,9 b' def test_ipython_prompt():'
100 IPYTHON_PROMPT_VI_INS,
102 IPYTHON_PROMPT_VI_INS,
101 IPYTHON_PROMPT_VI_NAV,
103 IPYTHON_PROMPT_VI_NAV,
102 ]:
104 ]:
103 assert (
105 assert ipt2.ipython_prompt(
104 ipt2.ipython_prompt(sample.splitlines(keepends=True)) ==
106 sample.splitlines(keepends=True)
105 expected.splitlines(keepends=True))
107 ) == expected.splitlines(keepends=True)
106
108
107
109
108 INDENT_SPACES = ("""\
110 INDENT_SPACES = ("""\
@@ -123,8 +125,9 b' if True:'
123
125
124 def test_leading_indent():
126 def test_leading_indent():
125 for sample, expected in [INDENT_SPACES, INDENT_TABS]:
127 for sample, expected in [INDENT_SPACES, INDENT_TABS]:
126 assert (ipt2.leading_indent(sample.splitlines(keepends=True)) ==
128 assert ipt2.leading_indent(
127 expected.splitlines(keepends=True))
129 sample.splitlines(keepends=True)
130 ) == expected.splitlines(keepends=True)
128
131
129 LEADING_EMPTY_LINES = ("""\
132 LEADING_EMPTY_LINES = ("""\
130 \t
133 \t
@@ -150,9 +153,9 b' ONLY_EMPTY_LINES = ("""\\'
150
153
151 def test_leading_empty_lines():
154 def test_leading_empty_lines():
152 for sample, expected in [LEADING_EMPTY_LINES, ONLY_EMPTY_LINES]:
155 for sample, expected in [LEADING_EMPTY_LINES, ONLY_EMPTY_LINES]:
153 assert (
156 assert ipt2.leading_empty_lines(
154 ipt2.leading_empty_lines(sample.splitlines(keepends=True)) ==
157 sample.splitlines(keepends=True)
155 expected.splitlines(keepends=True))
158 ) == expected.splitlines(keepends=True)
156
159
157 CRLF_MAGIC = ([
160 CRLF_MAGIC = ([
158 "%%ls\r\n"
161 "%%ls\r\n"
@@ -87,35 +87,36 b' ZeroDivisionError: ...'
87
87
88 def doctest_tb_verbose():
88 def doctest_tb_verbose():
89 """
89 """
90 In [5]: xmode verbose
90 In [5]: xmode verbose
91 Exception reporting mode: Verbose
91 Exception reporting mode: Verbose
92
93 In [6]: run simpleerr.py
94 ---------------------------------------------------------------------------
95 ZeroDivisionError Traceback (most recent call last)
96 <BLANKLINE>
97 ... in <module>
98 29 except IndexError:
99 30 mode = 'div'
100 ---> 32 bar(mode)
101 mode = 'div'
102 <BLANKLINE>
103 ... in bar(mode='div')
104 14 "bar"
105 15 if mode=='div':
106 ---> 16 div0()
107 17 elif mode=='exit':
108 18 try:
109 <BLANKLINE>
110 ... in div0()
111 6 x = 1
112 7 y = 0
113 ----> 8 x/y
114 x = 1
115 y = 0
116 <BLANKLINE>
117 ZeroDivisionError: ...
118 """
92
119
93 In [6]: run simpleerr.py
94 ---------------------------------------------------------------------------
95 ZeroDivisionError Traceback (most recent call last)
96 <BLANKLINE>
97 ... in <module>
98 29 except IndexError:
99 30 mode = 'div'
100 ---> 32 bar(mode)
101 mode = 'div'
102 <BLANKLINE>
103 ... in bar(mode='div')
104 14 "bar"
105 15 if mode=='div':
106 ---> 16 div0()
107 17 elif mode=='exit':
108 18 try:
109 <BLANKLINE>
110 ... in div0()
111 6 x = 1
112 7 y = 0
113 ----> 8 x/y
114 x = 1
115 y = 0
116 <BLANKLINE>
117 ZeroDivisionError: ...
118 """
119
120
120 # TODO : Marc 2021 – this seem to fail due
121 # TODO : Marc 2021 – this seem to fail due
121 # to upstream changes in CI for whatever reason.
122 # to upstream changes in CI for whatever reason.
@@ -206,11 +207,13 b' ZeroDivisionError: ...'
206
207
207 def test_run_cell():
208 def test_run_cell():
208 import textwrap
209 import textwrap
209 ip.run_cell('a = 10\na+=1')
210 ip.run_cell('assert a == 11\nassert 1')
211
210
212 assert ip.user_ns['a'] == 11
211 ip.run_cell("a = 10\na+=1")
213 complex = textwrap.dedent("""
212 ip.run_cell("assert a == 11\nassert 1")
213
214 assert ip.user_ns["a"] == 11
215 complex = textwrap.dedent(
216 """
214 if 1:
217 if 1:
215 print "hello"
218 print "hello"
216 if 1:
219 if 1:
@@ -232,7 +235,7 b' def test_run_cell():'
232
235
233 def test_db():
236 def test_db():
234 """Test the internal database used for variable persistence."""
237 """Test the internal database used for variable persistence."""
235 ip.db['__unittest_'] = 12
238 ip.db["__unittest_"] = 12
236 assert ip.db['__unittest_'] == 12
239 assert ip.db["__unittest_"] == 12
237 del ip.db['__unittest_']
240 del ip.db["__unittest_"]
238 assert '__unittest_' not in ip.db
241 assert "__unittest_" not in ip.db
@@ -12,8 +12,8 b' def test_logstart_inaccessible_file():'
12 except IOError:
12 except IOError:
13 pass
13 pass
14 else:
14 else:
15 assert False # The try block should never pass.
15 assert False # The try block should never pass.
16
16
17 try:
17 try:
18 _ip.run_cell("a=1") # Check it doesn't try to log this
18 _ip.run_cell("a=1") # Check it doesn't try to log this
19 finally:
19 finally:
@@ -74,45 +74,62 b' def foo(self, args):'
74
74
75
75
76 def test_magic_arguments():
76 def test_magic_arguments():
77 assert magic_foo1.__doc__ == '::\n\n %foo1 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n'
77 assert (
78 assert getattr(magic_foo1, 'argcmd_name', None) == None
78 magic_foo1.__doc__
79 assert real_name(magic_foo1) == 'foo1'
79 == "::\n\n %foo1 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n"
80 assert magic_foo1(None, '') == argparse.Namespace(foo=None)
80 )
81 assert hasattr(magic_foo1, 'has_arguments')
81 assert getattr(magic_foo1, "argcmd_name", None) == None
82
82 assert real_name(magic_foo1) == "foo1"
83 assert magic_foo2.__doc__ == '::\n\n %foo2\n\n A docstring.\n'
83 assert magic_foo1(None, "") == argparse.Namespace(foo=None)
84 assert getattr(magic_foo2, 'argcmd_name', None) == None
84 assert hasattr(magic_foo1, "has_arguments")
85 assert real_name(magic_foo2) == 'foo2'
85
86 assert magic_foo2(None, '') == argparse.Namespace()
86 assert magic_foo2.__doc__ == "::\n\n %foo2\n\n A docstring.\n"
87 assert hasattr(magic_foo2, 'has_arguments')
87 assert getattr(magic_foo2, "argcmd_name", None) == None
88
88 assert real_name(magic_foo2) == "foo2"
89 assert magic_foo3.__doc__ == '::\n\n %foo3 [-f FOO] [-b BAR] [-z BAZ]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n\nGroup:\n -b BAR, --bar BAR a grouped argument\n\nSecond Group:\n -z BAZ, --baz BAZ another grouped argument\n'
89 assert magic_foo2(None, "") == argparse.Namespace()
90 assert getattr(magic_foo3, 'argcmd_name', None) == None
90 assert hasattr(magic_foo2, "has_arguments")
91 assert real_name(magic_foo3) == 'foo3'
91
92 assert (magic_foo3(None, '') ==
92 assert (
93 argparse.Namespace(bar=None, baz=None, foo=None))
93 magic_foo3.__doc__
94 assert hasattr(magic_foo3, 'has_arguments')
94 == "::\n\n %foo3 [-f FOO] [-b BAR] [-z BAZ]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n\nGroup:\n -b BAR, --bar BAR a grouped argument\n\nSecond Group:\n -z BAZ, --baz BAZ another grouped argument\n"
95
95 )
96 assert magic_foo4.__doc__ == '::\n\n %foo4 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n'
96 assert getattr(magic_foo3, "argcmd_name", None) == None
97 assert getattr(magic_foo4, 'argcmd_name', None) == None
97 assert real_name(magic_foo3) == "foo3"
98 assert real_name(magic_foo4) == 'foo4'
98 assert magic_foo3(None, "") == argparse.Namespace(bar=None, baz=None, foo=None)
99 assert magic_foo4(None, '') == argparse.Namespace()
99 assert hasattr(magic_foo3, "has_arguments")
100 assert hasattr(magic_foo4, 'has_arguments')
100
101
101 assert (
102 assert magic_foo5.__doc__ == '::\n\n %frobnicate [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n'
102 magic_foo4.__doc__
103 assert getattr(magic_foo5, 'argcmd_name', None) == 'frobnicate'
103 == "::\n\n %foo4 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n"
104 assert real_name(magic_foo5) == 'frobnicate'
104 )
105 assert magic_foo5(None, '') == argparse.Namespace(foo=None)
105 assert getattr(magic_foo4, "argcmd_name", None) == None
106 assert hasattr(magic_foo5, 'has_arguments')
106 assert real_name(magic_foo4) == "foo4"
107
107 assert magic_foo4(None, "") == argparse.Namespace()
108 assert magic_magic_foo.__doc__ == '::\n\n %magic_foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n'
108 assert hasattr(magic_foo4, "has_arguments")
109 assert getattr(magic_magic_foo, 'argcmd_name', None) == None
109
110 assert real_name(magic_magic_foo) == 'magic_foo'
110 assert (
111 assert magic_magic_foo(None, '') == argparse.Namespace(foo=None)
111 magic_foo5.__doc__
112 assert hasattr(magic_magic_foo, 'has_arguments')
112 == "::\n\n %frobnicate [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n"
113
113 )
114 assert foo.__doc__ == '::\n\n %foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n'
114 assert getattr(magic_foo5, "argcmd_name", None) == "frobnicate"
115 assert getattr(foo, 'argcmd_name', None) == None
115 assert real_name(magic_foo5) == "frobnicate"
116 assert real_name(foo) == 'foo'
116 assert magic_foo5(None, "") == argparse.Namespace(foo=None)
117 assert foo(None, '') == argparse.Namespace(foo=None)
117 assert hasattr(magic_foo5, "has_arguments")
118 assert hasattr(foo, 'has_arguments')
118
119 assert (
120 magic_magic_foo.__doc__
121 == "::\n\n %magic_foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n"
122 )
123 assert getattr(magic_magic_foo, "argcmd_name", None) == None
124 assert real_name(magic_magic_foo) == "magic_foo"
125 assert magic_magic_foo(None, "") == argparse.Namespace(foo=None)
126 assert hasattr(magic_magic_foo, "has_arguments")
127
128 assert (
129 foo.__doc__
130 == "::\n\n %foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n"
131 )
132 assert getattr(foo, "argcmd_name", None) == None
133 assert real_name(foo) == "foo"
134 assert foo(None, "") == argparse.Namespace(foo=None)
135 assert hasattr(foo, "has_arguments")
@@ -32,16 +32,16 b' def test_prefilter_shadowed():'
32 # These should not be transformed - they are shadowed by other names
32 # These should not be transformed - they are shadowed by other names
33 for name in ['if', 'zip', 'get_ipython']: # keyword, builtin, global
33 for name in ['if', 'zip', 'get_ipython']: # keyword, builtin, global
34 ip.register_magic_function(dummy_magic, magic_name=name)
34 ip.register_magic_function(dummy_magic, magic_name=name)
35 res = ip.prefilter(name+' foo')
35 res = ip.prefilter(name + " foo")
36 assert res == name+' foo'
36 assert res == name + " foo"
37 del ip.magics_manager.magics['line'][name]
37 del ip.magics_manager.magics["line"][name]
38
38
39 # These should be transformed
39 # These should be transformed
40 for name in ['fi', 'piz', 'nohtypi_teg']:
40 for name in ['fi', 'piz', 'nohtypi_teg']:
41 ip.register_magic_function(dummy_magic, magic_name=name)
41 ip.register_magic_function(dummy_magic, magic_name=name)
42 res = ip.prefilter(name+' foo')
42 res = ip.prefilter(name + " foo")
43 assert res != name+' foo'
43 assert res != name + " foo"
44 del ip.magics_manager.magics['line'][name]
44 del ip.magics_manager.magics["line"][name]
45
45
46 finally:
46 finally:
47 ip.automagic = prev_automagic_state
47 ip.automagic = prev_automagic_state
@@ -52,8 +52,8 b' def test_autocall_binops():'
52 f = lambda x: x
52 f = lambda x: x
53 ip.user_ns['f'] = f
53 ip.user_ns['f'] = f
54 try:
54 try:
55 assert ip.prefilter('f 1') =='f(1)'
55 assert ip.prefilter("f 1") == "f(1)"
56 for t in ['f +1', 'f -1']:
56 for t in ["f +1", "f -1"]:
57 assert ip.prefilter(t) == t
57 assert ip.prefilter(t) == t
58
58
59 # Run tests again with a more permissive exclude_regexp, which will
59 # Run tests again with a more permissive exclude_regexp, which will
@@ -66,8 +66,8 b' def test_autocall_binops():'
66 ac.exclude_regexp = r'^[,&^\|\*/]|^is |^not |^in |^and |^or '
66 ac.exclude_regexp = r'^[,&^\|\*/]|^is |^not |^in |^and |^or '
67 pm.sort_checkers()
67 pm.sort_checkers()
68
68
69 assert ip.prefilter('f -1') == 'f(-1)'
69 assert ip.prefilter("f -1") == "f(-1)"
70 assert ip.prefilter('f +1') == 'f(+1)'
70 assert ip.prefilter("f +1") == "f(+1)"
71 finally:
71 finally:
72 pm.unregister_checker(ac)
72 pm.unregister_checker(ac)
73 finally:
73 finally:
@@ -121,7 +121,7 b' def test_autocall_should_support_unicode():'
121 ip.magic('autocall 2')
121 ip.magic('autocall 2')
122 ip.user_ns['π'] = lambda x: x
122 ip.user_ns['π'] = lambda x: x
123 try:
123 try:
124 assert ip.prefilter('π 3') =='π(3)'
124 assert ip.prefilter("π 3") == "π(3)"
125 finally:
125 finally:
126 ip.magic('autocall 0')
126 ip.magic('autocall 0')
127 del ip.user_ns['π']
127 del ip.user_ns['π']
General Comments 0
You need to be logged in to leave comments. Login now