Skip to content

bpo-45324: Rearrange some of the FrozenImporter finder tests. #28740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 56 additions & 30 deletions Lib/test/test_importlib/frozen/test_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ def check_basic(self, spec, name, ispkg=False):
self.assertIsNone(spec.submodule_search_locations)
self.assertIsNotNone(spec.loader_state)

def check_search_location(self, spec, source=None):
# Frozen packages do not have any path entries.
# (See https://bugs.python.org/issue21736.)
expected = []
self.assertListEqual(spec.submodule_search_locations, expected)

def check_data(self, spec, source=None, ispkg=None):
def check_data(self, spec):
with import_helper.frozen_modules():
expected = _imp.get_frozen_object(spec.name)
data = spec.loader_state
Expand All @@ -48,40 +42,72 @@ def check_data(self, spec, source=None, ispkg=None):
code = marshal.loads(data)
self.assertEqual(code, expected)

def check_search_locations(self, spec):
# Frozen packages do not have any path entries.
# (See https://bugs.python.org/issue21736.)
expected = []
self.assertListEqual(spec.submodule_search_locations, expected)

def test_module(self):
modules = [
'__hello__',
'__phello__.spam',
'__phello__.ham.eggs',
]
for name in modules:
with self.subTest(f'{name} -> {name}'):
spec = self.find(name)
self.check_basic(spec, name)
self.check_data(spec)
modules = {
'__hello__': None,
'__phello__.__init__': None,
'__phello__.spam': None,
'__phello__.ham.__init__': None,
'__phello__.ham.eggs': None,
'__hello_alias__': '__hello__',
}
for name, source in modules.items():
with self.subTest(name):
'_frozen_importlib': 'importlib._bootstrap',
}
for name, origname in modules.items():
with self.subTest(f'{name} -> {origname}'):
spec = self.find(name)
self.check_basic(spec, name)
self.check_data(spec)
modules = [
'__phello__.__init__',
'__phello__.ham.__init__',
]
for name in modules:
origname = name.rpartition('.')[0]
with self.subTest(f'{name} -> {origname}'):
spec = self.find(name)
self.check_basic(spec, name)
self.check_data(spec, source)
self.check_data(spec)
modules = {
'__hello_only__': ('Tools', 'freeze', 'flag.py'),
}
for name, path in modules.items():
filename = os.path.join(REPO_ROOT, *path)
with self.subTest(f'{name} -> {filename}'):
spec = self.find(name)
self.check_basic(spec, name)
self.check_data(spec)

def test_package(self):
modules = {
'__phello__': None,
'__phello__.ham': None,
packages = [
'__phello__',
'__phello__.ham',
]
for name in packages:
with self.subTest(f'{name} -> {name}'):
spec = self.find(name)
self.check_basic(spec, name, ispkg=True)
self.check_data(spec)
self.check_search_locations(spec)
packages = {
'__phello_alias__': '__hello__',
}
for name, source in modules.items():
with self.subTest(name):
for name, origname in packages.items():
with self.subTest(f'{name} -> {origname}'):
spec = self.find(name)
self.check_basic(spec, name, ispkg=True)
self.check_search_location(spec, source)
self.check_data(spec, source, ispkg=True)

def test_frozen_only(self):
name = '__hello_only__'
source = os.path.join(REPO_ROOT, 'Tools', 'freeze', 'flag.py')
spec = self.find(name)
self.check_basic(spec, name)
self.check_data(spec, source)
self.check_data(spec)
self.check_search_locations(spec)

# These are covered by test_module() and test_package().
test_module_in_package = None
Expand Down