##// END OF EJS Templates
Add a couple more tests for %run options
Thomas Kluyver -
Show More
@@ -15,6 +15,7 b' from __future__ import absolute_import'
15
15
16 import functools
16 import functools
17 import os
17 import os
18 from os.path import join as pjoin
18 import random
19 import random
19 import sys
20 import sys
20 import tempfile
21 import tempfile
@@ -359,6 +360,17 b' tclass.py: deleting object: C-third'
359 self.mktmp(src)
360 self.mktmp(src)
360 _ip.magic('run -t -N 1 %s' % self.fname)
361 _ip.magic('run -t -N 1 %s' % self.fname)
361 _ip.magic('run -t -N 10 %s' % self.fname)
362 _ip.magic('run -t -N 10 %s' % self.fname)
363
364 def test_ignore_sys_exit(self):
365 """Test the -e option to ignore sys.exit()"""
366 src = "import sys; sys.exit(1)"
367 self.mktmp(src)
368 with tt.AssertPrints('SystemExit'):
369 _ip.magic('run %s' % self.fname)
370
371 with tt.AssertNotPrints('SystemExit'):
372 _ip.magic('run -e %s' % self.fname)
373
362
374
363
375
364 class TestMagicRunWithPackage(unittest.TestCase):
376 class TestMagicRunWithPackage(unittest.TestCase):
@@ -431,3 +443,16 b' class TestMagicRunWithPackage(unittest.TestCase):'
431 @with_fake_debugger
443 @with_fake_debugger
432 def test_debug_run_submodule_with_relative_import(self):
444 def test_debug_run_submodule_with_relative_import(self):
433 self.check_run_submodule('relative', '-d')
445 self.check_run_submodule('relative', '-d')
446
447 def test_run__name__():
448 with TemporaryDirectory() as td:
449 path = pjoin(td, 'foo.py')
450 with open(path, 'w') as f:
451 f.write("q = __name__")
452
453 _ip.user_ns.pop('q', None)
454 _ip.magic('run {}'.format(path))
455 nt.assert_equal(_ip.user_ns.pop('q'), '__main__')
456
457 _ip.magic('run -n {}'.format(path))
458 nt.assert_equal(_ip.user_ns.pop('q'), 'foo')
General Comments 0
You need to be logged in to leave comments. Login now