<s> from importlib import _bootstrap <EOL> from importlib import machinery <EOL> from importlib import import_module <EOL> from . . import util <EOL> from . import util as import_util <EOL> import os <EOL> import sys <EOL> from types import ModuleType <EOL> import unittest <EOL> import warnings <EOL> import zipimport <EOL> class FinderTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_failure ( self ) : <EOL> module = '<STR_LIT>' <EOL> with util . import_state ( ) : <EOL> self . assertIsNone ( machinery . PathFinder . find_module ( module ) ) <EOL> def test_sys_path ( self ) : <EOL> module = '<STR_LIT>' <EOL> path = '<STR_LIT>' <EOL> importer = util . mock_modules ( module ) <EOL> with util . import_state ( path_importer_cache = { path : importer } , <EOL> path = [ path ] ) : <EOL> loader = machinery . PathFinder . find_module ( module ) <EOL> self . assertIs ( loader , importer ) <EOL> def test_path ( self ) : <EOL> module = '<STR_LIT>' <EOL> path = '<STR_LIT>' <EOL> importer = util . mock_modules ( module ) <EOL> with util . import_state ( path_importer_cache = { path : importer } ) : <EOL> loader = machinery . PathFinder . find_module ( module , [ path ] ) <EOL> self . assertIs ( loader , importer ) <EOL> def test_empty_list ( self ) : <EOL> module = '<STR_LIT>' <EOL> path = '<STR_LIT>' <EOL> importer = util . mock_modules ( module ) <EOL> with util . import_state ( path_importer_cache = { path : importer } , <EOL> path = [ path ] ) : <EOL> self . assertIsNone ( machinery . PathFinder . find_module ( '<STR_LIT>' , [ ] ) ) <EOL> def test_path_hooks ( self ) : <EOL> module = '<STR_LIT>' <EOL> path = '<STR_LIT>' <EOL> importer = util . mock_modules ( module ) <EOL> hook = import_util . mock_path_hook ( path , importer = importer ) <EOL> with util . import_state ( path_hooks = [ hook ] ) : <EOL> loader = machinery . PathFinder . find_module ( module , [ path ] ) <EOL> self . assertIs ( loader , importer ) <EOL> self . assertIn ( path , sys . path_importer_cache ) <EOL> self . assertIs ( sys . path_importer_cache [ path ] , importer ) <EOL> def test_empty_path_hooks ( self ) : <EOL> path_entry = '<STR_LIT>' <EOL> with util . import_state ( path_importer_cache = { } , path_hooks = [ ] , <EOL> path = [ path_entry ] ) : <EOL> with warnings . catch_warnings ( record = True ) as w : <EOL> warnings . simplefilter ( '<STR_LIT>' ) <EOL> self . assertIsNone ( machinery . PathFinder . find_module ( '<STR_LIT>' ) ) <EOL> self . assertIsNone ( sys . path_importer_cache [ path_entry ] ) <EOL> self . assertEqual ( len ( w ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( issubclass ( w [ - <NUM_LIT:1> ] . category , ImportWarning ) ) <EOL> def test_path_importer_cache_empty_string ( self ) : <EOL> path = '<STR_LIT>' <EOL> module = '<STR_LIT>' <EOL> importer = util . mock_modules ( module ) <EOL> hook = import_util . mock_path_hook ( os . curdir , importer = importer ) <EOL> with util . import_state ( path = [ path ] , path_hooks = [ hook ] ) : <EOL> loader = machinery . PathFinder . find_module ( module ) <EOL> self . assertIs ( loader , importer ) <EOL> self . assertIn ( os . curdir , sys . path_importer_cache ) <EOL> def test_None_on_sys_path ( self ) : <EOL> new_path = sys . path [ : ] <EOL> new_path . insert ( <NUM_LIT:0> , None ) <EOL> new_path_importer_cache = sys . path_importer_cache . copy ( ) <EOL> new_path_importer_cache . pop ( None , None ) <EOL> new_path_hooks = [ zipimport . zipimporter , <EOL> _bootstrap . FileFinder . path_hook ( <EOL> * _bootstrap . _get_supported_file_loaders ( ) ) ] <EOL> missing = object ( ) <EOL> email = sys . modules . pop ( '<STR_LIT:email>' , missing ) <EOL> try : <EOL> with util . import_state ( meta_path = sys . meta_path [ : ] , <EOL> path = new_path , <EOL> path_importer_cache = new_path_importer_cache , <EOL> path_hooks = new_path_hooks ) : <EOL> module = import_module ( '<STR_LIT:email>' ) <EOL> self . assertIsInstance ( module , ModuleType ) <EOL> finally : <EOL> if email is not missing : <EOL> sys . modules [ '<STR_LIT:email>' ] = email <EOL> def test_main ( ) : <EOL> from test . support import run_unittest <EOL> run_unittest ( FinderTests ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test_main ( ) </s>
