Show More
@@ -1,116 +1,116 b'' | |||||
1 | """Tests for the line-based transformers in IPython.core.inputtransformer2 |
|
1 | """Tests for the line-based transformers in IPython.core.inputtransformer2 | |
2 |
|
2 | |||
3 | Line-based transformers are the simpler ones; token-based transformers are |
|
3 | Line-based transformers are the simpler ones; token-based transformers are | |
4 | more complex. See test_inputtransformer2 for tests for token-based transformers. |
|
4 | more complex. See test_inputtransformer2 for tests for token-based transformers. | |
5 | """ |
|
5 | """ | |
6 | import nose.tools as nt |
|
6 | import nose.tools as nt | |
7 |
|
7 | |||
8 | from IPython.core import inputtransformer2 as ipt2 |
|
8 | from IPython.core import inputtransformer2 as ipt2 | |
9 |
|
9 | |||
10 | CELL_MAGIC = ("""\ |
|
10 | CELL_MAGIC = ("""\ | |
11 | %%foo arg |
|
11 | %%foo arg | |
12 | body 1 |
|
12 | body 1 | |
13 | body 2 |
|
13 | body 2 | |
14 | """, """\ |
|
14 | """, """\ | |
15 | get_ipython().run_cell_magic('foo', 'arg', 'body 1\\nbody 2\\n') |
|
15 | get_ipython().run_cell_magic('foo', 'arg', 'body 1\\nbody 2\\n') | |
16 | """) |
|
16 | """) | |
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 | nt.assert_equal(ipt2.cell_magic(sample.splitlines(keepends=True)), |
|
20 | nt.assert_equal(ipt2.cell_magic(sample.splitlines(keepends=True)), | |
21 | expected.splitlines(keepends=True)) |
|
21 | expected.splitlines(keepends=True)) | |
22 |
|
22 | |||
23 | CLASSIC_PROMPT = ("""\ |
|
23 | CLASSIC_PROMPT = ("""\ | |
24 | >>> for a in range(5): |
|
24 | >>> for a in range(5): | |
25 | ... print(a) |
|
25 | ... print(a) | |
26 | """, """\ |
|
26 | """, """\ | |
27 | for a in range(5): |
|
27 | for a in range(5): | |
28 | print(a) |
|
28 | print(a) | |
29 | """) |
|
29 | """) | |
30 |
|
30 | |||
31 | CLASSIC_PROMPT_L2 = ("""\ |
|
31 | CLASSIC_PROMPT_L2 = ("""\ | |
32 | for a in range(5): |
|
32 | for a in range(5): | |
33 | ... print(a) |
|
33 | ... print(a) | |
34 | ... print(a ** 2) |
|
34 | ... print(a ** 2) | |
35 | """, """\ |
|
35 | """, """\ | |
36 | for a in range(5): |
|
36 | for a in range(5): | |
37 | print(a) |
|
37 | print(a) | |
38 | print(a ** 2) |
|
38 | print(a ** 2) | |
39 | """) |
|
39 | """) | |
40 |
|
40 | |||
41 | def test_classic_prompt(): |
|
41 | def test_classic_prompt(): | |
42 | for sample, expected in [CLASSIC_PROMPT, CLASSIC_PROMPT_L2]: |
|
42 | for sample, expected in [CLASSIC_PROMPT, CLASSIC_PROMPT_L2]: | |
43 | nt.assert_equal(ipt2.classic_prompt(sample.splitlines(keepends=True)), |
|
43 | nt.assert_equal(ipt2.classic_prompt(sample.splitlines(keepends=True)), | |
44 | expected.splitlines(keepends=True)) |
|
44 | expected.splitlines(keepends=True)) | |
45 |
|
45 | |||
46 | IPYTHON_PROMPT = ("""\ |
|
46 | IPYTHON_PROMPT = ("""\ | |
47 | In [1]: for a in range(5): |
|
47 | In [1]: for a in range(5): | |
48 | ...: print(a) |
|
48 | ...: print(a) | |
49 | """, """\ |
|
49 | """, """\ | |
50 | for a in range(5): |
|
50 | for a in range(5): | |
51 | print(a) |
|
51 | print(a) | |
52 | """) |
|
52 | """) | |
53 |
|
53 | |||
54 | IPYTHON_PROMPT_L2 = ("""\ |
|
54 | IPYTHON_PROMPT_L2 = ("""\ | |
55 | for a in range(5): |
|
55 | for a in range(5): | |
56 | ...: print(a) |
|
56 | ...: print(a) | |
57 | ...: print(a ** 2) |
|
57 | ...: print(a ** 2) | |
58 | """, """\ |
|
58 | """, """\ | |
59 | for a in range(5): |
|
59 | for a in range(5): | |
60 | print(a) |
|
60 | print(a) | |
61 | print(a ** 2) |
|
61 | print(a ** 2) | |
62 | """) |
|
62 | """) | |
63 |
|
63 | |||
64 | def test_ipython_prompt(): |
|
64 | def test_ipython_prompt(): | |
65 | for sample, expected in [IPYTHON_PROMPT, IPYTHON_PROMPT_L2]: |
|
65 | for sample, expected in [IPYTHON_PROMPT, IPYTHON_PROMPT_L2]: | |
66 | nt.assert_equal(ipt2.ipython_prompt(sample.splitlines(keepends=True)), |
|
66 | nt.assert_equal(ipt2.ipython_prompt(sample.splitlines(keepends=True)), | |
67 | expected.splitlines(keepends=True)) |
|
67 | expected.splitlines(keepends=True)) | |
68 |
|
68 | |||
69 | INDENT_SPACES = ("""\ |
|
69 | INDENT_SPACES = ("""\ | |
70 | if True: |
|
70 | if True: | |
71 | a = 3 |
|
71 | a = 3 | |
72 | """, """\ |
|
72 | """, """\ | |
73 | if True: |
|
73 | if True: | |
74 | a = 3 |
|
74 | a = 3 | |
75 | """) |
|
75 | """) | |
76 |
|
76 | |||
77 | INDENT_TABS = ("""\ |
|
77 | INDENT_TABS = ("""\ | |
78 | \tif True: |
|
78 | \tif True: | |
79 | \t\tb = 4 |
|
79 | \t\tb = 4 | |
80 | """, """\ |
|
80 | """, """\ | |
81 | if True: |
|
81 | if True: | |
82 | \tb = 4 |
|
82 | \tb = 4 | |
83 | """) |
|
83 | """) | |
84 |
|
84 | |||
85 | def test_leading_indent(): |
|
85 | def test_leading_indent(): | |
86 | for sample, expected in [INDENT_SPACES, INDENT_TABS]: |
|
86 | for sample, expected in [INDENT_SPACES, INDENT_TABS]: | |
87 | nt.assert_equal(ipt2.leading_indent(sample.splitlines(keepends=True)), |
|
87 | nt.assert_equal(ipt2.leading_indent(sample.splitlines(keepends=True)), | |
88 | expected.splitlines(keepends=True)) |
|
88 | expected.splitlines(keepends=True)) | |
89 |
|
89 | |||
90 | LEADING_EMPTY_LINES = ("""\ |
|
90 | LEADING_EMPTY_LINES = ("""\ | |
91 | \t |
|
91 | \t | |
92 |
|
92 | |||
93 | if True: |
|
93 | if True: | |
94 | a = 3 |
|
94 | a = 3 | |
95 |
|
95 | |||
96 | b = 4 |
|
96 | b = 4 | |
97 | """, """\ |
|
97 | """, """\ | |
98 | if True: |
|
98 | if True: | |
99 | a = 3 |
|
99 | a = 3 | |
100 |
|
100 | |||
101 | b = 4 |
|
101 | b = 4 | |
102 | """) |
|
102 | """) | |
103 |
|
103 | |||
104 | ONLY_EMPTY_LINES = ("""\ |
|
104 | ONLY_EMPTY_LINES = ("""\ | |
105 | \t |
|
105 | \t | |
106 |
|
106 | |||
107 | """, """\ |
|
107 | """, """\ | |
108 | \t |
|
108 | \t | |
109 |
|
109 | |||
110 | """) |
|
110 | """) | |
111 |
|
111 | |||
112 | def leading_empty_lines(): |
|
112 | def test_leading_empty_lines(): | |
113 | for sample, expected in [LEADING_EMPTY_LINES, ONLY_EMPTY_LINES]: |
|
113 | for sample, expected in [LEADING_EMPTY_LINES, ONLY_EMPTY_LINES]: | |
114 | nt.assert_equal( |
|
114 | nt.assert_equal( | |
115 | ipt2.leading_empty_lines(sample.splitlines(keepends=True)), |
|
115 | ipt2.leading_empty_lines(sample.splitlines(keepends=True)), | |
116 | expected.splitlines(keepends=True)) |
|
116 | expected.splitlines(keepends=True)) |
General Comments 0
You need to be logged in to leave comments.
Login now