##// END OF EJS Templates
Fix test for issue #114, in this case the test had a small error....
Fernando Perez -
Show More
@@ -1,59 +1,68 b''
1 """Tests for input manipulation machinery."""
1 """Tests for input manipulation machinery."""
2
2
3 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
4 # Imports
4 # Imports
5 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
6 import nose.tools as nt
6 import nose.tools as nt
7
7
8 from IPython.testing import tools as tt, decorators as dec
8 from IPython.testing import tools as tt, decorators as dec
9 from IPython.testing.globalipapp import get_ipython
9 from IPython.testing.globalipapp import get_ipython
10
10
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12 # Tests
12 # Tests
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 ip = get_ipython()
14 ip = get_ipython()
15
15
16 @dec.parametric
16 @dec.parametric
17 def test_prefilter():
17 def test_prefilter():
18 """Test user input conversions"""
18 """Test user input conversions"""
19
19
20 # pairs of (raw, expected correct) input
20 # pairs of (raw, expected correct) input
21 pairs = [ ('2+2','2+2'),
21 pairs = [ ('2+2','2+2'),
22 ('>>> 2+2','2+2'),
22 ('>>> 2+2','2+2'),
23 ('>>> # This is a comment\n'
23 ('>>> # This is a comment\n'
24 '... 2+2',
24 '... 2+2',
25 '# This is a comment\n'
25 '# This is a comment\n'
26 '2+2'),
26 '2+2'),
27 # Some IPython input
27 # Some IPython input
28 ('In [1]: 1', '1'),
28 ('In [1]: 1', '1'),
29 ('In [2]: for i in range(5):\n'
29 ('In [2]: for i in range(5):\n'
30 ' ...: print i,',
30 ' ...: print i,',
31 'for i in range(5):\n'
31 'for i in range(5):\n'
32 ' print i,'),
32 ' print i,'),
33 ]
33 ]
34
34
35 for raw, correct in pairs:
35 for raw, correct in pairs:
36 yield nt.assert_equals(ip.prefilter(raw), correct)
36 yield nt.assert_equals(ip.prefilter(raw), correct)
37
37
38 @dec.parametric
38 @dec.parametric
39 def test_autocall_binops():
39 def test_autocall_binops():
40 """See https://bugs.launchpad.net/ipython/+bug/315706"""
40 """See https://bugs.launchpad.net/ipython/+bug/315706"""
41 ip.magic('autocall 2')
41 ip.magic('autocall 2')
42 f = lambda x: x
42 f = lambda x: x
43 ip.user_ns['f'] = f
43 ip.user_ns['f'] = f
44 try:
44 try:
45 yield nt.assert_equals(ip.prefilter('f 1'),'f(1)')
45 yield nt.assert_equals(ip.prefilter('f 1'),'f(1)')
46 for t in ['f +1', 'f -1']:
46 for t in ['f +1', 'f -1']:
47 yield nt.assert_equals(ip.prefilter(t), t)
47 yield nt.assert_equals(ip.prefilter(t), t)
48 finally:
48 finally:
49 ip.magic('autocall 0')
49 ip.magic('autocall 0')
50 del ip.user_ns['f']
50 del ip.user_ns['f']
51
51
52 @dec.parametric
52 @dec.parametric
53 def test_issue114():
53 def test_issue114():
54 """Check that multiline string literals don't expand as magic
54 """Check that multiline string literals don't expand as magic
55 see http://github.com/ipython/ipython/issues/#issue/114"""
55 see http://github.com/ipython/ipython/issues/#issue/114"""
56
56 template = '"""\n%s\n"""'
57 template = '"""\n%s\n"""'
58 # Store the current value of multi_line_specials and turn it off before
59 # running test, since it could be true (case in which the test doesn't make
60 # sense, as multiline string literals *will* expand as magic in that case).
61 msp = ip.prefilter_manager.multi_line_specials
62 ip.prefilter_manager.multi_line_specials = False
63 try:
57 for mgk in ip.lsmagic():
64 for mgk in ip.lsmagic():
58 raw = template % mgk
65 raw = template % mgk
59 yield nt.assert_equals(ip.prefilter(raw), raw)
66 yield nt.assert_equals(ip.prefilter(raw), raw)
67 finally:
68 ip.prefilter_manager.multi_line_specials = msp
General Comments 0
You need to be logged in to leave comments. Login now