cpython/Lib/importlib/test/import_/test_packages.py
Brett Cannon 2153dc001f Move over to using assertRaises as a context manager for importlib tests.
Obviously one shouldn't do whole sale conversions like this, but I was already
going through the test code and I was bored at the airport.
2009-08-27 23:49:21 +00:00

31 lines
872 B
Python

from .. import util
from . import util as import_util
import sys
import unittest
import importlib
class ParentModuleTests(unittest.TestCase):
"""Importing a submodule should import the parent modules."""
def test_import_parent(self):
with util.mock_modules('pkg.__init__', 'pkg.module') as mock:
with util.import_state(meta_path=[mock]):
module = import_util.import_('pkg.module')
self.assertTrue('pkg' in sys.modules)
def test_bad_parent(self):
with util.mock_modules('pkg.module') as mock:
with util.import_state(meta_path=[mock]):
with self.assertRaises(ImportError):
import_util.import_('pkg.module')
def test_main():
from test.support import run_unittest
run_unittest(ParentModuleTests)
if __name__ == '__main__':
test_main()