1from .. import util 2 3machinery = util.import_importlib('importlib.machinery') 4 5import unittest 6 7 8class PathHookTest: 9 10 """Test the path hook for source.""" 11 12 def path_hook(self): 13 return self.machinery.FileFinder.path_hook((self.machinery.SourceFileLoader, 14 self.machinery.SOURCE_SUFFIXES)) 15 16 def test_success(self): 17 with util.create_modules('dummy') as mapping: 18 self.assertTrue(hasattr(self.path_hook()(mapping['.root']), 19 'find_spec')) 20 21 def test_success_legacy(self): 22 with util.create_modules('dummy') as mapping: 23 self.assertTrue(hasattr(self.path_hook()(mapping['.root']), 24 'find_module')) 25 26 def test_empty_string(self): 27 # The empty string represents the cwd. 28 self.assertTrue(hasattr(self.path_hook()(''), 'find_spec')) 29 30 def test_empty_string_legacy(self): 31 # The empty string represents the cwd. 32 self.assertTrue(hasattr(self.path_hook()(''), 'find_module')) 33 34 35(Frozen_PathHookTest, 36 Source_PathHooktest 37 ) = util.test_both(PathHookTest, machinery=machinery) 38 39 40if __name__ == '__main__': 41 unittest.main() 42