Show More
@@ -25,6 +25,7 b' import nose.tools as nt' | |||
|
25 | 25 | |
|
26 | 26 | # Our own |
|
27 | 27 | from IPython.core import inputsplitter as isp |
|
28 | from IPython.core.tests.test_inputtransformer import syntax, syntax_ml | |
|
28 | 29 | from IPython.testing import tools as tt |
|
29 | 30 | from IPython.utils import py3compat |
|
30 | 31 | |
@@ -427,216 +428,7 b' def test_LineInfo():' | |||
|
427 | 428 | linfo = isp.LineInfo(' %cd /home') |
|
428 | 429 | nt.assert_equal(str(linfo), 'LineInfo [ |%|cd|/home]') |
|
429 | 430 | |
|
430 | # Transformer tests | |
|
431 | def transform_checker(tests, func): | |
|
432 | """Utility to loop over test inputs""" | |
|
433 | for inp, tr in tests: | |
|
434 | nt.assert_equal(func(inp), tr) | |
|
435 | ||
|
436 | # Data for all the syntax tests in the form of lists of pairs of | |
|
437 | # raw/transformed input. We store it here as a global dict so that we can use | |
|
438 | # it both within single-function tests and also to validate the behavior of the | |
|
439 | # larger objects | |
|
440 | ||
|
441 | syntax = \ | |
|
442 | dict(assign_system = | |
|
443 | [(i,py3compat.u_format(o)) for i,o in \ | |
|
444 | [(u'a =! ls', "a = get_ipython().getoutput({u}'ls')"), | |
|
445 | (u'b = !ls', "b = get_ipython().getoutput({u}'ls')"), | |
|
446 | ('x=1', 'x=1'), # normal input is unmodified | |
|
447 | (' ',' '), # blank lines are kept intact | |
|
448 | ]], | |
|
449 | ||
|
450 | assign_magic = | |
|
451 | [(i,py3compat.u_format(o)) for i,o in \ | |
|
452 | [(u'a =% who', "a = get_ipython().magic({u}'who')"), | |
|
453 | (u'b = %who', "b = get_ipython().magic({u}'who')"), | |
|
454 | ('x=1', 'x=1'), # normal input is unmodified | |
|
455 | (' ',' '), # blank lines are kept intact | |
|
456 | ]], | |
|
457 | ||
|
458 | classic_prompt = | |
|
459 | [('>>> x=1', 'x=1'), | |
|
460 | ('x=1', 'x=1'), # normal input is unmodified | |
|
461 | (' ', ' '), # blank lines are kept intact | |
|
462 | ('... ', ''), # continuation prompts | |
|
463 | ], | |
|
464 | ||
|
465 | ipy_prompt = | |
|
466 | [('In [1]: x=1', 'x=1'), | |
|
467 | ('x=1', 'x=1'), # normal input is unmodified | |
|
468 | (' ',' '), # blank lines are kept intact | |
|
469 | (' ....: ', ''), # continuation prompts | |
|
470 | ], | |
|
471 | ||
|
472 | # Tests for the escape transformer to leave normal code alone | |
|
473 | escaped_noesc = | |
|
474 | [ (' ', ' '), | |
|
475 | ('x=1', 'x=1'), | |
|
476 | ], | |
|
477 | ||
|
478 | # System calls | |
|
479 | escaped_shell = | |
|
480 | [(i,py3compat.u_format(o)) for i,o in \ | |
|
481 | [ (u'!ls', "get_ipython().system({u}'ls')"), | |
|
482 | # Double-escape shell, this means to capture the output of the | |
|
483 | # subprocess and return it | |
|
484 | (u'!!ls', "get_ipython().getoutput({u}'ls')"), | |
|
485 | ]], | |
|
486 | ||
|
487 | # Help/object info | |
|
488 | escaped_help = | |
|
489 | [(i,py3compat.u_format(o)) for i,o in \ | |
|
490 | [ (u'?', 'get_ipython().show_usage()'), | |
|
491 | (u'?x1', "get_ipython().magic({u}'pinfo x1')"), | |
|
492 | (u'??x2', "get_ipython().magic({u}'pinfo2 x2')"), | |
|
493 | (u'?a.*s', "get_ipython().magic({u}'psearch a.*s')"), | |
|
494 | (u'?%hist1', "get_ipython().magic({u}'pinfo %hist1')"), | |
|
495 | (u'?%%hist2', "get_ipython().magic({u}'pinfo %%hist2')"), | |
|
496 | (u'?abc = qwe', "get_ipython().magic({u}'pinfo abc')"), | |
|
497 | ]], | |
|
498 | ||
|
499 | end_help = | |
|
500 | [(i,py3compat.u_format(o)) for i,o in \ | |
|
501 | [ (u'x3?', "get_ipython().magic({u}'pinfo x3')"), | |
|
502 | (u'x4??', "get_ipython().magic({u}'pinfo2 x4')"), | |
|
503 | (u'%hist1?', "get_ipython().magic({u}'pinfo %hist1')"), | |
|
504 | (u'%hist2??', "get_ipython().magic({u}'pinfo2 %hist2')"), | |
|
505 | (u'%%hist3?', "get_ipython().magic({u}'pinfo %%hist3')"), | |
|
506 | (u'%%hist4??', "get_ipython().magic({u}'pinfo2 %%hist4')"), | |
|
507 | (u'f*?', "get_ipython().magic({u}'psearch f*')"), | |
|
508 | (u'ax.*aspe*?', "get_ipython().magic({u}'psearch ax.*aspe*')"), | |
|
509 | (u'a = abc?', "get_ipython().set_next_input({u}'a = abc');" | |
|
510 | "get_ipython().magic({u}'pinfo abc')"), | |
|
511 | (u'a = abc.qe??', "get_ipython().set_next_input({u}'a = abc.qe');" | |
|
512 | "get_ipython().magic({u}'pinfo2 abc.qe')"), | |
|
513 | (u'a = *.items?', "get_ipython().set_next_input({u}'a = *.items');" | |
|
514 | "get_ipython().magic({u}'psearch *.items')"), | |
|
515 | (u'plot(a?', "get_ipython().set_next_input({u}'plot(a');" | |
|
516 | "get_ipython().magic({u}'pinfo a')"), | |
|
517 | (u'a*2 #comment?', 'a*2 #comment?'), | |
|
518 | ]], | |
|
519 | ||
|
520 | # Explicit magic calls | |
|
521 | escaped_magic = | |
|
522 | [(i,py3compat.u_format(o)) for i,o in \ | |
|
523 | [ (u'%cd', "get_ipython().magic({u}'cd')"), | |
|
524 | (u'%cd /home', "get_ipython().magic({u}'cd /home')"), | |
|
525 | # Backslashes need to be escaped. | |
|
526 | (u'%cd C:\\User', "get_ipython().magic({u}'cd C:\\\\User')"), | |
|
527 | (u' %magic', " get_ipython().magic({u}'magic')"), | |
|
528 | ]], | |
|
529 | ||
|
530 | # Quoting with separate arguments | |
|
531 | escaped_quote = | |
|
532 | [ (',f', 'f("")'), | |
|
533 | (',f x', 'f("x")'), | |
|
534 | (' ,f y', ' f("y")'), | |
|
535 | (',f a b', 'f("a", "b")'), | |
|
536 | ], | |
|
537 | ||
|
538 | # Quoting with single argument | |
|
539 | escaped_quote2 = | |
|
540 | [ (';f', 'f("")'), | |
|
541 | (';f x', 'f("x")'), | |
|
542 | (' ;f y', ' f("y")'), | |
|
543 | (';f a b', 'f("a b")'), | |
|
544 | ], | |
|
545 | ||
|
546 | # Simply apply parens | |
|
547 | escaped_paren = | |
|
548 | [ ('/f', 'f()'), | |
|
549 | ('/f x', 'f(x)'), | |
|
550 | (' /f y', ' f(y)'), | |
|
551 | ('/f a b', 'f(a, b)'), | |
|
552 | ], | |
|
553 | ||
|
554 | # Check that we transform prompts before other transforms | |
|
555 | mixed = | |
|
556 | [(i,py3compat.u_format(o)) for i,o in \ | |
|
557 | [ (u'In [1]: %lsmagic', "get_ipython().magic({u}'lsmagic')"), | |
|
558 | (u'>>> %lsmagic', "get_ipython().magic({u}'lsmagic')"), | |
|
559 | (u'In [2]: !ls', "get_ipython().system({u}'ls')"), | |
|
560 | (u'In [3]: abs?', "get_ipython().magic({u}'pinfo abs')"), | |
|
561 | (u'In [4]: b = %who', "b = get_ipython().magic({u}'who')"), | |
|
562 | ]], | |
|
563 | ) | |
|
564 | ||
|
565 | # multiline syntax examples. Each of these should be a list of lists, with | |
|
566 | # each entry itself having pairs of raw/transformed input. The union (with | |
|
567 | # '\n'.join() of the transformed inputs is what the splitter should produce | |
|
568 | # when fed the raw lines one at a time via push. | |
|
569 | syntax_ml = \ | |
|
570 | dict(classic_prompt = | |
|
571 | [ [('>>> for i in range(10):','for i in range(10):'), | |
|
572 | ('... print i',' print i'), | |
|
573 | ('... ', ''), | |
|
574 | ], | |
|
575 | ], | |
|
576 | ||
|
577 | ipy_prompt = | |
|
578 | [ [('In [24]: for i in range(10):','for i in range(10):'), | |
|
579 | (' ....: print i',' print i'), | |
|
580 | (' ....: ', ''), | |
|
581 | ], | |
|
582 | ], | |
|
583 | ||
|
584 | multiline_datastructure = | |
|
585 | [ [('>>> a = [1,','a = [1,'), | |
|
586 | ('... 2]','2]'), | |
|
587 | ], | |
|
588 | ], | |
|
589 | ) | |
|
590 | ||
|
591 | ||
|
592 | def test_assign_system(): | |
|
593 | tt.check_pairs(isp.transform_assign_system, syntax['assign_system']) | |
|
594 | ||
|
595 | ||
|
596 | def test_assign_magic(): | |
|
597 | tt.check_pairs(isp.transform_assign_magic, syntax['assign_magic']) | |
|
598 | ||
|
599 | ||
|
600 | def test_classic_prompt(): | |
|
601 | transform_checker(syntax['classic_prompt'], isp.transform_classic_prompt) | |
|
602 | for example in syntax_ml['classic_prompt']: | |
|
603 | transform_checker(example, isp.transform_classic_prompt) | |
|
604 | ||
|
605 | ||
|
606 | def test_ipy_prompt(): | |
|
607 | transform_checker(syntax['ipy_prompt'], isp.transform_ipy_prompt) | |
|
608 | for example in syntax_ml['ipy_prompt']: | |
|
609 | transform_checker(example, isp.transform_ipy_prompt) | |
|
610 | ||
|
611 | def test_end_help(): | |
|
612 | tt.check_pairs(isp.transform_help_end, syntax['end_help']) | |
|
613 | ||
|
614 | def test_escaped_noesc(): | |
|
615 | tt.check_pairs(isp.transform_escaped, syntax['escaped_noesc']) | |
|
616 | ||
|
617 | 431 | |
|
618 | def test_escaped_shell(): | |
|
619 | tt.check_pairs(isp.transform_escaped, syntax['escaped_shell']) | |
|
620 | ||
|
621 | ||
|
622 | def test_escaped_help(): | |
|
623 | tt.check_pairs(isp.transform_escaped, syntax['escaped_help']) | |
|
624 | ||
|
625 | ||
|
626 | def test_escaped_magic(): | |
|
627 | tt.check_pairs(isp.transform_escaped, syntax['escaped_magic']) | |
|
628 | ||
|
629 | ||
|
630 | def test_escaped_quote(): | |
|
631 | tt.check_pairs(isp.transform_escaped, syntax['escaped_quote']) | |
|
632 | ||
|
633 | ||
|
634 | def test_escaped_quote2(): | |
|
635 | tt.check_pairs(isp.transform_escaped, syntax['escaped_quote2']) | |
|
636 | ||
|
637 | ||
|
638 | def test_escaped_paren(): | |
|
639 | tt.check_pairs(isp.transform_escaped, syntax['escaped_paren']) | |
|
640 | 432 | |
|
641 | 433 | |
|
642 | 434 | class IPythonInputTestCase(InputSplitterTestCase): |
@@ -3,82 +3,303 b' import nose.tools as nt' | |||
|
3 | 3 | |
|
4 | 4 | from IPython.testing import tools as tt |
|
5 | 5 | from IPython.utils import py3compat |
|
6 | u_fmt = py3compat.u_format | |
|
6 | 7 | |
|
7 | from IPython.core import inputtransformer | |
|
8 | from IPython.core.tests.test_inputsplitter import syntax | |
|
8 | from IPython.core import inputtransformer as ipt | |
|
9 | 9 | |
|
10 |
def |
|
|
10 | def transform_and_reset(transformer): | |
|
11 | 11 | def transform(inp): |
|
12 | results = [] | |
|
13 | for line in inp: | |
|
14 | res = transformer.push(line) | |
|
15 | if res is not None: | |
|
16 | results.append(res) | |
|
17 | transformer.reset() | |
|
18 | return results | |
|
12 | try: | |
|
13 | return transformer.push(inp) | |
|
14 | finally: | |
|
15 | transformer.reset() | |
|
19 | 16 | |
|
20 | 17 | return transform |
|
21 | 18 | |
|
22 | cellmagic_tests = [ | |
|
23 | (['%%foo a', None], ["get_ipython().run_cell_magic('foo', 'a', '')"]), | |
|
24 | (['%%bar 123', 'hello', ''], ["get_ipython().run_cell_magic('bar', '123', 'hello')"]), | |
|
25 | ] | |
|
19 | # Transformer tests | |
|
20 | def transform_checker(tests, transformer): | |
|
21 | """Utility to loop over test inputs""" | |
|
22 | try: | |
|
23 | for inp, tr in tests: | |
|
24 | nt.assert_equal(transformer.push(inp), tr) | |
|
25 | finally: | |
|
26 | transformer.reset() | |
|
27 | ||
|
28 | # Data for all the syntax tests in the form of lists of pairs of | |
|
29 | # raw/transformed input. We store it here as a global dict so that we can use | |
|
30 | # it both within single-function tests and also to validate the behavior of the | |
|
31 | # larger objects | |
|
32 | ||
|
33 | syntax = \ | |
|
34 | dict(assign_system = | |
|
35 | [(i,py3compat.u_format(o)) for i,o in \ | |
|
36 | [(u'a =! ls', "a = get_ipython().getoutput({u}'ls')"), | |
|
37 | (u'b = !ls', "b = get_ipython().getoutput({u}'ls')"), | |
|
38 | ('x=1', 'x=1'), # normal input is unmodified | |
|
39 | (' ',' '), # blank lines are kept intact | |
|
40 | ]], | |
|
41 | ||
|
42 | assign_magic = | |
|
43 | [(i,py3compat.u_format(o)) for i,o in \ | |
|
44 | [(u'a =% who', "a = get_ipython().magic({u}'who')"), | |
|
45 | (u'b = %who', "b = get_ipython().magic({u}'who')"), | |
|
46 | ('x=1', 'x=1'), # normal input is unmodified | |
|
47 | (' ',' '), # blank lines are kept intact | |
|
48 | ]], | |
|
49 | ||
|
50 | classic_prompt = | |
|
51 | [('>>> x=1', 'x=1'), | |
|
52 | ('x=1', 'x=1'), # normal input is unmodified | |
|
53 | (' ', ' '), # blank lines are kept intact | |
|
54 | ], | |
|
55 | ||
|
56 | ipy_prompt = | |
|
57 | [('In [1]: x=1', 'x=1'), | |
|
58 | ('x=1', 'x=1'), # normal input is unmodified | |
|
59 | (' ',' '), # blank lines are kept intact | |
|
60 | ], | |
|
61 | ||
|
62 | # Tests for the escape transformer to leave normal code alone | |
|
63 | escaped_noesc = | |
|
64 | [ (' ', ' '), | |
|
65 | ('x=1', 'x=1'), | |
|
66 | ], | |
|
67 | ||
|
68 | # System calls | |
|
69 | escaped_shell = | |
|
70 | [(i,py3compat.u_format(o)) for i,o in \ | |
|
71 | [ (u'!ls', "get_ipython().system({u}'ls')"), | |
|
72 | # Double-escape shell, this means to capture the output of the | |
|
73 | # subprocess and return it | |
|
74 | (u'!!ls', "get_ipython().getoutput({u}'ls')"), | |
|
75 | ]], | |
|
76 | ||
|
77 | # Help/object info | |
|
78 | escaped_help = | |
|
79 | [(i,py3compat.u_format(o)) for i,o in \ | |
|
80 | [ (u'?', 'get_ipython().show_usage()'), | |
|
81 | (u'?x1', "get_ipython().magic({u}'pinfo x1')"), | |
|
82 | (u'??x2', "get_ipython().magic({u}'pinfo2 x2')"), | |
|
83 | (u'?a.*s', "get_ipython().magic({u}'psearch a.*s')"), | |
|
84 | (u'?%hist1', "get_ipython().magic({u}'pinfo %hist1')"), | |
|
85 | (u'?%%hist2', "get_ipython().magic({u}'pinfo %%hist2')"), | |
|
86 | (u'?abc = qwe', "get_ipython().magic({u}'pinfo abc')"), | |
|
87 | ]], | |
|
88 | ||
|
89 | end_help = | |
|
90 | [(i,py3compat.u_format(o)) for i,o in \ | |
|
91 | [ (u'x3?', "get_ipython().magic({u}'pinfo x3')"), | |
|
92 | (u'x4??', "get_ipython().magic({u}'pinfo2 x4')"), | |
|
93 | (u'%hist1?', "get_ipython().magic({u}'pinfo %hist1')"), | |
|
94 | (u'%hist2??', "get_ipython().magic({u}'pinfo2 %hist2')"), | |
|
95 | (u'%%hist3?', "get_ipython().magic({u}'pinfo %%hist3')"), | |
|
96 | (u'%%hist4??', "get_ipython().magic({u}'pinfo2 %%hist4')"), | |
|
97 | (u'f*?', "get_ipython().magic({u}'psearch f*')"), | |
|
98 | (u'ax.*aspe*?', "get_ipython().magic({u}'psearch ax.*aspe*')"), | |
|
99 | (u'a = abc?', "get_ipython().set_next_input({u}'a = abc');" | |
|
100 | "get_ipython().magic({u}'pinfo abc')"), | |
|
101 | (u'a = abc.qe??', "get_ipython().set_next_input({u}'a = abc.qe');" | |
|
102 | "get_ipython().magic({u}'pinfo2 abc.qe')"), | |
|
103 | (u'a = *.items?', "get_ipython().set_next_input({u}'a = *.items');" | |
|
104 | "get_ipython().magic({u}'psearch *.items')"), | |
|
105 | (u'plot(a?', "get_ipython().set_next_input({u}'plot(a');" | |
|
106 | "get_ipython().magic({u}'pinfo a')"), | |
|
107 | (u'a*2 #comment?', 'a*2 #comment?'), | |
|
108 | ]], | |
|
109 | ||
|
110 | # Explicit magic calls | |
|
111 | escaped_magic = | |
|
112 | [(i,py3compat.u_format(o)) for i,o in \ | |
|
113 | [ (u'%cd', "get_ipython().magic({u}'cd')"), | |
|
114 | (u'%cd /home', "get_ipython().magic({u}'cd /home')"), | |
|
115 | # Backslashes need to be escaped. | |
|
116 | (u'%cd C:\\User', "get_ipython().magic({u}'cd C:\\\\User')"), | |
|
117 | (u' %magic', " get_ipython().magic({u}'magic')"), | |
|
118 | ]], | |
|
119 | ||
|
120 | # Quoting with separate arguments | |
|
121 | escaped_quote = | |
|
122 | [ (',f', 'f("")'), | |
|
123 | (',f x', 'f("x")'), | |
|
124 | (' ,f y', ' f("y")'), | |
|
125 | (',f a b', 'f("a", "b")'), | |
|
126 | ], | |
|
127 | ||
|
128 | # Quoting with single argument | |
|
129 | escaped_quote2 = | |
|
130 | [ (';f', 'f("")'), | |
|
131 | (';f x', 'f("x")'), | |
|
132 | (' ;f y', ' f("y")'), | |
|
133 | (';f a b', 'f("a b")'), | |
|
134 | ], | |
|
135 | ||
|
136 | # Simply apply parens | |
|
137 | escaped_paren = | |
|
138 | [ ('/f', 'f()'), | |
|
139 | ('/f x', 'f(x)'), | |
|
140 | (' /f y', ' f(y)'), | |
|
141 | ('/f a b', 'f(a, b)'), | |
|
142 | ], | |
|
143 | ||
|
144 | # Check that we transform prompts before other transforms | |
|
145 | mixed = | |
|
146 | [(i,py3compat.u_format(o)) for i,o in \ | |
|
147 | [ (u'In [1]: %lsmagic', "get_ipython().magic({u}'lsmagic')"), | |
|
148 | (u'>>> %lsmagic', "get_ipython().magic({u}'lsmagic')"), | |
|
149 | (u'In [2]: !ls', "get_ipython().system({u}'ls')"), | |
|
150 | (u'In [3]: abs?', "get_ipython().magic({u}'pinfo abs')"), | |
|
151 | (u'In [4]: b = %who', "b = get_ipython().magic({u}'who')"), | |
|
152 | ]], | |
|
153 | ) | |
|
26 | 154 | |
|
27 | def test_transform_cellmagic(): | |
|
28 | tt.check_pairs(wrap_transform(inputtransformer.cellmagic), cellmagic_tests) | |
|
155 | # multiline syntax examples. Each of these should be a list of lists, with | |
|
156 | # each entry itself having pairs of raw/transformed input. The union (with | |
|
157 | # '\n'.join() of the transformed inputs is what the splitter should produce | |
|
158 | # when fed the raw lines one at a time via push. | |
|
159 | syntax_ml = \ | |
|
160 | dict(classic_prompt = | |
|
161 | [ [('>>> for i in range(10):','for i in range(10):'), | |
|
162 | ('... print i',' print i'), | |
|
163 | ('... ', ''), | |
|
164 | ], | |
|
165 | [('>>> a="""','a="""'), | |
|
166 | ('... 123"""','123"""'), | |
|
167 | ], | |
|
168 | [('a="""','a="""'), | |
|
169 | ('... 123"""','... 123"""'), | |
|
170 | ], | |
|
171 | ], | |
|
29 | 172 | |
|
30 | esctransform_tests = [(i, [py3compat.u_format(ol) for ol in o]) for i,o in [ | |
|
31 | (['%pdef zip'], ["get_ipython().magic({u}'pdef zip')"]), | |
|
32 | (['%abc def \\', 'ghi'], ["get_ipython().magic({u}'abc def ghi')"]), | |
|
33 | (['%abc def \\', 'ghi\\', None], ["get_ipython().magic({u}'abc def ghi')"]), | |
|
34 | ]] | |
|
173 | ipy_prompt = | |
|
174 | [ [('In [24]: for i in range(10):','for i in range(10):'), | |
|
175 | (' ....: print i',' print i'), | |
|
176 | (' ....: ', ''), | |
|
177 | ], | |
|
178 | [('In [2]: a="""','a="""'), | |
|
179 | (' ...: 123"""','123"""'), | |
|
180 | ], | |
|
181 | [('a="""','a="""'), | |
|
182 | (' ...: 123"""',' ...: 123"""'), | |
|
183 | ], | |
|
184 | ], | |
|
35 | 185 | |
|
36 | def test_transform_escaped(): | |
|
37 | tt.check_pairs(wrap_transform(inputtransformer.escaped_transformer), esctransform_tests) | |
|
186 | multiline_datastructure = | |
|
187 | [ [('>>> a = [1,','a = [1,'), | |
|
188 | ('... 2]','2]'), | |
|
189 | ], | |
|
190 | ], | |
|
191 | ||
|
192 | leading_indent = | |
|
193 | [ [(' print "hi"','print "hi"'), | |
|
194 | (' for a in range(5):','for a in range(5):'), | |
|
195 | (' a*2',' a*2'), | |
|
196 | ], | |
|
197 | [(' a="""','a="""'), | |
|
198 | (' 123"""','123"""'), | |
|
199 | ], | |
|
200 | [('a="""','a="""'), | |
|
201 | (' 123"""',' 123"""'), | |
|
202 | ], | |
|
203 | ], | |
|
204 | ||
|
205 | cellmagic = | |
|
206 | [ [('%%foo a', None), | |
|
207 | (None, "get_ipython().run_cell_magic('foo', 'a', '')"), | |
|
208 | ], | |
|
209 | [('%%bar 123', None), | |
|
210 | ('hello', None), | |
|
211 | ('', "get_ipython().run_cell_magic('bar', '123', 'hello')"), | |
|
212 | ], | |
|
213 | ], | |
|
214 | ||
|
215 | escaped = | |
|
216 | [ [('%abc def \\', None), | |
|
217 | ('ghi', u_fmt("get_ipython().magic({u}'abc def ghi')")), | |
|
218 | ], | |
|
219 | [('%abc def \\', None), | |
|
220 | ('ghi\\', None), | |
|
221 | (None, u_fmt("get_ipython().magic({u}'abc def ghi')")), | |
|
222 | ], | |
|
223 | ], | |
|
224 | ||
|
225 | assign_magic = | |
|
226 | [ [('a = %bc de \\', None), | |
|
227 | ('fg', "a = get_ipython().magic('bc de fg')"), | |
|
228 | ], | |
|
229 | [('a = %bc de \\', None), | |
|
230 | ('fg\\', None), | |
|
231 | (None, "a = get_ipython().magic('bc de fg')"), | |
|
232 | ], | |
|
233 | ], | |
|
234 | ||
|
235 | assign_system = | |
|
236 | [ [('a = !bc de \\', None), | |
|
237 | ('fg', "a = get_ipython().getoutput('bc de fg')"), | |
|
238 | ], | |
|
239 | [('a = !bc de \\', None), | |
|
240 | ('fg\\', None), | |
|
241 | (None, "a = get_ipython().getoutput('bc de fg')"), | |
|
242 | ], | |
|
243 | ], | |
|
244 | ) | |
|
38 | 245 | |
|
39 | def endhelp_test(): | |
|
40 | tt.check_pairs(inputtransformer.help_end.push, syntax['end_help']) | |
|
41 | 246 | |
|
42 | classic_prompt_tests = [ | |
|
43 | (['>>> a=1'], ['a=1']), | |
|
44 | (['>>> a="""','... 123"""'], ['a="""', '123"""']), | |
|
45 | (['a="""','... 123"""'], ['a="""', '... 123"""']), | |
|
46 | ] | |
|
247 | def test_assign_system(): | |
|
248 | tt.check_pairs(transform_and_reset(ipt.assign_from_system), syntax['assign_system']) | |
|
249 | for example in syntax_ml['assign_system']: | |
|
250 | transform_checker(example, ipt.assign_from_system) | |
|
251 | ||
|
252 | def test_assign_magic(): | |
|
253 | tt.check_pairs(transform_and_reset(ipt.assign_from_magic), syntax['assign_magic']) | |
|
254 | for example in syntax_ml['assign_magic']: | |
|
255 | transform_checker(example, ipt.assign_from_magic) | |
|
256 | ||
|
47 | 257 | |
|
48 | 258 | def test_classic_prompt(): |
|
49 |
tt.check_pairs( |
|
|
259 | tt.check_pairs(transform_and_reset(ipt.classic_prompt), syntax['classic_prompt']) | |
|
260 | for example in syntax_ml['classic_prompt']: | |
|
261 | transform_checker(example, ipt.classic_prompt) | |
|
50 | 262 | |
|
51 | ipy_prompt_tests = [ | |
|
52 | (['In [1]: a=1'], ['a=1']), | |
|
53 | (['In [2]: a="""',' ...: 123"""'], ['a="""', '123"""']), | |
|
54 | (['a="""',' ...: 123"""'], ['a="""', ' ...: 123"""']), | |
|
55 | ] | |
|
56 | 263 | |
|
57 | 264 | def test_ipy_prompt(): |
|
58 |
tt.check_pairs( |
|
|
265 | tt.check_pairs(transform_and_reset(ipt.ipy_prompt), syntax['ipy_prompt']) | |
|
266 | for example in syntax_ml['ipy_prompt']: | |
|
267 | transform_checker(example, ipt.ipy_prompt) | |
|
59 | 268 | |
|
60 | leading_indent_tests = [ | |
|
61 | ([' print "hi"'], ['print "hi"']), | |
|
62 | ([' for a in range(5):', ' a*2'], ['for a in range(5):', ' a*2']), | |
|
63 | ([' a="""',' 123"""'], ['a="""', '123"""']), | |
|
64 | (['a="""',' 123"""'], ['a="""', ' 123"""']), | |
|
65 | ] | |
|
269 | def test_help_end(): | |
|
270 | tt.check_pairs(transform_and_reset(ipt.help_end), syntax['end_help']) | |
|
66 | 271 | |
|
67 |
def test_ |
|
|
68 | tt.check_pairs(wrap_transform(inputtransformer.leading_indent), leading_indent_tests) | |
|
272 | def test_escaped_noesc(): | |
|
273 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_noesc']) | |
|
69 | 274 | |
|
70 | assign_magic_tests = [(i, [py3compat.u_format(ol) for ol in o]) for i,o in [ | |
|
71 | (['a = %bc de \\', 'fg'], ["a = get_ipython().magic('bc de fg')"]), | |
|
72 | (['a = %bc de \\', 'fg\\', None], ["a = get_ipython().magic('bc de fg')"]), | |
|
73 | ]] | |
|
74 | 275 | |
|
75 | def test_assign_magic(): | |
|
76 | tt.check_pairs(wrap_transform(inputtransformer.assign_from_magic), assign_magic_tests) | |
|
276 | def test_escaped_shell(): | |
|
277 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_shell']) | |
|
77 | 278 | |
|
78 | assign_system_tests = [(i, [py3compat.u_format(ol) for ol in o]) for i,o in [ | |
|
79 | (['a = !bc de \\', 'fg'], ["a = get_ipython().getoutput('bc de fg')"]), | |
|
80 | (['a = !bc de \\', 'fg\\', None], ["a = get_ipython().getoutput('bc de fg')"]), | |
|
81 | ]] | |
|
82 | 279 | |
|
83 |
def test_ |
|
|
84 | tt.check_pairs(wrap_transform(inputtransformer.assign_from_system), assign_system_tests) | |
|
280 | def test_escaped_help(): | |
|
281 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_help']) | |
|
282 | ||
|
283 | ||
|
284 | def test_escaped_magic(): | |
|
285 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_magic']) | |
|
286 | ||
|
287 | ||
|
288 | def test_escaped_quote(): | |
|
289 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_quote']) | |
|
290 | ||
|
291 | ||
|
292 | def test_escaped_quote2(): | |
|
293 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_quote2']) | |
|
294 | ||
|
295 | ||
|
296 | def test_escaped_paren(): | |
|
297 | tt.check_pairs(transform_and_reset(ipt.escaped_transformer), syntax['escaped_paren']) | |
|
298 | ||
|
299 | def test_escaped_multiline(): | |
|
300 | for example in syntax_ml['escaped']: | |
|
301 | transform_checker(example, ipt.escaped_transformer) | |
|
302 | ||
|
303 | def test_cellmagic(): | |
|
304 | for example in syntax_ml['cellmagic']: | |
|
305 | transform_checker(example, ipt.cellmagic) |
General Comments 0
You need to be logged in to leave comments.
Login now