Skip to content

Commit 08e6e4c

Browse files
AvasamAlexWaygood
andauthored
Add pyright testcases / regression tests to the runtests script (#10002)
Co-authored-by: Alex Waygood <[email protected]>
1 parent f66769a commit 08e6e4c

File tree

1 file changed

+55
-17
lines changed

1 file changed

+55
-17
lines changed

scripts/runtests.py

+55-17
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ def colored(text: str, color: str | None = None, on_color: str | None = None, at
1919

2020

2121
_STRICTER_CONFIG_FILE = "pyrightconfig.stricter.json"
22+
_TESTCASES_CONFIG_FILE = "pyrightconfig.testcases.json"
23+
_TESTCASES = "test_cases"
24+
_NPX_ERROR_PATTERN = r"error (runn|find)ing npx"
25+
_NPX_ERROR_MESSAGE = colored("\nSkipping Pyright tests: npx is not installed or can't be run!", "yellow")
2226
_SUCCESS = colored("Success", "green")
2327
_SKIPPED = colored("Skipped", "yellow")
2428
_FAILED = colored("Failed", "red")
@@ -89,14 +93,15 @@ def main() -> None:
8993
print("\nRunning check_new_syntax.py...")
9094
check_new_syntax_result = subprocess.run([sys.executable, "tests/check_new_syntax.py"])
9195

92-
print(f"\nRunning Pyright on Python {_PYTHON_VERSION}...")
96+
strict_params = _get_strict_params(path)
97+
print(f"\nRunning Pyright ({'stricter' if strict_params else 'base' } configs) for Python {_PYTHON_VERSION}...")
9398
pyright_result = subprocess.run(
94-
[sys.executable, "tests/pyright_test.py", path, "--pythonversion", _PYTHON_VERSION] + _get_strict_params(path),
95-
stderr=subprocess.PIPE,
99+
[sys.executable, "tests/pyright_test.py", path, "--pythonversion", _PYTHON_VERSION] + strict_params,
100+
capture_output=True,
96101
text=True,
97102
)
98-
if re.match(r"error (runn|find)ing npx", pyright_result.stderr):
99-
print(colored("\nSkipping Pyright tests: npx is not installed or can't be run!", "yellow"))
103+
if re.match(_NPX_ERROR_PATTERN, pyright_result.stderr):
104+
print(_NPX_ERROR_MESSAGE)
100105
pyright_returncode = 0
101106
pyright_skipped = True
102107
else:
@@ -133,19 +138,47 @@ def main() -> None:
133138
print("\nRunning pytype...")
134139
pytype_result = subprocess.run([sys.executable, "tests/pytype_test.py", path])
135140

136-
print(f"\nRunning regression tests for Python {_PYTHON_VERSION}...")
137-
regr_test_result = subprocess.run(
138-
[sys.executable, "tests/regr_test.py", "stdlib" if folder == "stdlib" else stub, "--python-version", _PYTHON_VERSION],
139-
stderr=subprocess.PIPE,
140-
text=True,
141-
)
142-
# No test means they all ran successfully (0 out of 0). Not all 3rd-party stubs have regression tests.
143-
if "No test cases found" in regr_test_result.stderr:
141+
test_cases_path = Path(path) / "@tests" / _TESTCASES if folder == "stubs" else Path(_TESTCASES)
142+
if not test_cases_path.exists():
143+
# No test means they all ran successfully (0 out of 0). Not all 3rd-party stubs have regression tests.
144+
print(colored(f"\nRegression tests: No {_TESTCASES} folder for {stub!r}!", "green"))
145+
pyright_testcases_returncode = 0
146+
pyright_testcases_skipped = False
144147
regr_test_returncode = 0
145-
print(colored(f"\nNo test cases found for {stub!r}!", "green"))
146148
else:
147-
regr_test_returncode = regr_test_result.returncode
148-
print(regr_test_result.stderr)
149+
print(f"\nRunning Pyright regression tests for Python {_PYTHON_VERSION}...")
150+
command = [
151+
sys.executable,
152+
"tests/pyright_test.py",
153+
str(test_cases_path),
154+
"--pythonversion",
155+
_PYTHON_VERSION,
156+
"-p",
157+
_TESTCASES_CONFIG_FILE,
158+
]
159+
pyright_testcases_result = subprocess.run(command, capture_output=True, text=True)
160+
if re.match(_NPX_ERROR_PATTERN, pyright_testcases_result.stderr):
161+
print(_NPX_ERROR_MESSAGE)
162+
pyright_testcases_returncode = 0
163+
pyright_testcases_skipped = True
164+
else:
165+
print(pyright_result.stderr)
166+
pyright_testcases_returncode = pyright_testcases_result.returncode
167+
pyright_testcases_skipped = False
168+
169+
print(f"\nRunning mypy regression tests for Python {_PYTHON_VERSION}...")
170+
regr_test_result = subprocess.run(
171+
[sys.executable, "tests/regr_test.py", "stdlib" if folder == "stdlib" else stub, "--python-version", _PYTHON_VERSION],
172+
capture_output=True,
173+
text=True,
174+
)
175+
# No test means they all ran successfully (0 out of 0). Not all 3rd-party stubs have regression tests.
176+
if "No test cases found" in regr_test_result.stderr:
177+
regr_test_returncode = 0
178+
print(colored(f"\nNo test cases found for {stub!r}!", "green"))
179+
else:
180+
regr_test_returncode = regr_test_result.returncode
181+
print(regr_test_result.stderr)
149182

150183
any_failure = any(
151184
[
@@ -156,6 +189,7 @@ def main() -> None:
156189
mypy_result.returncode,
157190
getattr(stubtest_result, "returncode", 0),
158191
getattr(pytype_result, "returncode", 0),
192+
pyright_testcases_returncode,
159193
regr_test_returncode,
160194
]
161195
)
@@ -180,7 +214,11 @@ def main() -> None:
180214
print("pytype:", _SKIPPED)
181215
else:
182216
print("pytype:", _SUCCESS if pytype_result.returncode == 0 else _FAILED)
183-
print("Regression test:", _SUCCESS if regr_test_returncode == 0 else _FAILED)
217+
if pyright_testcases_skipped:
218+
print("Pyright regression tests:", _SKIPPED)
219+
else:
220+
print("Pyright regression tests:", _SUCCESS if pyright_testcases_returncode == 0 else _FAILED)
221+
print("mypy regression test:", _SUCCESS if regr_test_returncode == 0 else _FAILED)
184222

185223
sys.exit(int(any_failure))
186224

0 commit comments

Comments
 (0)