##// END OF EJS Templates
Merging -r 1186 from lp:ipython.
Brian Granger -
r2137:349d1e30 merge
parent child Browse files
Show More
@@ -1707,7 +1707,12 b' Currently the magic system has the following functions:\\n"""'
1707 1707 # (leaving dangling references).
1708 1708 self.shell.cache_main_mod(prog_ns,filename)
1709 1709 # update IPython interactive namespace
1710 del prog_ns['__name__']
1710
1711 # Some forms of read errors on the file may mean the
1712 # __name__ key was never set; using pop we don't have to
1713 # worry about a possible KeyError.
1714 prog_ns.pop('__name__', None)
1715
1711 1716 self.shell.user_ns.update(prog_ns)
1712 1717 finally:
1713 1718 # It's a bit of a mystery why, but __builtins__ can change from
@@ -164,7 +164,6 b' def doctest_run_ns2():'
164 164 tclass.py: deleting object: C-first_pass
165 165 """
166 166
167 @dec.skip_win32
168 167 def doctest_run_builtins():
169 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 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 183 In [4]: f.write('pass\\n')
183 184
184 185 In [5]: f.flush()
185 186
186 In [6]: print 'B1:',type(__builtins__)
187 B1: <type 'module'>
187 In [6]: print type(__builtins__)
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 194 In [8]: bid2 = id(__builtins__)
192 195
193 In [9]: print 'B2:',type(__builtins__)
194 B2: <type 'module'>
196 In [9]: print type(__builtins__)
197 <type 'module'>
195 198
196 199 In [10]: bid1 == bid2
197 200 Out[10]: True
201
202 In [12]: try:
203 ....: os.unlink(fname)
204 ....: except:
205 ....: pass
206 ....:
198 207 """
199 208
200 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 214 def setup(self):
206 215 """Make a valid python temp file."""
207 f = tempfile.NamedTemporaryFile()
216 fname = tempfile.mkstemp()[1]
217 f = open(fname,'w')
208 218 f.write('pass\n')
209 219 f.flush()
210 220 self.tmpfile = f
221 self.fname = fname
211 222
212 223 def run_tmpfile(self):
213 224 # This fails on Windows if self.tmpfile.name has spaces or "~" in it.
214 225 # See below and ticket https://bugs.launchpad.net/bugs/366353
215 _ip.magic('run %s' % self.tmpfile.name)
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.")
226 _ip.magic('run "%s"' % self.fname)
221 227
222 # See https://bugs.launchpad.net/bugs/366353
223 @dec.skip_win32
224 228 def test_builtins_id(self):
225 229 """Check that %run doesn't damage __builtins__ """
226 230
@@ -230,8 +234,6 b' class TestMagicRun(object):'
230 234 bid2 = id(_ip.user_ns['__builtins__'])
231 235 tt.assert_equals(bid1, bid2)
232 236
233 # See https://bugs.launchpad.net/bugs/366353
234 @dec.skip_win32
235 237 def test_builtins_type(self):
236 238 """Check that the type of __builtins__ doesn't change with %run.
237 239
@@ -242,8 +244,6 b' class TestMagicRun(object):'
242 244 self.run_tmpfile()
243 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 247 def test_prompts(self):
248 248 """Test that prompts correctly generate after %run"""
249 249 self.run_tmpfile()
@@ -252,6 +252,12 b' class TestMagicRun(object):'
252 252
253 253 def teardown(self):
254 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 262 # Multiple tests for clipboard pasting
257 263 def test_paste():
General Comments 0
You need to be logged in to leave comments. Login now