| 
									
										
										
										
											2009-01-22 22:43:07 +00:00
										 |  |  | from importlib import machinery | 
					
						
							| 
									
										
										
										
											2009-02-01 01:34:13 +00:00
										 |  |  | from .. import abc | 
					
						
							| 
									
										
										
										
											2009-02-01 04:00:05 +00:00
										 |  |  | from .. import util | 
					
						
							| 
									
										
										
										
											2009-02-01 01:34:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class LoaderTests(abc.LoaderTests): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_module(self): | 
					
						
							| 
									
										
										
										
											2009-02-01 04:00:05 +00:00
										 |  |  |         with util.uncache('__hello__'): | 
					
						
							| 
									
										
										
										
											2009-02-01 01:34:13 +00:00
										 |  |  |             module = machinery.FrozenImporter.load_module('__hello__') | 
					
						
							|  |  |  |             check = {'__name__': '__hello__', '__file__': '<frozen>', | 
					
						
							| 
									
										
										
										
											2009-02-07 01:38:38 +00:00
										 |  |  |                         '__package__': ''} | 
					
						
							| 
									
										
										
										
											2009-02-01 01:34:13 +00:00
										 |  |  |             for attr, value in check.items(): | 
					
						
							|  |  |  |                 self.assertEqual(getattr(module, attr), value) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_package(self): | 
					
						
							| 
									
										
										
										
											2009-02-01 04:00:05 +00:00
										 |  |  |         with util.uncache('__phello__'): | 
					
						
							| 
									
										
										
										
											2009-02-01 01:34:13 +00:00
										 |  |  |             module = machinery.FrozenImporter.load_module('__phello__') | 
					
						
							|  |  |  |             check = {'__name__': '__phello__', '__file__': '<frozen>', | 
					
						
							|  |  |  |                      '__package__': '__phello__', '__path__': ['__phello__']} | 
					
						
							|  |  |  |             for attr, value in check.items(): | 
					
						
							|  |  |  |                 attr_value = getattr(module, attr) | 
					
						
							|  |  |  |                 self.assertEqual(attr_value, value, | 
					
						
							|  |  |  |                                  "for __phello__.%s, %r != %r" % | 
					
						
							|  |  |  |                                  (attr, attr_value, value)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_lacking_parent(self): | 
					
						
							| 
									
										
										
										
											2009-02-01 04:00:05 +00:00
										 |  |  |         with util.uncache('__phello__', '__phello__.spam'): | 
					
						
							| 
									
										
										
										
											2009-02-01 01:34:13 +00:00
										 |  |  |             module = machinery.FrozenImporter.load_module('__phello__.spam') | 
					
						
							|  |  |  |             check = {'__name__': '__phello__.spam', '__file__': '<frozen>', | 
					
						
							|  |  |  |                      '__package__': '__phello__'} | 
					
						
							|  |  |  |             for attr, value in check.items(): | 
					
						
							|  |  |  |                 attr_value = getattr(module, attr) | 
					
						
							|  |  |  |                 self.assertEqual(attr_value, value, | 
					
						
							|  |  |  |                                  "for __phello__.spam.%s, %r != %r" % | 
					
						
							|  |  |  |                                  (attr, attr_value, value)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_module_reuse(self): | 
					
						
							| 
									
										
										
										
											2009-02-01 04:00:05 +00:00
										 |  |  |         with util.uncache('__hello__'): | 
					
						
							| 
									
										
										
										
											2009-02-01 01:34:13 +00:00
										 |  |  |             module1 = machinery.FrozenImporter.load_module('__hello__') | 
					
						
							|  |  |  |             module2 = machinery.FrozenImporter.load_module('__hello__') | 
					
						
							|  |  |  |             self.assert_(module1 is module2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_state_after_failure(self): | 
					
						
							|  |  |  |         # No way to trigger an error in a frozen module. | 
					
						
							|  |  |  |         pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_unloadable(self): | 
					
						
							|  |  |  |         assert machinery.FrozenImporter.find_module('_not_real') is None | 
					
						
							|  |  |  |         self.assertRaises(ImportError, machinery.FrozenImporter.load_module, | 
					
						
							|  |  |  |                             '_not_real') | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_main(): | 
					
						
							|  |  |  |     from test.support import run_unittest | 
					
						
							| 
									
										
										
										
											2009-02-01 01:34:13 +00:00
										 |  |  |     run_unittest(LoaderTests) | 
					
						
							| 
									
										
										
										
											2009-01-18 00:24:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  |     test_main() |