Skip to content

Commit 5da171b

Browse files
authored
mypy_test.py: Always add dependencies of stubs to the files to test (#8800)
1 parent e5d52a3 commit 5da171b

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
with:
8080
python-version: 3.x
8181
- run: pip install -r requirements-tests.txt
82-
- run: ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }}
82+
- run: python ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }}
8383

8484
regression-tests:
8585
name: Run mypy on the test cases

tests/mypy_test.py

100755100644
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
VERSIONS_RE as VERSION_LINE_RE,
2626
colored,
2727
get_gitignore_spec,
28+
get_recursive_requirements,
2829
print_error,
2930
print_success_msg,
30-
read_dependencies,
3131
spec_matches_path,
3232
strip_comments,
3333
)
@@ -272,11 +272,19 @@ def add_third_party_files(
272272
return
273273
seen_dists.add(distribution)
274274

275-
dependencies = read_dependencies(distribution)
275+
stubs_dir = Path("stubs")
276+
dependencies = get_recursive_requirements(distribution)
277+
276278
for dependency in dependencies:
277-
add_third_party_files(dependency, files, args, configurations, seen_dists)
279+
if dependency in seen_dists:
280+
continue
281+
seen_dists.add(dependency)
282+
files_to_add = sorted((stubs_dir / dependency).rglob("*.pyi"))
283+
files.extend(files_to_add)
284+
for file in files_to_add:
285+
log(args, file, f"included as a dependency of {distribution!r}")
278286

279-
root = Path("stubs", distribution)
287+
root = stubs_dir / distribution
280288
for name in os.listdir(root):
281289
if name.startswith("."):
282290
continue
@@ -348,9 +356,10 @@ def test_third_party_stubs(code: int, args: TestConfig) -> TestResults:
348356
if spec_matches_path(gitignore_spec, distribution_path):
349357
continue
350358

351-
this_code, checked = test_third_party_distribution(distribution, args)
352-
code = max(code, this_code)
353-
files_checked += checked
359+
if distribution_path in args.filter or any(distribution_path in path.parents for path in args.filter):
360+
this_code, checked = test_third_party_distribution(distribution, args)
361+
code = max(code, this_code)
362+
files_checked += checked
354363

355364
return TestResults(code, files_checked)
356365

tests/regr_test.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
import subprocess
1010
import sys
1111
import tempfile
12-
from itertools import filterfalse, product
12+
from itertools import product
1313
from pathlib import Path
1414
from typing_extensions import TypeAlias
1515

1616
from utils import (
1717
PackageInfo,
1818
colored,
1919
get_all_testcase_directories,
20+
get_recursive_requirements,
2021
print_error,
2122
print_success_msg,
22-
read_dependencies,
2323
testcase_dir_from_package_name,
2424
)
2525

@@ -81,13 +81,6 @@ def package_with_test_cases(package_name: str) -> PackageInfo:
8181
)
8282

8383

84-
def get_recursive_requirements(package_name: str, seen: set[str] | None = None) -> list[str]:
85-
seen = seen if seen is not None else {package_name}
86-
for dependency in filterfalse(seen.__contains__, read_dependencies(package_name)):
87-
seen.update(get_recursive_requirements(dependency, seen))
88-
return sorted(seen | {package_name})
89-
90-
9184
def test_testcase_directory(package: PackageInfo, version: str, platform: str) -> ReturnCode:
9285
package_name, test_case_directory = package
9386
is_stdlib = package_name == "stdlib"

tests/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"""Utilities that are imported by multiple scripts in the tests directory."""
22

3+
from __future__ import annotations
4+
35
import os
46
import re
57
from functools import cache
8+
from itertools import filterfalse
69
from pathlib import Path
710
from typing import NamedTuple
811

@@ -53,6 +56,13 @@ def read_dependencies(distribution: str) -> tuple[str, ...]:
5356
return tuple(dependencies)
5457

5558

59+
def get_recursive_requirements(package_name: str, seen: set[str] | None = None) -> list[str]:
60+
seen = seen if seen is not None else {package_name}
61+
for dependency in filterfalse(seen.__contains__, read_dependencies(package_name)):
62+
seen.update(get_recursive_requirements(dependency, seen))
63+
return sorted(seen | {package_name})
64+
65+
5666
# ====================================================================
5767
# Parsing the stdlib/VERSIONS file
5868
# ====================================================================

0 commit comments

Comments
 (0)