mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 12:44:28 +08:00
check_consistent.py: Allow having weird filenames in the test_cases directory (#9239)
This commit is contained in:
@@ -23,7 +23,9 @@ extension_descriptions = {".pyi": "stub", ".py": ".py"}
|
||||
supported_stubtest_platforms = {"win32", "darwin", "linux"}
|
||||
|
||||
|
||||
def assert_consistent_filetypes(directory: Path, *, kind: str, allowed: set[str]) -> None:
|
||||
def assert_consistent_filetypes(
|
||||
directory: Path, *, kind: str, allowed: set[str], allow_nonidentifier_filenames: bool = False
|
||||
) -> None:
|
||||
"""Check that given directory contains only valid Python files of a certain kind."""
|
||||
allowed_paths = {Path(f) for f in allowed}
|
||||
contents = list(directory.iterdir())
|
||||
@@ -36,8 +38,9 @@ def assert_consistent_filetypes(directory: Path, *, kind: str, allowed: set[str]
|
||||
# Note if a subdirectory is allowed, we will not check its contents
|
||||
continue
|
||||
if entry.is_file():
|
||||
assert entry.stem.isidentifier(), f'Files must be valid modules, got: "{entry}"'
|
||||
bad_filetype = f'Only {extension_descriptions[kind]!r} files allowed in the "{directory}" directory; got: {entry}'
|
||||
if not allow_nonidentifier_filenames:
|
||||
assert entry.stem.isidentifier(), f'Files must be valid modules, got: "{entry}"'
|
||||
bad_filetype = f'Only {extension_descriptions[kind]!r} files allowed in the "{directory}" directory; got: {entry}'
|
||||
assert entry.suffix == kind, bad_filetype
|
||||
else:
|
||||
assert entry.name.isidentifier(), f"Directories must be valid packages, got: {entry}"
|
||||
@@ -67,7 +70,7 @@ def check_stubs() -> None:
|
||||
|
||||
def check_test_cases() -> None:
|
||||
for package_name, testcase_dir in get_all_testcase_directories():
|
||||
assert_consistent_filetypes(testcase_dir, kind=".py", allowed={"README.md"})
|
||||
assert_consistent_filetypes(testcase_dir, kind=".py", allowed={"README.md"}, allow_nonidentifier_filenames=True)
|
||||
bad_test_case_filename = 'Files in a `test_cases` directory must have names starting with "check_"; got "{}"'
|
||||
for file in testcase_dir.rglob("*.py"):
|
||||
assert file.stem.startswith("check_"), bad_test_case_filename.format(file)
|
||||
|
||||
Reference in New Issue
Block a user