| 
									
										
										
										
											2022-01-22 19:05:05 +03:00
										 |  |  | from test.test_importlib import abc, util | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-09 14:32:57 -04:00
										 |  |  | machinery = util.import_importlib('importlib.machinery') | 
					
						
							| 
									
										
										
										
											2013-10-25 15:39:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  | import unittest | 
					
						
							| 
									
										
										
										
											2022-06-24 20:28:04 +02:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-25 15:39:02 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | class FinderTests(abc.FinderTests): | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     """Test the finder for extension modules.""" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-22 12:04:36 +02:00
										 |  |  |     def setUp(self): | 
					
						
							|  |  |  |         if not self.machinery.EXTENSION_SUFFIXES: | 
					
						
							|  |  |  |             raise unittest.SkipTest("Requires dynamic loading support.") | 
					
						
							| 
									
										
										
										
											2022-06-24 20:28:04 +02:00
										 |  |  |         if util.EXTENSIONS.name in sys.builtin_module_names: | 
					
						
							|  |  |  |             raise unittest.SkipTest( | 
					
						
							|  |  |  |                 f"{util.EXTENSIONS.name} is a builtin module" | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2022-03-22 12:04:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-06 08:56:57 -07:00
										 |  |  |     def find_spec(self, fullname): | 
					
						
							| 
									
										
										
										
											2014-05-09 14:32:57 -04:00
										 |  |  |         importer = self.machinery.FileFinder(util.EXTENSIONS.path, | 
					
						
							| 
									
										
										
										
											2013-10-25 15:39:02 -04:00
										 |  |  |                                             (self.machinery.ExtensionFileLoader, | 
					
						
							|  |  |  |                                              self.machinery.EXTENSION_SUFFIXES)) | 
					
						
							| 
									
										
										
										
											2021-04-06 08:56:57 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return importer.find_spec(fullname) | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 01:33:54 +00:00
										 |  |  |     def test_module(self): | 
					
						
							| 
									
										
										
										
											2021-04-06 08:56:57 -07:00
										 |  |  |         self.assertTrue(self.find_spec(util.EXTENSIONS.name)) | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-22 09:05:39 -07:00
										 |  |  |     # No extension module as an __init__ available for testing. | 
					
						
							|  |  |  |     test_package = test_package_in_package = None | 
					
						
							| 
									
										
										
										
											2009-01-27 01:33:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-22 09:05:39 -07:00
										 |  |  |     # No extension module in a package available for testing. | 
					
						
							|  |  |  |     test_module_in_package = None | 
					
						
							| 
									
										
										
										
											2009-01-27 01:33:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-22 09:05:39 -07:00
										 |  |  |     # Extension modules cannot be an __init__ for a package. | 
					
						
							|  |  |  |     test_package_over_module = None | 
					
						
							| 
									
										
										
										
											2009-01-27 01:33:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  |     def test_failure(self): | 
					
						
							| 
									
										
										
										
											2021-04-06 08:56:57 -07:00
										 |  |  |         self.assertIsNone(self.find_spec('asdfjkl;')) | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-16 11:40:40 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | (Frozen_FinderTests, | 
					
						
							|  |  |  |  Source_FinderTests | 
					
						
							|  |  |  |  ) = util.test_both(FinderTests, machinery=machinery) | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							| 
									
										
										
										
											2013-10-25 15:39:02 -04:00
										 |  |  |     unittest.main() |