@@ -32,13 +32,7 @@ def check_basic(self, spec, name, ispkg=False):
32
32
self .assertIsNone (spec .submodule_search_locations )
33
33
self .assertIsNotNone (spec .loader_state )
34
34
35
- def check_search_location (self , spec , source = None ):
36
- # Frozen packages do not have any path entries.
37
- # (See https://bugs.python.org/issue21736.)
38
- expected = []
39
- self .assertListEqual (spec .submodule_search_locations , expected )
40
-
41
- def check_data (self , spec , source = None , ispkg = None ):
35
+ def check_data (self , spec ):
42
36
with import_helper .frozen_modules ():
43
37
expected = _imp .get_frozen_object (spec .name )
44
38
data = spec .loader_state
@@ -48,40 +42,72 @@ def check_data(self, spec, source=None, ispkg=None):
48
42
code = marshal .loads (data )
49
43
self .assertEqual (code , expected )
50
44
45
+ def check_search_locations (self , spec ):
46
+ # Frozen packages do not have any path entries.
47
+ # (See https://bugs.python.org/issue21736.)
48
+ expected = []
49
+ self .assertListEqual (spec .submodule_search_locations , expected )
50
+
51
51
def test_module (self ):
52
+ modules = [
53
+ '__hello__' ,
54
+ '__phello__.spam' ,
55
+ '__phello__.ham.eggs' ,
56
+ ]
57
+ for name in modules :
58
+ with self .subTest (f'{ name } -> { name } ' ):
59
+ spec = self .find (name )
60
+ self .check_basic (spec , name )
61
+ self .check_data (spec )
52
62
modules = {
53
- '__hello__' : None ,
54
- '__phello__.__init__' : None ,
55
- '__phello__.spam' : None ,
56
- '__phello__.ham.__init__' : None ,
57
- '__phello__.ham.eggs' : None ,
58
63
'__hello_alias__' : '__hello__' ,
59
- }
60
- for name , source in modules .items ():
61
- with self .subTest (name ):
64
+ '_frozen_importlib' : 'importlib._bootstrap' ,
65
+ }
66
+ for name , origname in modules .items ():
67
+ with self .subTest (f'{ name } -> { origname } ' ):
68
+ spec = self .find (name )
69
+ self .check_basic (spec , name )
70
+ self .check_data (spec )
71
+ modules = [
72
+ '__phello__.__init__' ,
73
+ '__phello__.ham.__init__' ,
74
+ ]
75
+ for name in modules :
76
+ origname = name .rpartition ('.' )[0 ]
77
+ with self .subTest (f'{ name } -> { origname } ' ):
62
78
spec = self .find (name )
63
79
self .check_basic (spec , name )
64
- self .check_data (spec , source )
80
+ self .check_data (spec )
81
+ modules = {
82
+ '__hello_only__' : ('Tools' , 'freeze' , 'flag.py' ),
83
+ }
84
+ for name , path in modules .items ():
85
+ filename = os .path .join (REPO_ROOT , * path )
86
+ with self .subTest (f'{ name } -> { filename } ' ):
87
+ spec = self .find (name )
88
+ self .check_basic (spec , name )
89
+ self .check_data (spec )
65
90
66
91
def test_package (self ):
67
- modules = {
68
- '__phello__' : None ,
69
- '__phello__.ham' : None ,
92
+ packages = [
93
+ '__phello__' ,
94
+ '__phello__.ham' ,
95
+ ]
96
+ for name in packages :
97
+ with self .subTest (f'{ name } -> { name } ' ):
98
+ spec = self .find (name )
99
+ self .check_basic (spec , name , ispkg = True )
100
+ self .check_data (spec )
101
+ self .check_search_locations (spec )
102
+ packages = {
70
103
'__phello_alias__' : '__hello__' ,
71
104
}
72
- for name , source in modules .items ():
73
- with self .subTest (name ):
105
+ for name , origname in packages .items ():
106
+ with self .subTest (f' { name } -> { origname } ' ):
74
107
spec = self .find (name )
75
108
self .check_basic (spec , name , ispkg = True )
76
- self .check_search_location (spec , source )
77
- self .check_data (spec , source , ispkg = True )
78
-
79
- def test_frozen_only (self ):
80
- name = '__hello_only__'
81
- source = os .path .join (REPO_ROOT , 'Tools' , 'freeze' , 'flag.py' )
82
- spec = self .find (name )
83
- self .check_basic (spec , name )
84
- self .check_data (spec , source )
109
+ self .check_data (spec )
110
+ self .check_search_locations (spec )
85
111
86
112
# These are covered by test_module() and test_package().
87
113
test_module_in_package = None
0 commit comments