Skip to content

Commit

Permalink
test_packages_distributions_all_module_types: Create valid import names
Browse files Browse the repository at this point in the history
The import names that were created by these tests were not valid Python
identifiers.

Fix that, and furthermore: add another check to verify that _all_ import
names returned from packages_distributions() are always valid Python
identifiers. Ideally we should check that all keys returned from
packages_distributions() are valid import names (i.e. can be imported),
but this is at least a step in the right direction.
  • Loading branch information
jherland committed Mar 19, 2023
1 parent fa9cca4 commit 70ff991
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ def test_packages_distributions_all_module_types(self):
filenames = list(
itertools.chain.from_iterable(
[
f'{i}-top-level{suffix}',
f'{i}-in-namespace/mod{suffix}',
f'{i}-in-package/__init__.py',
f'{i}-in-package/mod{suffix}',
f'top_level_{i}{suffix}',
f'in_namespace_{i}/mod{suffix}',
f'in_package_{i}/__init__.py',
f'in_package_{i}/mod{suffix}',
]
for i, suffix in enumerate(suffixes)
)
Expand All @@ -367,9 +367,14 @@ def test_packages_distributions_all_module_types(self):
distributions = packages_distributions()

for i in range(len(suffixes)):
assert distributions[f'{i}-top-level'] == ['all_distributions']
assert distributions[f'{i}-in-namespace'] == ['all_distributions']
assert distributions[f'{i}-in-package'] == ['all_distributions']
assert distributions[f'top_level_{i}'] == ['all_distributions']
assert distributions[f'in_namespace_{i}'] == ['all_distributions']
assert distributions[f'in_package_{i}'] == ['all_distributions']

# All keys returned from packages_distributions() should be valid import
# names, which means that they must _at least_ be valid identifiers:
for import_name in distributions.keys():
assert import_name.isidentifier(), import_name


class PackagesDistributionsEggTest(
Expand Down

0 comments on commit 70ff991

Please sign in to comment.