<s> import importlib <EOL> from importlib import machinery <EOL> from . . import abc <EOL> from . . import util <EOL> from . import util as builtin_util <EOL> import sys <EOL> import types <EOL> import unittest <EOL> class LoaderTests ( abc . LoaderTests ) : <EOL> """<STR_LIT>""" <EOL> verification = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : machinery . BuiltinImporter } <EOL> def verify ( self , module ) : <EOL> """<STR_LIT>""" <EOL> self . assertIsInstance ( module , types . ModuleType ) <EOL> for attr , value in self . verification . items ( ) : <EOL> self . assertEqual ( getattr ( module , attr ) , value ) <EOL> self . assertIn ( module . __name__ , sys . modules ) <EOL> load_module = staticmethod ( lambda name : <EOL> machinery . BuiltinImporter . load_module ( name ) ) <EOL> def test_module ( self ) : <EOL> with util . uncache ( builtin_util . NAME ) : <EOL> module = self . load_module ( builtin_util . NAME ) <EOL> self . verify ( module ) <EOL> def test_package ( self ) : <EOL> pass <EOL> def test_lacking_parent ( self ) : <EOL> pass <EOL> def test_state_after_failure ( self ) : <EOL> pass <EOL> def test_module_reuse ( self ) : <EOL> with util . uncache ( builtin_util . NAME ) : <EOL> module1 = self . load_module ( builtin_util . NAME ) <EOL> module2 = self . load_module ( builtin_util . NAME ) <EOL> self . assertIs ( module1 , module2 ) <EOL> def test_unloadable ( self ) : <EOL> name = '<STR_LIT>' <EOL> assert name not in sys . builtin_module_names <EOL> with self . assertRaises ( ImportError ) as cm : <EOL> self . load_module ( name ) <EOL> self . assertEqual ( cm . exception . name , name ) <EOL> def test_already_imported ( self ) : <EOL> assert hasattr ( importlib , '<STR_LIT>' ) <EOL> with self . assertRaises ( ImportError ) as cm : <EOL> self . load_module ( '<STR_LIT>' ) <EOL> self . assertEqual ( cm . exception . name , '<STR_LIT>' ) <EOL> class InspectLoaderTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_get_code ( self ) : <EOL> result = machinery . BuiltinImporter . get_code ( builtin_util . NAME ) <EOL> self . assertIsNone ( result ) <EOL> def test_get_source ( self ) : <EOL> result = machinery . BuiltinImporter . get_source ( builtin_util . NAME ) <EOL> self . assertIsNone ( result ) <EOL> def test_is_package ( self ) : <EOL> result = machinery . BuiltinImporter . is_package ( builtin_util . NAME ) <EOL> self . assertTrue ( not result ) <EOL> def test_not_builtin ( self ) : <EOL> for meth_name in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> method = getattr ( machinery . BuiltinImporter , meth_name ) <EOL> with self . assertRaises ( ImportError ) as cm : <EOL> method ( builtin_util . BAD_NAME ) <EOL> self . assertRaises ( builtin_util . BAD_NAME ) <EOL> def test_main ( ) : <EOL> from test . support import run_unittest <EOL> run_unittest ( LoaderTests , InspectLoaderTests ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test_main ( ) </s>
