##// END OF EJS Templates
Make test suite more robust under Win32....
Fernando Perez -
Show More
@@ -1706,7 +1706,12 b' Currently the magic system has the following functions:\\n"""'
1706 # (leaving dangling references).
1706 # (leaving dangling references).
1707 self.shell.cache_main_mod(prog_ns,filename)
1707 self.shell.cache_main_mod(prog_ns,filename)
1708 # update IPython interactive namespace
1708 # update IPython interactive namespace
1709 del prog_ns['__name__']
1709
1710 # Some forms of read errors on the file may mean the
1711 # __name__ key was never set; using pop we don't have to
1712 # worry about a possible KeyError.
1713 prog_ns.pop('__name__', None)
1714
1710 self.shell.user_ns.update(prog_ns)
1715 self.shell.user_ns.update(prog_ns)
1711 finally:
1716 finally:
1712 # It's a bit of a mystery why, but __builtins__ can change from
1717 # It's a bit of a mystery why, but __builtins__ can change from
@@ -164,7 +164,6 b' def doctest_run_ns2():'
164 tclass.py: deleting object: C-first_pass
164 tclass.py: deleting object: C-first_pass
165 """
165 """
166
166
167 @dec.skip_win32
168 def doctest_run_builtins():
167 def doctest_run_builtins():
169 """Check that %run doesn't damage __builtins__ via a doctest.
168 """Check that %run doesn't damage __builtins__ via a doctest.
170
169
@@ -177,24 +176,34 b' def doctest_run_builtins():'
177
176
178 In [2]: bid1 = id(__builtins__)
177 In [2]: bid1 = id(__builtins__)
179
178
180 In [3]: f = tempfile.NamedTemporaryFile()
179 In [3]: fname = tempfile.mkstemp()[1]
180
181 In [3]: f = open(fname,'w')
181
182
182 In [4]: f.write('pass\\n')
183 In [4]: f.write('pass\\n')
183
184
184 In [5]: f.flush()
185 In [5]: f.flush()
185
186
186 In [6]: print 'B1:',type(__builtins__)
187 In [6]: print type(__builtins__)
187 B1: <type 'module'>
188 <type 'module'>
189
190 In [7]: %run "$fname"
188
191
189 In [7]: %run $f.name
192 In [7]: f.close()
190
193
191 In [8]: bid2 = id(__builtins__)
194 In [8]: bid2 = id(__builtins__)
192
195
193 In [9]: print 'B2:',type(__builtins__)
196 In [9]: print type(__builtins__)
194 B2: <type 'module'>
197 <type 'module'>
195
198
196 In [10]: bid1 == bid2
199 In [10]: bid1 == bid2
197 Out[10]: True
200 Out[10]: True
201
202 In [12]: try:
203 ....: os.unlink(fname)
204 ....: except:
205 ....: pass
206 ....:
198 """
207 """
199
208
200 # For some tests, it will be handy to organize them in a class with a common
209 # For some tests, it will be handy to organize them in a class with a common
@@ -204,23 +213,18 b' class TestMagicRun(object):'
204
213
205 def setup(self):
214 def setup(self):
206 """Make a valid python temp file."""
215 """Make a valid python temp file."""
207 f = tempfile.NamedTemporaryFile()
216 fname = tempfile.mkstemp()[1]
217 f = open(fname,'w')
208 f.write('pass\n')
218 f.write('pass\n')
209 f.flush()
219 f.flush()
210 self.tmpfile = f
220 self.tmpfile = f
221 self.fname = fname
211
222
212 def run_tmpfile(self):
223 def run_tmpfile(self):
213 # This fails on Windows if self.tmpfile.name has spaces or "~" in it.
224 # This fails on Windows if self.tmpfile.name has spaces or "~" in it.
214 # See below and ticket https://bugs.launchpad.net/bugs/366353
225 # See below and ticket https://bugs.launchpad.net/bugs/366353
215 _ip.magic('run %s' % self.tmpfile.name)
226 _ip.magic('run "%s"' % self.fname)
216
217 # See https://bugs.launchpad.net/bugs/366353
218 @dec.skip_if_not_win32
219 def test_run_tempfile_path(self):
220 tt.assert_equals(True,False,"%run doesn't work with tempfile paths on win32.")
221
227
222 # See https://bugs.launchpad.net/bugs/366353
223 @dec.skip_win32
224 def test_builtins_id(self):
228 def test_builtins_id(self):
225 """Check that %run doesn't damage __builtins__ """
229 """Check that %run doesn't damage __builtins__ """
226
230
@@ -230,8 +234,6 b' class TestMagicRun(object):'
230 bid2 = id(_ip.user_ns['__builtins__'])
234 bid2 = id(_ip.user_ns['__builtins__'])
231 tt.assert_equals(bid1, bid2)
235 tt.assert_equals(bid1, bid2)
232
236
233 # See https://bugs.launchpad.net/bugs/366353
234 @dec.skip_win32
235 def test_builtins_type(self):
237 def test_builtins_type(self):
236 """Check that the type of __builtins__ doesn't change with %run.
238 """Check that the type of __builtins__ doesn't change with %run.
237
239
@@ -242,8 +244,6 b' class TestMagicRun(object):'
242 self.run_tmpfile()
244 self.run_tmpfile()
243 tt.assert_equals(type(_ip.user_ns['__builtins__']),type(sys))
245 tt.assert_equals(type(_ip.user_ns['__builtins__']),type(sys))
244
246
245 # See https://bugs.launchpad.net/bugs/366353
246 @dec.skip_win32
247 def test_prompts(self):
247 def test_prompts(self):
248 """Test that prompts correctly generate after %run"""
248 """Test that prompts correctly generate after %run"""
249 self.run_tmpfile()
249 self.run_tmpfile()
@@ -252,6 +252,12 b' class TestMagicRun(object):'
252
252
253 def teardown(self):
253 def teardown(self):
254 self.tmpfile.close()
254 self.tmpfile.close()
255 try:
256 os.unlink(self.fname)
257 except:
258 # On Windows, even though we close the file, we still can't delete
259 # it. I have no clue why
260 pass
255
261
256 # Multiple tests for clipboard pasting
262 # Multiple tests for clipboard pasting
257 def test_paste():
263 def test_paste():
General Comments 0
You need to be logged in to leave comments. Login now