##// END OF EJS Templates
Some more tests for escaped commands
Thomas Kluyver -
Show More
@@ -14,6 +14,14 b" get_ipython().run_line_magic('foo', ' bar')"
14 14 g()
15 15 """.splitlines(keepends=True))
16 16
17 INDENTED_MAGIC = ("""\
18 for a in range(5):
19 %ls
20 """.splitlines(keepends=True), """\
21 for a in range(5):
22 get_ipython().run_line_magic('ls', '')
23 """.splitlines(keepends=True))
24
17 25 MULTILINE_MAGIC_ASSIGN = ("""\
18 26 a = f()
19 27 b = %foo \\
@@ -36,6 +44,21 b" b = get_ipython().getoutput('foo bar')"
36 44 g()
37 45 """.splitlines(keepends=True))
38 46
47 AUTOCALL_QUOTE = (
48 [",f 1 2 3\n"],
49 ['f("1", "2", "3")\n']
50 )
51
52 AUTOCALL_QUOTE2 = (
53 [";f 1 2 3\n"],
54 ['f("1 2 3")\n']
55 )
56
57 AUTOCALL_PAREN = (
58 ["/f 1 2 3\n"],
59 ['f(1, 2, 3)\n']
60 )
61
39 62 def test_continued_line():
40 63 lines = MULTILINE_MAGIC_ASSIGN[0]
41 64 nt.assert_equal(ipt2.find_end_of_continued_line(lines, 1), 2)
@@ -74,9 +97,27 b' def test_find_magic_escape():'
74 97 tbl = make_tokens_by_line(MULTILINE_MAGIC[0])
75 98 nt.assert_equal(ipt2.EscapedCommand.find(tbl), (2, 0))
76 99
100 tbl = make_tokens_by_line(INDENTED_MAGIC[0])
101 nt.assert_equal(ipt2.EscapedCommand.find(tbl), (2, 4))
102
77 103 tbl = make_tokens_by_line(MULTILINE_MAGIC_ASSIGN[0]) # Shouldn't find a = %foo
78 104 nt.assert_equal(ipt2.EscapedCommand.find(tbl), None)
79 105
80 106 def test_transform_magic_escape():
81 107 res = ipt2.EscapedCommand.transform(MULTILINE_MAGIC[0], (2, 0))
82 108 nt.assert_equal(res, MULTILINE_MAGIC[1])
109
110 res = ipt2.EscapedCommand.transform(INDENTED_MAGIC[0], (2, 4))
111 nt.assert_equal(res, INDENTED_MAGIC[1])
112
113 def test_find_autocalls():
114 for sample, _ in [AUTOCALL_QUOTE, AUTOCALL_QUOTE2, AUTOCALL_PAREN]:
115 print("Testing %r" % sample)
116 tbl = make_tokens_by_line(sample)
117 nt.assert_equal(ipt2.EscapedCommand.find(tbl), (1, 0))
118
119 def test_transform_autocall():
120 for sample, expected in [AUTOCALL_QUOTE, AUTOCALL_QUOTE2, AUTOCALL_PAREN]:
121 print("Testing %r" % sample)
122 res = ipt2.EscapedCommand.transform(sample, (1, 0))
123 nt.assert_equal(res, expected)
General Comments 0
You need to be logged in to leave comments. Login now