Show More
@@ -248,3 +248,35 b' tclass.py: deleting object: C-third' | |||||
248 | na = os.path.join(mydir, 'nonascii.py') |
|
248 | na = os.path.join(mydir, 'nonascii.py') | |
249 | _ip.magic('run "%s"' % na) |
|
249 | _ip.magic('run "%s"' % na) | |
250 | nt.assert_equal(_ip.user_ns['u'], u'Ўт№Ф') |
|
250 | nt.assert_equal(_ip.user_ns['u'], u'Ўт№Ф') | |
|
251 | ||||
|
252 | def test_run_py_file_attribute(self): | |||
|
253 | """Test handling of `__file__` attribute in `%run <file>.py`.""" | |||
|
254 | src = "t = __file__\n" | |||
|
255 | self.mktmp(src) | |||
|
256 | _missing = object() | |||
|
257 | file1 = _ip.user_ns.get('__file__', _missing) | |||
|
258 | _ip.magic('run %s' % self.fname) | |||
|
259 | file2 = _ip.user_ns.get('__file__', _missing) | |||
|
260 | ||||
|
261 | # Check that __file__ was equal to the filename in the script's | |||
|
262 | # namespace. | |||
|
263 | nt.assert_equal(_ip.user_ns['t'], self.fname) | |||
|
264 | ||||
|
265 | # Check that __file__ was not leaked back into user_ns. | |||
|
266 | nt.assert_equal(file1, file2) | |||
|
267 | ||||
|
268 | def test_run_ipy_file_attribute(self): | |||
|
269 | """Test handling of `__file__` attribute in `%run <file.ipy>`.""" | |||
|
270 | src = "t = __file__\n" | |||
|
271 | self.mktmp(src, ext='.ipy') | |||
|
272 | _missing = object() | |||
|
273 | file1 = _ip.user_ns.get('__file__', _missing) | |||
|
274 | _ip.magic('run %s' % self.fname) | |||
|
275 | file2 = _ip.user_ns.get('__file__', _missing) | |||
|
276 | ||||
|
277 | # Check that __file__ was equal to the filename in the script's | |||
|
278 | # namespace. | |||
|
279 | nt.assert_equal(_ip.user_ns['t'], self.fname) | |||
|
280 | ||||
|
281 | # Check that __file__ was not leaked back into user_ns. | |||
|
282 | nt.assert_equal(file1, file2) |
General Comments 0
You need to be logged in to leave comments.
Login now