blob: 7f17c4bd356b5cbe49768c98b9ea1c72958faf85 [file] [log] [blame]
Brett Cannonbcb26c52009-02-01 04:00:05 +00001from .. import util
Brett Cannon23cbd8a2009-01-18 00:24:28 +00002import sys
3import unittest
4import importlib
Brett Cannon23cbd8a2009-01-18 00:24:28 +00005
6
7class ParentModuleTests(unittest.TestCase):
8
9 """Importing a submodule should import the parent modules."""
10
11 def test_import_parent(self):
Brett Cannonbcb26c52009-02-01 04:00:05 +000012 with util.mock_modules('pkg.__init__', 'pkg.module') as mock:
13 with util.import_state(meta_path=[mock]):
14 module = util.import_('pkg.module')
Brett Cannon23cbd8a2009-01-18 00:24:28 +000015 self.assert_('pkg' in sys.modules)
16
17 def test_bad_parent(self):
Brett Cannonbcb26c52009-02-01 04:00:05 +000018 with util.mock_modules('pkg.module') as mock:
19 with util.import_state(meta_path=[mock]):
20 self.assertRaises(ImportError, util.import_, 'pkg.module')
Brett Cannon23cbd8a2009-01-18 00:24:28 +000021
22
23def test_main():
24 from test.support import run_unittest
25 run_unittest(ParentModuleTests)
26
27
28if __name__ == '__main__':
29 test_main()