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