mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Issue #14605: Use None in sys.path_importer_cache to represent no
finder instead of using some (now non-existent) implicit finder.
This commit is contained in:
		
							parent
							
								
									9e66ac683c
								
							
						
					
					
						commit
						aa93642a35
					
				
					 7 changed files with 1096 additions and 1172 deletions
				
			
		|  | @ -66,36 +66,18 @@ def test_path_hooks(self): | |||
|             self.assertTrue(sys.path_importer_cache[path] is importer) | ||||
| 
 | ||||
|     def test_empty_path_hooks(self): | ||||
|         # Test that if sys.path_hooks is empty a warning is raised and | ||||
|         # PathFinder returns None. | ||||
|         # tried again (with a warning). | ||||
|         # Test that if sys.path_hooks is empty a warning is raised, | ||||
|         # sys.path_importer_cache gets None set, and PathFinder returns None. | ||||
|         path_entry = 'bogus_path' | ||||
|         with util.import_state(path_importer_cache={}, path_hooks=[], | ||||
|                                path=['bogus_path']): | ||||
|                                path=[path_entry]): | ||||
|             with warnings.catch_warnings(record=True) as w: | ||||
|                 warnings.simplefilter('always') | ||||
|                 self.assertIsNone(machinery.PathFinder.find_module('os')) | ||||
|                 self.assertNotIn('os', sys.path_importer_cache) | ||||
|                 self.assertIsNone(sys.path_importer_cache[path_entry]) | ||||
|                 self.assertEqual(len(w), 1) | ||||
|                 self.assertTrue(issubclass(w[-1].category, ImportWarning)) | ||||
| 
 | ||||
|     def test_path_importer_cache_has_None_continues(self): | ||||
|         # Test that having None in sys.path_importer_cache causes the search to | ||||
|         # continue. | ||||
|         path = '<test path>' | ||||
|         module = '<test module>' | ||||
|         importer = util.mock_modules(module) | ||||
|         with util.import_state(path=['1', '2'], | ||||
|                             path_importer_cache={'1': None, '2': importer}, | ||||
|                             path_hooks=[imp.NullImporter]): | ||||
|             with warnings.catch_warnings(record=True) as w: | ||||
|                 warnings.simplefilter('always') | ||||
|                 loader = machinery.PathFinder.find_module(module) | ||||
|                 self.assertTrue(loader is importer) | ||||
|                 self.assertEqual(len(w), 1) | ||||
|                 warned = w[0] | ||||
|                 self.assertTrue(issubclass(warned.category, ImportWarning)) | ||||
|                 self.assertIn(repr(None), str(warned.message)) | ||||
| 
 | ||||
|     def test_path_importer_cache_empty_string(self): | ||||
|         # The empty string should create a finder using the cwd. | ||||
|         path = '' | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Brett Cannon
						Brett Cannon