8000 Rearrage the finder tests. (gh-28740) · python/cpython@69f6dab · GitHub
[go: up one dir, main page]

Skip to content

Commit 69f6dab

Browse files
Rearrage the finder tests. (gh-28740)
This makes the tests a bit cleaner and makes adding more tests a little simpler. https://bugs.python.org/issue45324
1 parent c3d9ac8 commit 69f6dab

File tree

1 file changed

+56
-30
lines changed

1 file changed

+56
-30
lines changed

Lib/test/test_importlib/frozen/test_finder.py

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,7 @@ def check_basic(self, spec, name, ispkg=False):
3232
self.assertIsNone(spec.submodule_search_locations)
3333
self.assertIsNotNone(spec.loader_state)
3434

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):
4236
with import_helper.frozen_modules():
4337
expected = _imp.get_frozen_object(spec.name)
4438
data = spec.loader_state
@@ -48,40 +42,72 @@ def check_data(self, spec, source=None, ispkg=None):
4842
code = marshal.loads(data)
4943
self.assertEqual(code, expected)
5044

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+
5151
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)
5262
modules = {
53-
'__hello__': None,
54-
'__phello__.__init__': None,
55-
'__phello__.spam': None,
56-
'__phello__.ham.__init__': None,
57-
'__phello__.ham.eggs': None,
5863
'__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}'):
6278
spec = self.find(name)
6379
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)
6590

6691
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 = {
70103
'__phello_alias__': '__hello__',
71104
}
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}'):
74107
spec = self.find(name)
75108
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)
85111

86112
# These are covered by test_module() and test_package().
87113
test_module_in_package = None

0 commit comments

Comments
 (0)
0