@@ -23,6 +23,62 @@ def test_bad_parent(self):
2323 import_util .import_ ('pkg.module' )
2424 self .assertEqual (cm .exception .name , 'pkg' )
2525
26+ def test_raising_parent_after_importing_child (self ):
27+ def __init__ ():
28+ import pkg .module
29+ 1 / 0
30+ mock = util .mock_modules ('pkg.__init__' , 'pkg.module' ,
31+ module_code = {'pkg' : __init__ })
32+ with mock :
33+ with util .import_state (meta_path = [mock ]):
34+ with self .assertRaises (ZeroDivisionError ):
35+ import_util .import_ ('pkg' )
36+ self .assertFalse ('pkg' in sys .modules )
37+ self .assertTrue ('pkg.module' in sys .modules )
38+ with self .assertRaises (ZeroDivisionError ):
39+ import_util .import_ ('pkg.module' )
40+ self .assertFalse ('pkg' in sys .modules )
41+ self .assertTrue ('pkg.module' in sys .modules )
42+
43+ def test_raising_parent_after_relative_importing_child (self ):
44+ def __init__ ():
45+ from . import module
46+ 1 / 0
47+ mock = util .mock_modules ('pkg.__init__' , 'pkg.module' ,
48+ module_code = {'pkg' : __init__ })
49+ with mock :
50+ with util .import_state (meta_path = [mock ]):
51+ with self .assertRaises ((ZeroDivisionError , ImportError )):
52+ # This raises ImportError on the "from . import module"
53+ # line, not sure why.
54+ import_util .import_ ('pkg' )
55+ self .assertFalse ('pkg' in sys .modules )
56+ with self .assertRaises ((ZeroDivisionError , ImportError )):
57+ import_util .import_ ('pkg.module' )
58+ self .assertFalse ('pkg' in sys .modules )
59+ # XXX False
60+ #self.assertTrue('pkg.module' in sys.modules)
61+
62+ def test_raising_parent_after_double_relative_importing_child (self ):
63+ def __init__ ():
64+ from ..subpkg import module
65+ 1 / 0
66+ mock = util .mock_modules ('pkg.__init__' , 'pkg.subpkg.__init__' ,
67+ 'pkg.subpkg.module' ,
68+ module_code = {'pkg.subpkg' : __init__ })
69+ with mock :
70+ with util .import_state (meta_path = [mock ]):
71+ with self .assertRaises ((ZeroDivisionError , ImportError )):
72+ # This raises ImportError on the "from ..subpkg import module"
73+ # line, not sure why.
74+ import_util .import_ ('pkg.subpkg' )
75+ self .assertFalse ('pkg.subpkg' in sys .modules )
76+ with self .assertRaises ((ZeroDivisionError , ImportError )):
77+ import_util .import_ ('pkg.subpkg.module' )
78+ self .assertFalse ('pkg.subpkg' in sys .modules )
79+ # XXX False
80+ #self.assertTrue('pkg.subpkg.module' in sys.modules)
81+
2682 def test_module_not_package (self ):
2783 # Try to import a submodule from a non-package should raise ImportError.
2884 assert not hasattr (sys , '__path__' )
0 commit comments