| 
									
										
										
										
											2012-05-11 14:48:41 -04:00
										 |  |  | from importlib import machinery | 
					
						
							| 
									
										
										
										
											2009-02-07 02:06:43 +00:00
										 |  |  | from . import util as ext_util | 
					
						
							| 
									
										
										
										
											2009-02-01 00:49:41 +00:00
										 |  |  | from .. import abc | 
					
						
							| 
									
										
										
										
											2009-02-01 04:00:05 +00:00
										 |  |  | from .. import util | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import unittest | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-01 00:49:41 +00:00
										 |  |  | class LoaderTests(abc.LoaderTests): | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     """Test load_module() for extension modules.""" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-11 14:48:41 -04:00
										 |  |  |     def setUp(self): | 
					
						
							|  |  |  |         self.loader = machinery.ExtensionFileLoader(ext_util.NAME, | 
					
						
							|  |  |  |                                                      ext_util.FILEPATH) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  |     def load_module(self, fullname): | 
					
						
							| 
									
										
										
										
											2012-05-11 14:48:41 -04:00
										 |  |  |         return self.loader.load_module(fullname) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_load_module_API(self): | 
					
						
							|  |  |  |         # Test the default argument for load_module(). | 
					
						
							|  |  |  |         self.loader.load_module() | 
					
						
							|  |  |  |         self.loader.load_module(None) | 
					
						
							|  |  |  |         with self.assertRaises(ImportError): | 
					
						
							|  |  |  |             self.load_module('XXX') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-01 00:49:41 +00:00
										 |  |  |     def test_module(self): | 
					
						
							| 
									
										
										
										
											2009-02-07 02:06:43 +00:00
										 |  |  |         with util.uncache(ext_util.NAME): | 
					
						
							|  |  |  |             module = self.load_module(ext_util.NAME) | 
					
						
							|  |  |  |             for attr, value in [('__name__', ext_util.NAME), | 
					
						
							|  |  |  |                                 ('__file__', ext_util.FILEPATH), | 
					
						
							| 
									
										
										
										
											2009-02-07 01:52:25 +00:00
										 |  |  |                                 ('__package__', '')]: | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  |                 self.assertEqual(getattr(module, attr), value) | 
					
						
							| 
									
										
										
										
											2009-06-30 23:06:06 +00:00
										 |  |  |             self.assertTrue(ext_util.NAME in sys.modules) | 
					
						
							|  |  |  |             self.assertTrue(isinstance(module.__loader__, | 
					
						
							| 
									
										
										
										
											2012-05-11 14:48:41 -04:00
										 |  |  |                                     machinery.ExtensionFileLoader)) | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-01 00:49:41 +00:00
										 |  |  |     def test_package(self): | 
					
						
							|  |  |  |         # Extensions are not found in packages. | 
					
						
							|  |  |  |         pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_lacking_parent(self): | 
					
						
							|  |  |  |         # Extensions are not found in packages. | 
					
						
							|  |  |  |         pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_module_reuse(self): | 
					
						
							| 
									
										
										
										
											2009-02-07 02:06:43 +00:00
										 |  |  |         with util.uncache(ext_util.NAME): | 
					
						
							|  |  |  |             module1 = self.load_module(ext_util.NAME) | 
					
						
							|  |  |  |             module2 = self.load_module(ext_util.NAME) | 
					
						
							| 
									
										
										
										
											2009-06-30 23:06:06 +00:00
										 |  |  |             self.assertTrue(module1 is module2) | 
					
						
							| 
									
										
										
										
											2009-02-01 00:49:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_state_after_failure(self): | 
					
						
							|  |  |  |         # No easy way to trigger a failure after a successful import. | 
					
						
							|  |  |  |         pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_unloadable(self): | 
					
						
							| 
									
										
										
										
											2012-04-12 21:09:01 -04:00
										 |  |  |         name = 'asdfjkl;' | 
					
						
							|  |  |  |         with self.assertRaises(ImportError) as cm: | 
					
						
							|  |  |  |             self.load_module(name) | 
					
						
							|  |  |  |         self.assertEqual(cm.exception.name, name) | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_main(): | 
					
						
							|  |  |  |     from test.support import run_unittest | 
					
						
							|  |  |  |     run_unittest(LoaderTests) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  |     test_main() |