1from .. import abc 2from .. import util 3 4machinery = util.import_importlib('importlib.machinery') 5 6import unittest 7 8 9class FindSpecTests(abc.FinderTests): 10 11 """Test finding frozen modules.""" 12 13 def find(self, name, path=None): 14 finder = self.machinery.FrozenImporter 15 return finder.find_spec(name, path) 16 17 def test_module(self): 18 name = '__hello__' 19 spec = self.find(name) 20 self.assertEqual(spec.origin, 'frozen') 21 22 def test_package(self): 23 spec = self.find('__phello__') 24 self.assertIsNotNone(spec) 25 26 def test_module_in_package(self): 27 spec = self.find('__phello__.spam', ['__phello__']) 28 self.assertIsNotNone(spec) 29 30 # No frozen package within another package to test with. 31 test_package_in_package = None 32 33 # No easy way to test. 34 test_package_over_module = None 35 36 def test_failure(self): 37 spec = self.find('<not real>') 38 self.assertIsNone(spec) 39 40 41(Frozen_FindSpecTests, 42 Source_FindSpecTests 43 ) = util.test_both(FindSpecTests, machinery=machinery) 44 45 46class FinderTests(abc.FinderTests): 47 48 """Test finding frozen modules.""" 49 50 def find(self, name, path=None): 51 finder = self.machinery.FrozenImporter 52 return finder.find_module(name, path) 53 54 def test_module(self): 55 name = '__hello__' 56 loader = self.find(name) 57 self.assertTrue(hasattr(loader, 'load_module')) 58 59 def test_package(self): 60 loader = self.find('__phello__') 61 self.assertTrue(hasattr(loader, 'load_module')) 62 63 def test_module_in_package(self): 64 loader = self.find('__phello__.spam', ['__phello__']) 65 self.assertTrue(hasattr(loader, 'load_module')) 66 67 # No frozen package within another package to test with. 68 test_package_in_package = None 69 70 # No easy way to test. 71 test_package_over_module = None 72 73 def test_failure(self): 74 loader = self.find('<not real>') 75 self.assertIsNone(loader) 76 77 78(Frozen_FinderTests, 79 Source_FinderTests 80 ) = util.test_both(FinderTests, machinery=machinery) 81 82 83if __name__ == '__main__': 84 unittest.main() 85