mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 04:54:47 +08:00
mypy_test.py: Always add dependencies of stubs to the files to test (#8800)
This commit is contained in:
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@@ -79,7 +79,7 @@ jobs:
|
||||
with:
|
||||
python-version: 3.x
|
||||
- run: pip install -r requirements-tests.txt
|
||||
- run: ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }}
|
||||
- run: python ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }}
|
||||
|
||||
regression-tests:
|
||||
name: Run mypy on the test cases
|
||||
|
||||
25
tests/mypy_test.py
Executable file → Normal file
25
tests/mypy_test.py
Executable file → Normal file
@@ -25,9 +25,9 @@ from utils import (
|
||||
VERSIONS_RE as VERSION_LINE_RE,
|
||||
colored,
|
||||
get_gitignore_spec,
|
||||
get_recursive_requirements,
|
||||
print_error,
|
||||
print_success_msg,
|
||||
read_dependencies,
|
||||
spec_matches_path,
|
||||
strip_comments,
|
||||
)
|
||||
@@ -272,11 +272,19 @@ def add_third_party_files(
|
||||
return
|
||||
seen_dists.add(distribution)
|
||||
|
||||
dependencies = read_dependencies(distribution)
|
||||
for dependency in dependencies:
|
||||
add_third_party_files(dependency, files, args, configurations, seen_dists)
|
||||
stubs_dir = Path("stubs")
|
||||
dependencies = get_recursive_requirements(distribution)
|
||||
|
||||
root = Path("stubs", distribution)
|
||||
for dependency in dependencies:
|
||||
if dependency in seen_dists:
|
||||
continue
|
||||
seen_dists.add(dependency)
|
||||
files_to_add = sorted((stubs_dir / dependency).rglob("*.pyi"))
|
||||
files.extend(files_to_add)
|
||||
for file in files_to_add:
|
||||
log(args, file, f"included as a dependency of {distribution!r}")
|
||||
|
||||
root = stubs_dir / distribution
|
||||
for name in os.listdir(root):
|
||||
if name.startswith("."):
|
||||
continue
|
||||
@@ -348,9 +356,10 @@ def test_third_party_stubs(code: int, args: TestConfig) -> TestResults:
|
||||
if spec_matches_path(gitignore_spec, distribution_path):
|
||||
continue
|
||||
|
||||
this_code, checked = test_third_party_distribution(distribution, args)
|
||||
code = max(code, this_code)
|
||||
files_checked += checked
|
||||
if distribution_path in args.filter or any(distribution_path in path.parents for path in args.filter):
|
||||
this_code, checked = test_third_party_distribution(distribution, args)
|
||||
code = max(code, this_code)
|
||||
files_checked += checked
|
||||
|
||||
return TestResults(code, files_checked)
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from itertools import filterfalse, product
|
||||
from itertools import product
|
||||
from pathlib import Path
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
@@ -17,9 +17,9 @@ from utils import (
|
||||
PackageInfo,
|
||||
colored,
|
||||
get_all_testcase_directories,
|
||||
get_recursive_requirements,
|
||||
print_error,
|
||||
print_success_msg,
|
||||
read_dependencies,
|
||||
testcase_dir_from_package_name,
|
||||
)
|
||||
|
||||
@@ -81,13 +81,6 @@ parser.add_argument(
|
||||
)
|
||||
|
||||
|
||||
def get_recursive_requirements(package_name: str, seen: set[str] | None = None) -> list[str]:
|
||||
seen = seen if seen is not None else {package_name}
|
||||
for dependency in filterfalse(seen.__contains__, read_dependencies(package_name)):
|
||||
seen.update(get_recursive_requirements(dependency, seen))
|
||||
return sorted(seen | {package_name})
|
||||
|
||||
|
||||
def test_testcase_directory(package: PackageInfo, version: str, platform: str) -> ReturnCode:
|
||||
package_name, test_case_directory = package
|
||||
is_stdlib = package_name == "stdlib"
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
"""Utilities that are imported by multiple scripts in the tests directory."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
from functools import cache
|
||||
from itertools import filterfalse
|
||||
from pathlib import Path
|
||||
from typing import NamedTuple
|
||||
|
||||
@@ -53,6 +56,13 @@ def read_dependencies(distribution: str) -> tuple[str, ...]:
|
||||
return tuple(dependencies)
|
||||
|
||||
|
||||
def get_recursive_requirements(package_name: str, seen: set[str] | None = None) -> list[str]:
|
||||
seen = seen if seen is not None else {package_name}
|
||||
for dependency in filterfalse(seen.__contains__, read_dependencies(package_name)):
|
||||
seen.update(get_recursive_requirements(dependency, seen))
|
||||
return sorted(seen | {package_name})
|
||||
|
||||
|
||||
# ====================================================================
|
||||
# Parsing the stdlib/VERSIONS file
|
||||
# ====================================================================
|
||||
|
||||
Reference in New Issue
Block a user