##// END OF EJS Templates
Fix tests for cpaste to use email quotes consistently in pasted blocks.
Fernando Perez -
Show More
@@ -35,7 +35,6 b' def check_cpaste(code, should_fail=False):'
35 35 if not hasattr(src, 'encoding'):
36 36 # IPython expects stdin to have an encoding attribute
37 37 src.encoding = None
38 src.write('\n')
39 38 src.write(code)
40 39 src.write('\n--\n')
41 40 src.seek(0)
@@ -58,30 +57,30 b' PY31 = sys.version_info[:2] == (3,1)'
58 57 def test_cpaste():
59 58 """Test cpaste magic"""
60 59
61 def run():
60 def runf():
62 61 """Marker function: sets a flag when executed.
63 62 """
64 63 _ip.user_ns['code_ran'] = True
65 return 'run' # return string so '+ run()' doesn't result in success
66
67 tests = {'pass': ["run()",
68 "In [1]: run()",
69 "In [1]: if 1:\n ...: run()",
70 "> > > run()",
71 ">>> run()",
72 " >>> run()",
64 return 'runf' # return string so '+ runf()' doesn't result in success
65
66 tests = {'pass': ["runf()",
67 "In [1]: runf()",
68 "In [1]: if 1:\n ...: runf()",
69 "> > > runf()",
70 ">>> runf()",
71 " >>> runf()",
73 72 ],
74 73
75 'fail': ["1 + run()",
74 'fail': ["1 + runf()",
76 75 ]}
77 76
78 77 # I don't know why this is failing specifically on Python 3.1. I've
79 78 # checked it manually interactively, but we don't care enough about 3.1
80 79 # to spend time fiddling with the tests, so we just skip it.
81 80 if not PY31:
82 tests['fail'].append("++ run()")
81 tests['fail'].append("++ runf()")
83 82
84 _ip.user_ns['run'] = run
83 _ip.user_ns['runf'] = runf
85 84
86 85 for code in tests['pass']:
87 86 check_cpaste(code)
@@ -108,13 +107,15 b' class PasteTestCase(TestCase):'
108 107
109 108 def test_paste(self):
110 109 ip.user_ns.pop('x', None)
111 self.paste('x=1')
110 self.paste('x = 1')
112 111 nt.assert_equal(ip.user_ns['x'], 1)
112 ip.user_ns.pop('x')
113 113
114 114 def test_paste_pyprompt(self):
115 115 ip.user_ns.pop('x', None)
116 116 self.paste('>>> x=2')
117 117 nt.assert_equal(ip.user_ns['x'], 2)
118 ip.user_ns.pop('x')
118 119
119 120 def test_paste_py_multi(self):
120 121 self.paste("""
@@ -122,45 +123,44 b' class PasteTestCase(TestCase):'
122 123 >>> y = []
123 124 >>> for i in x:
124 125 ... y.append(i**2)
125 ...
126 ...
126 127 """)
127 128 nt.assert_equal(ip.user_ns['x'], [1,2,3])
128 129 nt.assert_equal(ip.user_ns['y'], [1,4,9])
129 130
130 131 def test_paste_py_multi_r(self):
131 132 "Now, test that self.paste -r works"
132 ip.user_ns.pop('x', None)
133 nt.assert_equal(ip.user_ns.pop('x'), [1,2,3])
134 nt.assert_equal(ip.user_ns.pop('y'), [1,4,9])
133 135 nt.assert_false('x' in ip.user_ns)
134 136 ip.magic('paste -r')
135 137 nt.assert_equal(ip.user_ns['x'], [1,2,3])
138 nt.assert_equal(ip.user_ns['y'], [1,4,9])
136 139
137 140 def test_paste_email(self):
138 141 "Test pasting of email-quoted contents"
139 self.paste("""
142 self.paste("""\
140 143 >> def foo(x):
141 144 >> return x + 1
142 >> x = foo(1.1)
143 """)
144 nt.assert_equal(ip.user_ns['x'], 2.1)
145 >> xx = foo(1.1)""")
146 nt.assert_equal(ip.user_ns['xx'], 2.1)
145 147
146 148 def test_paste_email2(self):
147 149 "Email again; some programs add a space also at each quoting level"
148 self.paste("""
150 self.paste("""\
149 151 > > def foo(x):
150 152 > > return x + 1
151 > > x = foo(2.1)
152 """)
153 nt.assert_equal(ip.user_ns['x'], 3.1)
153 > > yy = foo(2.1) """)
154 nt.assert_equal(ip.user_ns['yy'], 3.1)
154 155
155 156 def test_paste_email_py(self):
156 157 "Email quoting of interactive input"
157 self.paste("""
158 self.paste("""\
158 159 >> >>> def f(x):
159 160 >> ... return x+1
160 >> ...
161 >> >>> x = f(2.5)
162 """)
163 nt.assert_equal(ip.user_ns['x'], 3.5)
161 >> ...
162 >> >>> zz = f(2.5) """)
163 nt.assert_equal(ip.user_ns['zz'], 3.5)
164 164
165 165 def test_paste_echo(self):
166 166 "Also test self.paste echoing, by temporarily faking the writer"
@@ -200,6 +200,5 b' def funcfoo():'
200 200 return 'fooresult'
201 201 '''
202 202 ip.user_ns.pop('funcfoo', None)
203 tm.store_or_execute(s, 'foosrc')
204 nt.assert_in('foosrc', ip.user_ns)
203 self.paste(s)
205 204 nt.assert_equals(ip.user_ns['funcfoo'](), 'fooresult')
General Comments 0
You need to be logged in to leave comments. Login now