11from .. import abc
2- import os .path
32from .. import util
43
54machinery = util .import_importlib ('importlib.machinery' )
65
6+ import _imp
7+ import marshal
8+ import os .path
79import unittest
810import warnings
911
10- from test .support import import_helper
12+ from test .support import import_helper , REPO_ROOT
13+
14+
15+ def get_frozen_data (name , source = None ):
16+ with import_helper .frozen_modules ():
17+ return _imp .get_frozen_object (name )
1118
1219
1320class FindSpecTests (abc .FinderTests ):
@@ -19,39 +26,49 @@ def find(self, name, **kwargs):
1926 with import_helper .frozen_modules ():
2027 return finder .find_spec (name , ** kwargs )
2128
22- def check (self , spec , name ):
29+ def check (self , spec , name , orig = None ):
2330 self .assertEqual (spec .name , name )
2431 self .assertIs (spec .loader , self .machinery .FrozenImporter )
2532 self .assertEqual (spec .origin , 'frozen' )
2633 self .assertFalse (spec .has_location )
34+ self .assertIsNotNone (spec .loader_state )
35+
36+ def check_data (self , spec , source = None ):
37+ expected = get_frozen_data (spec .name , source )
38+ data , = spec .loader_state
39+ code = marshal .loads (data )
40+ self .assertEqual (code , expected )
2741
2842 def test_module (self ):
29- names = [
30- '__hello__' ,
31- '__hello_alias__' ,
32- '__hello_only__' ,
33- '__phello__.__init__' ,
34- '__phello__.spam' ,
35- '__phello__.ham.__init__' ,
36- '__phello__.ham.eggs' ,
37- ]
38- for name in names :
43+ FROZEN_ONLY = os .path .join (REPO_ROOT , 'Tools' , 'freeze' , 'flag.py' )
44+ modules = {
45+ '__hello__' : None ,
46+ '__phello__.__init__' : None ,
47+ '__phello__.spam' : None ,
48+ '__phello__.ham.__init__' : None ,
49+ '__phello__.ham.eggs' : None ,
50+ '__hello_alias__' : '__hello__' ,
51+ '__hello_only__' : FROZEN_ONLY ,
52+ }
53+ for name in modules :
3954 with self .subTest (name ):
4055 spec = self .find (name )
4156 self .check (spec , name )
4257 self .assertEqual (spec .submodule_search_locations , None )
58+ self .check_data (spec , modules [name ])
4359
4460 def test_package (self ):
45- names = [
46- '__phello__' ,
47- '__phello__.ham' ,
48- '__phello_alias__' ,
49- ]
50- for name in names :
61+ modules = {
62+ '__phello__' : None ,
63+ '__phello__.ham' : None ,
64+ '__phello_alias__' : '__hello__' ,
65+ }
66+ for name in modules :
5167 with self .subTest (name ):
5268 spec = self .find (name )
5369 self .check (spec , name )
5470 self .assertEqual (spec .submodule_search_locations , [])
71+ self .check_data (spec , modules [name ])
5572
5673 # These are covered by test_module() and test_package().
5774 test_module_in_package = None
0 commit comments