mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
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
This commit is contained in:
parent
c3d9ac8b34
commit
69f6dabb9c
1 changed files with 60 additions and 34 deletions
|
@ -32,13 +32,7 @@ class FindSpecTests(abc.FinderTests):
|
||||||
self.assertIsNone(spec.submodule_search_locations)
|
self.assertIsNone(spec.submodule_search_locations)
|
||||||
self.assertIsNotNone(spec.loader_state)
|
self.assertIsNotNone(spec.loader_state)
|
||||||
|
|
||||||
def check_search_location(self, spec, source=None):
|
def check_data(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 check_data(self, spec, source=None, ispkg=None):
|
|
||||||
with import_helper.frozen_modules():
|
with import_helper.frozen_modules():
|
||||||
expected = _imp.get_frozen_object(spec.name)
|
expected = _imp.get_frozen_object(spec.name)
|
||||||
data = spec.loader_state
|
data = spec.loader_state
|
||||||
|
@ -48,40 +42,72 @@ class FindSpecTests(abc.FinderTests):
|
||||||
code = marshal.loads(data)
|
code = marshal.loads(data)
|
||||||
self.assertEqual(code, expected)
|
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):
|
def test_module(self):
|
||||||
modules = {
|
modules = [
|
||||||
'__hello__': None,
|
'__hello__',
|
||||||
'__phello__.__init__': None,
|
'__phello__.spam',
|
||||||
'__phello__.spam': None,
|
'__phello__.ham.eggs',
|
||||||
'__phello__.ham.__init__': None,
|
]
|
||||||
'__phello__.ham.eggs': None,
|
for name in modules:
|
||||||
'__hello_alias__': '__hello__',
|
with self.subTest(f'{name} -> {name}'):
|
||||||
}
|
|
||||||
for name, source in modules.items():
|
|
||||||
with self.subTest(name):
|
|
||||||
spec = self.find(name)
|
spec = self.find(name)
|
||||||
self.check_basic(spec, name)
|
self.check_basic(spec, name)
|
||||||
self.check_data(spec, source)
|
self.check_data(spec)
|
||||||
|
modules = {
|
||||||
|
'__hello_alias__': '__hello__',
|
||||||
|
'_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)
|
||||||
|
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):
|
def test_package(self):
|
||||||
modules = {
|
packages = [
|
||||||
'__phello__': None,
|
'__phello__',
|
||||||
'__phello__.ham': None,
|
'__phello__.ham',
|
||||||
'__phello_alias__': '__hello__',
|
]
|
||||||
}
|
for name in packages:
|
||||||
for name, source in modules.items():
|
with self.subTest(f'{name} -> {name}'):
|
||||||
with self.subTest(name):
|
|
||||||
spec = self.find(name)
|
spec = self.find(name)
|
||||||
self.check_basic(spec, name, ispkg=True)
|
self.check_basic(spec, name, ispkg=True)
|
||||||
self.check_search_location(spec, source)
|
self.check_data(spec)
|
||||||
self.check_data(spec, source, ispkg=True)
|
self.check_search_locations(spec)
|
||||||
|
packages = {
|
||||||
def test_frozen_only(self):
|
'__phello_alias__': '__hello__',
|
||||||
name = '__hello_only__'
|
}
|
||||||
source = os.path.join(REPO_ROOT, 'Tools', 'freeze', 'flag.py')
|
for name, origname in packages.items():
|
||||||
spec = self.find(name)
|
with self.subTest(f'{name} -> {origname}'):
|
||||||
self.check_basic(spec, name)
|
spec = self.find(name)
|
||||||
self.check_data(spec, source)
|
self.check_basic(spec, name, ispkg=True)
|
||||||
|
self.check_data(spec)
|
||||||
|
self.check_search_locations(spec)
|
||||||
|
|
||||||
# These are covered by test_module() and test_package().
|
# These are covered by test_module() and test_package().
|
||||||
test_module_in_package = None
|
test_module_in_package = None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue