Show More
@@ -1,6 +1,6 b'' | |||
|
1 | 1 | from IPython.utils.capture import capture_output |
|
2 | 2 | |
|
3 | import nose.tools as nt | |
|
3 | import pytest | |
|
4 | 4 | |
|
5 | 5 | def test_alias_lifecycle(): |
|
6 | 6 | name = 'test_alias1' |
@@ -9,8 +9,8 b' def test_alias_lifecycle():' | |||
|
9 | 9 | am.clear_aliases() |
|
10 | 10 | am.define_alias(name, cmd) |
|
11 | 11 | assert am.is_alias(name) |
|
12 |
|
|
|
13 |
|
|
|
12 | assert am.retrieve_alias(name) == cmd | |
|
13 | assert (name, cmd) in am.aliases | |
|
14 | 14 | |
|
15 | 15 | # Test running the alias |
|
16 | 16 | orig_system = _ip.system |
@@ -19,16 +19,16 b' def test_alias_lifecycle():' | |||
|
19 | 19 | try: |
|
20 | 20 | _ip.run_cell('%{}'.format(name)) |
|
21 | 21 | result = [c.strip() for c in result] |
|
22 |
|
|
|
22 | assert result == [cmd] | |
|
23 | 23 | finally: |
|
24 | 24 | _ip.system = orig_system |
|
25 | 25 | |
|
26 | 26 | # Test removing the alias |
|
27 | 27 | am.undefine_alias(name) |
|
28 | 28 | assert not am.is_alias(name) |
|
29 |
with |
|
|
29 | with pytest.raises(ValueError): | |
|
30 | 30 | am.retrieve_alias(name) |
|
31 |
|
|
|
31 | assert (name, cmd) not in am.aliases | |
|
32 | 32 | |
|
33 | 33 | |
|
34 | 34 | def test_alias_args_error(): |
@@ -38,7 +38,7 b' def test_alias_args_error():' | |||
|
38 | 38 | with capture_output() as cap: |
|
39 | 39 | _ip.run_cell('parts 1') |
|
40 | 40 | |
|
41 |
|
|
|
41 | assert cap.stderr.split(':')[0] == 'UsageError' | |
|
42 | 42 | |
|
43 | 43 | def test_alias_args_commented(): |
|
44 | 44 | """Check that alias correctly ignores 'commented out' args""" |
@@ -62,4 +62,4 b' def test_alias_args_commented_nargs():' | |||
|
62 | 62 | assert am.is_alias(alias_name) |
|
63 | 63 | |
|
64 | 64 | thealias = am.get_alias(alias_name) |
|
65 |
|
|
|
65 | assert thealias.nargs == 1 |
@@ -18,7 +18,7 b' import linecache' | |||
|
18 | 18 | import sys |
|
19 | 19 | |
|
20 | 20 | # Third-party imports |
|
21 | import nose.tools as nt | |
|
21 | import pytest | |
|
22 | 22 | |
|
23 | 23 | # Our own imports |
|
24 | 24 | from IPython.core import compilerop |
@@ -30,13 +30,13 b' from IPython.core import compilerop' | |||
|
30 | 30 | def test_code_name(): |
|
31 | 31 | code = 'x=1' |
|
32 | 32 | name = compilerop.code_name(code) |
|
33 |
|
|
|
33 | assert name.startswith('<ipython-input-0') | |
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | def test_code_name2(): |
|
37 | 37 | code = 'x=1' |
|
38 | 38 | name = compilerop.code_name(code, 9) |
|
39 |
|
|
|
39 | assert name.startswith('<ipython-input-9') | |
|
40 | 40 | |
|
41 | 41 | |
|
42 | 42 | def test_cache(): |
@@ -45,18 +45,18 b' def test_cache():' | |||
|
45 | 45 | cp = compilerop.CachingCompiler() |
|
46 | 46 | ncache = len(linecache.cache) |
|
47 | 47 | cp.cache('x=1') |
|
48 |
|
|
|
48 | assert len(linecache.cache) > ncache | |
|
49 | 49 | |
|
50 | 50 | def test_proper_default_encoding(): |
|
51 | 51 | # Check we're in a proper Python 2 environment (some imports, such |
|
52 | 52 | # as GTK, can change the default encoding, which can hide bugs.) |
|
53 |
|
|
|
53 | assert sys.getdefaultencoding() == "utf-8" | |
|
54 | 54 | |
|
55 | 55 | def test_cache_unicode(): |
|
56 | 56 | cp = compilerop.CachingCompiler() |
|
57 | 57 | ncache = len(linecache.cache) |
|
58 | 58 | cp.cache(u"t = 'žćčšđ'") |
|
59 |
|
|
|
59 | assert len(linecache.cache) > ncache | |
|
60 | 60 | |
|
61 | 61 | def test_compiler_check_cache(): |
|
62 | 62 | """Test the compiler properly manages the cache. |
@@ -3,7 +3,7 b'' | |||
|
3 | 3 | Line-based transformers are the simpler ones; token-based transformers are |
|
4 | 4 | more complex. See test_inputtransformer2 for tests for token-based transformers. |
|
5 | 5 | """ |
|
6 | import nose.tools as nt | |
|
6 | import pytest | |
|
7 | 7 | |
|
8 | 8 | from IPython.core import inputtransformer2 as ipt2 |
|
9 | 9 | |
@@ -17,7 +17,7 b" get_ipython().run_cell_magic('foo', 'arg', 'body 1\\\\nbody 2\\\\n')" | |||
|
17 | 17 | |
|
18 | 18 | def test_cell_magic(): |
|
19 | 19 | for sample, expected in [CELL_MAGIC]: |
|
20 |
|
|
|
20 | assert (ipt2.cell_magic(sample.splitlines(keepends=True)) == | |
|
21 | 21 | expected.splitlines(keepends=True)) |
|
22 | 22 | |
|
23 | 23 | CLASSIC_PROMPT = ("""\ |
@@ -40,7 +40,7 b' for a in range(5):' | |||
|
40 | 40 | |
|
41 | 41 | def test_classic_prompt(): |
|
42 | 42 | for sample, expected in [CLASSIC_PROMPT, CLASSIC_PROMPT_L2]: |
|
43 |
|
|
|
43 | assert (ipt2.classic_prompt(sample.splitlines(keepends=True)) == | |
|
44 | 44 | expected.splitlines(keepends=True)) |
|
45 | 45 | |
|
46 | 46 | IPYTHON_PROMPT = ("""\ |
@@ -100,10 +100,9 b' def test_ipython_prompt():' | |||
|
100 | 100 | IPYTHON_PROMPT_VI_INS, |
|
101 | 101 | IPYTHON_PROMPT_VI_NAV, |
|
102 | 102 | ]: |
|
103 |
|
|
|
104 |
ipt2.ipython_prompt(sample.splitlines(keepends=True)) |
|
|
105 |
expected.splitlines(keepends=True) |
|
|
106 | ) | |
|
103 | assert ( | |
|
104 | ipt2.ipython_prompt(sample.splitlines(keepends=True)) == | |
|
105 | expected.splitlines(keepends=True)) | |
|
107 | 106 | |
|
108 | 107 | |
|
109 | 108 | INDENT_SPACES = ("""\ |
@@ -124,7 +123,7 b' if True:' | |||
|
124 | 123 | |
|
125 | 124 | def test_leading_indent(): |
|
126 | 125 | for sample, expected in [INDENT_SPACES, INDENT_TABS]: |
|
127 |
|
|
|
126 | assert (ipt2.leading_indent(sample.splitlines(keepends=True)) == | |
|
128 | 127 | expected.splitlines(keepends=True)) |
|
129 | 128 | |
|
130 | 129 | LEADING_EMPTY_LINES = ("""\ |
@@ -151,8 +150,8 b' ONLY_EMPTY_LINES = ("""\\' | |||
|
151 | 150 | |
|
152 | 151 | def test_leading_empty_lines(): |
|
153 | 152 | for sample, expected in [LEADING_EMPTY_LINES, ONLY_EMPTY_LINES]: |
|
154 |
|
|
|
155 |
ipt2.leading_empty_lines(sample.splitlines(keepends=True)) |
|
|
153 | assert ( | |
|
154 | ipt2.leading_empty_lines(sample.splitlines(keepends=True)) == | |
|
156 | 155 | expected.splitlines(keepends=True)) |
|
157 | 156 | |
|
158 | 157 | CRLF_MAGIC = ([ |
@@ -163,4 +162,4 b' CRLF_MAGIC = ([' | |||
|
163 | 162 | |
|
164 | 163 | def test_crlf_magic(): |
|
165 | 164 | for sample, expected in [CRLF_MAGIC]: |
|
166 |
|
|
|
165 | assert ipt2.cell_magic(sample) == expected |
@@ -5,7 +5,7 b'' | |||
|
5 | 5 | #----------------------------------------------------------------------------- |
|
6 | 6 | |
|
7 | 7 | # third party |
|
8 | import nose.tools as nt | |
|
8 | import pytest | |
|
9 | 9 | |
|
10 | 10 | # our own packages |
|
11 | 11 | |
@@ -31,8 +31,8 b' def test_reset():' | |||
|
31 | 31 | |
|
32 | 32 | # Finally, check that all namespaces have only as many variables as we |
|
33 | 33 | # expect to find in them: |
|
34 |
|
|
|
35 |
|
|
|
34 | assert len(ip.user_ns) == nvars_user_ns | |
|
35 | assert len(ip.user_ns_hidden) == nvars_hidden | |
|
36 | 36 | |
|
37 | 37 | |
|
38 | 38 | # Tests for reporting of exceptions in various modes, handling of SystemExit, |
@@ -209,7 +209,7 b' def test_run_cell():' | |||
|
209 | 209 | ip.run_cell('a = 10\na+=1') |
|
210 | 210 | ip.run_cell('assert a == 11\nassert 1') |
|
211 | 211 | |
|
212 |
|
|
|
212 | assert ip.user_ns['a'] == 11 | |
|
213 | 213 | complex = textwrap.dedent(""" |
|
214 | 214 | if 1: |
|
215 | 215 | print "hello" |
@@ -233,6 +233,6 b' def test_run_cell():' | |||
|
233 | 233 | def test_db(): |
|
234 | 234 | """Test the internal database used for variable persistence.""" |
|
235 | 235 | ip.db['__unittest_'] = 12 |
|
236 |
|
|
|
236 | assert ip.db['__unittest_'] == 12 | |
|
237 | 237 | del ip.db['__unittest_'] |
|
238 | 238 | assert '__unittest_' not in ip.db |
@@ -2,8 +2,8 b'' | |||
|
2 | 2 | """Test IPython.core.logger""" |
|
3 | 3 | |
|
4 | 4 | import os.path |
|
5 | import pytest | |
|
5 | 6 | |
|
6 | import nose.tools as nt | |
|
7 | 7 | from IPython.utils.tempdir import TemporaryDirectory |
|
8 | 8 | |
|
9 | 9 | def test_logstart_inaccessible_file(): |
@@ -12,7 +12,7 b' def test_logstart_inaccessible_file():' | |||
|
12 | 12 | except IOError: |
|
13 | 13 | pass |
|
14 | 14 | else: |
|
15 |
|
|
|
15 | assert False # The try block should never pass. | |
|
16 | 16 | |
|
17 | 17 | try: |
|
18 | 18 | _ip.run_cell("a=1") # Check it doesn't try to log this |
@@ -7,7 +7,7 b'' | |||
|
7 | 7 | #----------------------------------------------------------------------------- |
|
8 | 8 | |
|
9 | 9 | import argparse |
|
10 | from nose.tools import assert_equal | |
|
10 | import pytest | |
|
11 | 11 | |
|
12 | 12 | from IPython.core.magic_arguments import (argument, argument_group, kwds, |
|
13 | 13 | magic_arguments, parse_argstring, real_name) |
@@ -74,45 +74,45 b' def foo(self, args):' | |||
|
74 | 74 | |
|
75 | 75 | |
|
76 | 76 | def test_magic_arguments(): |
|
77 |
assert |
|
|
78 |
assert |
|
|
79 |
assert |
|
|
80 |
assert |
|
|
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' | |
|
78 | assert getattr(magic_foo1, 'argcmd_name', None) == None | |
|
79 | assert real_name(magic_foo1) == 'foo1' | |
|
80 | assert magic_foo1(None, '') == argparse.Namespace(foo=None) | |
|
81 | 81 | assert hasattr(magic_foo1, 'has_arguments') |
|
82 | 82 | |
|
83 |
assert |
|
|
84 |
assert |
|
|
85 |
assert |
|
|
86 |
assert |
|
|
83 | assert magic_foo2.__doc__ == '::\n\n %foo2\n\n A docstring.\n' | |
|
84 | assert getattr(magic_foo2, 'argcmd_name', None) == None | |
|
85 | assert real_name(magic_foo2) == 'foo2' | |
|
86 | assert magic_foo2(None, '') == argparse.Namespace() | |
|
87 | 87 | assert hasattr(magic_foo2, 'has_arguments') |
|
88 | 88 | |
|
89 |
assert |
|
|
90 |
assert |
|
|
91 |
assert |
|
|
92 |
assert |
|
|
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' | |
|
90 | assert getattr(magic_foo3, 'argcmd_name', None) == None | |
|
91 | assert real_name(magic_foo3) == 'foo3' | |
|
92 | assert (magic_foo3(None, '') == | |
|
93 | 93 | argparse.Namespace(bar=None, baz=None, foo=None)) |
|
94 | 94 | assert hasattr(magic_foo3, 'has_arguments') |
|
95 | 95 | |
|
96 |
assert |
|
|
97 |
assert |
|
|
98 |
assert |
|
|
99 |
assert |
|
|
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' | |
|
97 | assert getattr(magic_foo4, 'argcmd_name', None) == None | |
|
98 | assert real_name(magic_foo4) == 'foo4' | |
|
99 | assert magic_foo4(None, '') == argparse.Namespace() | |
|
100 | 100 | assert hasattr(magic_foo4, 'has_arguments') |
|
101 | 101 | |
|
102 |
assert |
|
|
103 |
assert |
|
|
104 |
assert |
|
|
105 |
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' | |
|
103 | assert getattr(magic_foo5, 'argcmd_name', None) == 'frobnicate' | |
|
104 | assert real_name(magic_foo5) == 'frobnicate' | |
|
105 | assert magic_foo5(None, '') == argparse.Namespace(foo=None) | |
|
106 | 106 | assert hasattr(magic_foo5, 'has_arguments') |
|
107 | 107 | |
|
108 |
assert |
|
|
109 |
assert |
|
|
110 |
assert |
|
|
111 |
assert |
|
|
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' | |
|
109 | assert getattr(magic_magic_foo, 'argcmd_name', None) == None | |
|
110 | assert real_name(magic_magic_foo) == 'magic_foo' | |
|
111 | assert magic_magic_foo(None, '') == argparse.Namespace(foo=None) | |
|
112 | 112 | assert hasattr(magic_magic_foo, 'has_arguments') |
|
113 | 113 | |
|
114 |
assert |
|
|
115 |
assert |
|
|
116 |
assert |
|
|
117 |
assert |
|
|
114 | assert foo.__doc__ == '::\n\n %foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n' | |
|
115 | assert getattr(foo, 'argcmd_name', None) == None | |
|
116 | assert real_name(foo) == 'foo' | |
|
117 | assert foo(None, '') == argparse.Namespace(foo=None) | |
|
118 | 118 | assert hasattr(foo, 'has_arguments') |
@@ -3,7 +3,7 b'' | |||
|
3 | 3 | #----------------------------------------------------------------------------- |
|
4 | 4 | # Imports |
|
5 | 5 | #----------------------------------------------------------------------------- |
|
6 | import nose.tools as nt | |
|
6 | import pytest | |
|
7 | 7 | |
|
8 | 8 | from IPython.core.prefilter import AutocallChecker |
|
9 | 9 | |
@@ -19,7 +19,7 b' def test_prefilter():' | |||
|
19 | 19 | ] |
|
20 | 20 | |
|
21 | 21 | for raw, correct in pairs: |
|
22 |
|
|
|
22 | assert ip.prefilter(raw) == correct | |
|
23 | 23 | |
|
24 | 24 | def test_prefilter_shadowed(): |
|
25 | 25 | def dummy_magic(line): pass |
@@ -33,14 +33,14 b' def test_prefilter_shadowed():' | |||
|
33 | 33 | for name in ['if', 'zip', 'get_ipython']: # keyword, builtin, global |
|
34 | 34 | ip.register_magic_function(dummy_magic, magic_name=name) |
|
35 | 35 | res = ip.prefilter(name+' foo') |
|
36 |
|
|
|
36 | assert res == name+' foo' | |
|
37 | 37 | del ip.magics_manager.magics['line'][name] |
|
38 | 38 | |
|
39 | 39 | # These should be transformed |
|
40 | 40 | for name in ['fi', 'piz', 'nohtypi_teg']: |
|
41 | 41 | ip.register_magic_function(dummy_magic, magic_name=name) |
|
42 | 42 | res = ip.prefilter(name+' foo') |
|
43 |
|
|
|
43 | assert res != name+' foo' | |
|
44 | 44 | del ip.magics_manager.magics['line'][name] |
|
45 | 45 | |
|
46 | 46 | finally: |
@@ -52,9 +52,9 b' def test_autocall_binops():' | |||
|
52 | 52 | f = lambda x: x |
|
53 | 53 | ip.user_ns['f'] = f |
|
54 | 54 | try: |
|
55 |
|
|
|
55 | assert ip.prefilter('f 1') =='f(1)' | |
|
56 | 56 | for t in ['f +1', 'f -1']: |
|
57 |
|
|
|
57 | assert ip.prefilter(t) == t | |
|
58 | 58 | |
|
59 | 59 | # Run tests again with a more permissive exclude_regexp, which will |
|
60 | 60 | # allow transformation of binary operations ('f -1' -> 'f(-1)'). |
@@ -66,8 +66,8 b' def test_autocall_binops():' | |||
|
66 | 66 | ac.exclude_regexp = r'^[,&^\|\*/]|^is |^not |^in |^and |^or ' |
|
67 | 67 | pm.sort_checkers() |
|
68 | 68 | |
|
69 |
|
|
|
70 |
|
|
|
69 | assert ip.prefilter('f -1') == 'f(-1)' | |
|
70 | assert ip.prefilter('f +1') == 'f(+1)' | |
|
71 | 71 | finally: |
|
72 | 72 | pm.unregister_checker(ac) |
|
73 | 73 | finally: |
@@ -88,7 +88,7 b' def test_issue_114():' | |||
|
88 | 88 | try: |
|
89 | 89 | for mgk in ip.magics_manager.lsmagic()['line']: |
|
90 | 90 | raw = template % mgk |
|
91 |
|
|
|
91 | assert ip.prefilter(raw) == raw | |
|
92 | 92 | finally: |
|
93 | 93 | ip.prefilter_manager.multi_line_specials = msp |
|
94 | 94 | |
@@ -121,7 +121,7 b' def test_autocall_should_support_unicode():' | |||
|
121 | 121 | ip.magic('autocall 2') |
|
122 | 122 | ip.user_ns['π'] = lambda x: x |
|
123 | 123 | try: |
|
124 |
|
|
|
124 | assert ip.prefilter('π 3') =='π(3)' | |
|
125 | 125 | finally: |
|
126 | 126 | ip.magic('autocall 0') |
|
127 | 127 | del ip.user_ns['π'] |
General Comments 0
You need to be logged in to leave comments.
Login now