2009-02-01 00:00:05 -04:00
|
|
|
from .. import util
|
2009-01-17 20:24:28 -04:00
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
import importlib
|
|
|
|
|
|
|
|
|
|
|
|
class ParentModuleTests(unittest.TestCase):
|
|
|
|
|
|
|
|
"""Importing a submodule should import the parent modules."""
|
|
|
|
|
|
|
|
def test_import_parent(self):
|
2009-02-01 00:00:05 -04:00
|
|
|
with util.mock_modules('pkg.__init__', 'pkg.module') as mock:
|
|
|
|
with util.import_state(meta_path=[mock]):
|
|
|
|
module = util.import_('pkg.module')
|
2009-01-17 20:24:28 -04:00
|
|
|
self.assert_('pkg' in sys.modules)
|
|
|
|
|
|
|
|
def test_bad_parent(self):
|
2009-02-01 00:00:05 -04:00
|
|
|
with util.mock_modules('pkg.module') as mock:
|
|
|
|
with util.import_state(meta_path=[mock]):
|
|
|
|
self.assertRaises(ImportError, util.import_, 'pkg.module')
|
2009-01-17 20:24:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_main():
|
|
|
|
from test.support import run_unittest
|
|
|
|
run_unittest(ParentModuleTests)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_main()
|