Brett Cannon | bcb26c5 | 2009-02-01 04:00:05 +0000 | [diff] [blame^] | 1 | from .. import util |
Brett Cannon | 23cbd8a | 2009-01-18 00:24:28 +0000 | [diff] [blame] | 2 | import sys |
| 3 | import unittest |
| 4 | import importlib |
Brett Cannon | 23cbd8a | 2009-01-18 00:24:28 +0000 | [diff] [blame] | 5 | |
| 6 | |
| 7 | class ParentModuleTests(unittest.TestCase): |
| 8 | |
| 9 | """Importing a submodule should import the parent modules.""" |
| 10 | |
| 11 | def test_import_parent(self): |
Brett Cannon | bcb26c5 | 2009-02-01 04:00:05 +0000 | [diff] [blame^] | 12 | 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 Cannon | 23cbd8a | 2009-01-18 00:24:28 +0000 | [diff] [blame] | 15 | self.assert_('pkg' in sys.modules) |
| 16 | |
| 17 | def test_bad_parent(self): |
Brett Cannon | bcb26c5 | 2009-02-01 04:00:05 +0000 | [diff] [blame^] | 18 | 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 Cannon | 23cbd8a | 2009-01-18 00:24:28 +0000 | [diff] [blame] | 21 | |
| 22 | |
| 23 | def test_main(): |
| 24 | from test.support import run_unittest |
| 25 | run_unittest(ParentModuleTests) |
| 26 | |
| 27 | |
| 28 | if __name__ == '__main__': |
| 29 | test_main() |