##// END OF EJS Templates
Merge pull request #4338 from minrk/sync_imports...
Thomas Kluyver -
r12881:08529615 merge
parent child Browse files
Show More
@@ -457,7 +457,7 b' class DirectView(View):'
457 else:
457 else:
458 user_ns[name] = sys.modules[name]
458 user_ns[name] = sys.modules[name]
459
459
460 def view_import(name, globals={}, locals={}, fromlist=[], level=-1):
460 def view_import(name, globals={}, locals={}, fromlist=[], level=0):
461 """the drop-in replacement for __import__, that optionally imports
461 """the drop-in replacement for __import__, that optionally imports
462 locally as well.
462 locally as well.
463 """
463 """
@@ -478,7 +478,7 b' class DirectView(View):'
478 imp.release_lock()
478 imp.release_lock()
479
479
480 key = name+':'+','.join(fromlist or [])
480 key = name+':'+','.join(fromlist or [])
481 if level == -1 and key not in modules:
481 if level <= 0 and key not in modules:
482 modules.add(key)
482 modules.add(key)
483 if not quiet:
483 if not quiet:
484 if fromlist:
484 if fromlist:
@@ -805,4 +805,30 b' class TestView(ClusterTestCase):'
805 view = self.client[-1]
805 view = self.client[-1]
806 tup = view.apply_sync(echoxy, point(1, 2))
806 tup = view.apply_sync(echoxy, point(1, 2))
807 self.assertEqual(tup, (2,1))
807 self.assertEqual(tup, (2,1))
808
809 def test_sync_imports(self):
810 view = self.client[-1]
811 with capture_output() as io:
812 with view.sync_imports():
813 import IPython
814 self.assertIn("IPython", io.stdout)
815
816 @interactive
817 def find_ipython():
818 return 'IPython' in globals()
819
820 assert view.apply_sync(find_ipython)
821
822 def test_sync_imports_quiet(self):
823 view = self.client[-1]
824 with capture_output() as io:
825 with view.sync_imports(quiet=True):
826 import IPython
827 self.assertEqual(io.stdout, '')
828
829 @interactive
830 def find_ipython():
831 return 'IPython' in globals()
832
833 assert view.apply_sync(find_ipython)
808
834
General Comments 0
You need to be logged in to leave comments. Login now