Skip to content

Commit 392ae93

Browse files
authored
Move test_cases to stdlib/@tests/test_cases (#11865)
1 parent ea61ca5 commit 392ae93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+37
-37
lines changed

pyrightconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"exclude": [
99
// test cases use a custom config file
10-
"stubs/**/@tests/test_cases"
10+
"**/@tests/test_cases",
1111
],
1212
"typeCheckingMode": "strict",
1313
// Allowed in base settings for incomplete stubs, checked in stricter settings

pyrightconfig.stricter.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"exclude": [
99
// test cases use a custom pyrightconfig file
10-
"stubs/**/@tests/test_cases",
10+
"**/@tests/test_cases",
1111
"stdlib/distutils/command",
1212
"stdlib/distutils/dist.pyi",
1313
"stdlib/importlib/readers.pyi",

pyrightconfig.testcases.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"$schema": "https://raw.githubusercontent.com/microsoft/pyright/main/packages/vscode-pyright/schemas/pyrightconfig.schema.json",
33
"typeshedPath": ".",
44
"include": [
5-
"test_cases",
6-
"stubs/**/@tests/test_cases"
5+
"**/@tests/test_cases",
76
],
87
"typeCheckingMode": "strict",
98
// Extra strict settings
File renamed without changes.
File renamed without changes.

tests/README.md

+2-1

test_cases/README.md renamed to tests/REGRESSION.md

+13-18

tests/check_typeshed_structure.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from parse_metadata import read_metadata
1616
from utils import (
1717
REQS_FILE,
18+
STDLIB_PATH,
1819
TEST_CASES_DIR,
1920
TESTS_DIR,
2021
VERSIONS_RE,
@@ -59,7 +60,8 @@ def assert_consistent_filetypes(
5960

6061
def check_stdlib() -> None:
6162
"""Check that the stdlib directory contains only the correct files."""
62-
assert_consistent_filetypes(Path("stdlib"), kind=".pyi", allowed={"_typeshed/README.md", "VERSIONS"})
63+
assert_consistent_filetypes(STDLIB_PATH, kind=".pyi", allowed={"_typeshed/README.md", "VERSIONS", TESTS_DIR})
64+
check_tests_dir(tests_path("stdlib"))
6365

6466

6567
def check_stubs() -> None:
@@ -81,11 +83,13 @@ def check_stubs() -> None:
8183

8284
tests_dir = tests_path(dist.name)
8385
if tests_dir.exists() and tests_dir.is_dir():
84-
py_files_present = any(file.suffix == ".py" for file in tests_dir.iterdir())
85-
error_message = (
86-
f"Test-case files must be in an `{TESTS_DIR}/{TEST_CASES_DIR}` directory, not in the `{TESTS_DIR}` directory"
87-
)
88-
assert not py_files_present, error_message
86+
check_tests_dir(tests_dir)
87+
88+
89+
def check_tests_dir(tests_dir: Path) -> None:
90+
py_files_present = any(file.suffix == ".py" for file in tests_dir.iterdir())
91+
error_message = f"Test-case files must be in an `{TESTS_DIR}/{TEST_CASES_DIR}` directory, not in the `{TESTS_DIR}` directory"
92+
assert not py_files_present, error_message
8993

9094

9195
def check_distutils() -> None:
@@ -146,7 +150,7 @@ def check_versions_file() -> None:
146150

147151
def _find_stdlib_modules() -> set[str]:
148152
modules = set[str]()
149-
for path, _, files in os.walk("stdlib"):
153+
for path, _, files in os.walk(STDLIB_PATH):
150154
for filename in files:
151155
base_module = ".".join(os.path.normpath(path).split(os.sep)[1:])
152156
if filename == "__init__.pyi":

tests/mypy_test.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from parse_metadata import PackageDependencies, get_recursive_requirements, read_metadata
3030
from utils import (
3131
PYTHON_VERSION,
32+
TESTS_DIR,
3233
VERSIONS_RE as VERSION_LINE_RE,
3334
colored,
3435
get_gitignore_spec,
@@ -366,7 +367,7 @@ def test_stdlib(args: TestConfig) -> TestResult:
366367
stdlib = Path("stdlib")
367368
supported_versions = parse_versions(stdlib / "VERSIONS")
368369
for name in os.listdir(stdlib):
369-
if name == "VERSIONS" or name.startswith("."):
370+
if name in ("VERSIONS", TESTS_DIR) or name.startswith("."):
370371
continue
371372
module = Path(name).stem
372373
module_min_version, module_max_version = supported_versions[module]

tests/utils.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def colored(text: str, color: str | None = None, **kwargs: Any) -> str: # type:
2222

2323
PYTHON_VERSION: Final = f"{sys.version_info.major}.{sys.version_info.minor}"
2424

25+
STDLIB_PATH = Path("stdlib")
2526
STUBS_PATH = Path("stubs")
2627

2728

@@ -139,15 +140,14 @@ def distribution_info(distribution_name: str) -> DistributionTests:
139140

140141

141142
def tests_path(distribution_name: str) -> Path:
142-
assert distribution_name != "stdlib"
143-
return STUBS_PATH / distribution_name / TESTS_DIR
143+
if distribution_name == "stdlib":
144+
return STDLIB_PATH / TESTS_DIR
145+
else:
146+
return STUBS_PATH / distribution_name / TESTS_DIR
144147

145148

146149
def test_cases_path(distribution_name: str) -> Path:
147-
if distribution_name == "stdlib":
148-
return Path(TEST_CASES_DIR)
149-
else:
150-
return tests_path(distribution_name) / TEST_CASES_DIR
150+
return tests_path(distribution_name) / TEST_CASES_DIR
151151

152152

153153
def get_all_testcase_directories() -> list[DistributionTests]:

0 commit comments

Comments
 (0)