<s> from . . import util <EOL> from . import util as import_util <EOL> import sys <EOL> import unittest <EOL> import importlib <EOL> from test import support <EOL> class ParentModuleTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_import_parent ( self ) : <EOL> with util . mock_modules ( '<STR_LIT>' , '<STR_LIT>' ) as mock : <EOL> with util . import_state ( meta_path = [ mock ] ) : <EOL> module = import_util . import_ ( '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , sys . modules ) <EOL> def test_bad_parent ( self ) : <EOL> with util . mock_modules ( '<STR_LIT>' ) as mock : <EOL> with util . import_state ( meta_path = [ mock ] ) : <EOL> with self . assertRaises ( ImportError ) as cm : <EOL> import_util . import_ ( '<STR_LIT>' ) <EOL> self . assertEqual ( cm . exception . name , '<STR_LIT>' ) <EOL> def test_raising_parent_after_importing_child ( self ) : <EOL> def __init__ ( ) : <EOL> import pkg . module <EOL> <NUM_LIT:1> / <NUM_LIT:0> <EOL> mock = util . mock_modules ( '<STR_LIT>' , '<STR_LIT>' , <EOL> module_code = { '<STR_LIT>' : __init__ } ) <EOL> with mock : <EOL> with util . import_state ( meta_path = [ mock ] ) : <EOL> with self . assertRaises ( ZeroDivisionError ) : <EOL> import_util . import_ ( '<STR_LIT>' ) <EOL> self . assertNotIn ( '<STR_LIT>' , sys . modules ) <EOL> self . assertIn ( '<STR_LIT>' , sys . modules ) <EOL> with self . assertRaises ( ZeroDivisionError ) : <EOL> import_util . import_ ( '<STR_LIT>' ) <EOL> self . assertNotIn ( '<STR_LIT>' , sys . modules ) <EOL> self . assertIn ( '<STR_LIT>' , sys . modules ) <EOL> def test_raising_parent_after_relative_importing_child ( self ) : <EOL> def __init__ ( ) : <EOL> from . import module <EOL> <NUM_LIT:1> / <NUM_LIT:0> <EOL> mock = util . mock_modules ( '<STR_LIT>' , '<STR_LIT>' , <EOL> module_code = { '<STR_LIT>' : __init__ } ) <EOL> with mock : <EOL> with util . import_state ( meta_path = [ mock ] ) : <EOL> with self . assertRaises ( ( ZeroDivisionError , ImportError ) ) : <EOL> import_util . import_ ( '<STR_LIT>' ) <EOL> self . assertNotIn ( '<STR_LIT>' , sys . modules ) <EOL> with self . assertRaises ( ( ZeroDivisionError , ImportError ) ) : <EOL> import_util . import_ ( '<STR_LIT>' ) <EOL> self . assertNotIn ( '<STR_LIT>' , sys . modules ) <EOL> def test_raising_parent_after_double_relative_importing_child ( self ) : <EOL> def __init__ ( ) : <EOL> from . . subpkg import module <EOL> <NUM_LIT:1> / <NUM_LIT:0> <EOL> mock = util . mock_modules ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> module_code = { '<STR_LIT>' : __init__ } ) <EOL> with mock : <EOL> with util . import_state ( meta_path = [ mock ] ) : <EOL> with self . assertRaises ( ( ZeroDivisionError , ImportError ) ) : <EOL> import_util . import_ ( '<STR_LIT>' ) <EOL> self . assertNotIn ( '<STR_LIT>' , sys . modules ) <EOL> with self . assertRaises ( ( ZeroDivisionError , ImportError ) ) : <EOL> import_util . import_ ( '<STR_LIT>' ) <EOL> self . assertNotIn ( '<STR_LIT>' , sys . modules ) <EOL> def test_module_not_package ( self ) : <EOL> assert not hasattr ( sys , '<STR_LIT>' ) <EOL> with self . assertRaises ( ImportError ) as cm : <EOL> import_util . import_ ( '<STR_LIT>' ) <EOL> self . assertEqual ( cm . exception . name , '<STR_LIT>' ) <EOL> def test_module_not_package_but_side_effects ( self ) : <EOL> name = '<STR_LIT>' <EOL> subname = name + '<STR_LIT>' <EOL> def module_injection ( ) : <EOL> sys . modules [ subname ] = '<STR_LIT>' <EOL> mock_modules = util . mock_modules ( '<STR_LIT>' , <EOL> module_code = { '<STR_LIT>' : module_injection } ) <EOL> with mock_modules as mock : <EOL> with util . import_state ( meta_path = [ mock ] ) : <EOL> try : <EOL> submodule = import_util . import_ ( subname ) <EOL> finally : <EOL> support . unload ( subname ) <EOL> def test_main ( ) : <EOL> from test . support import run_unittest <EOL> run_unittest ( ParentModuleTests ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test_main ( ) </s>
