Skip to content

mypy_test.py: Always add dependencies of stubs to the files to test #8800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 16 additions & 7 deletions tests/mypy_test.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
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,
)
Expand Down Expand Up @@ -272,11 +272,19 @@ def add_third_party_files(
return
seen_dists.add(distribution)

dependencies = read_dependencies(distribution)
stubs_dir = Path("stubs")
dependencies = get_recursive_requirements(distribution)

for dependency in dependencies:
add_third_party_files(dependency, files, args, configurations, seen_dists)
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 = Path("stubs", distribution)
root = stubs_dir / distribution
for name in os.listdir(root):
if name.startswith("."):
continue
Expand Down Expand Up @@ -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)

Expand Down
11 changes: 2 additions & 9 deletions tests/regr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
import subprocess
import sys
import tempfile
from itertools import filterfalse, product
from itertools import product
from pathlib import Path
from typing_extensions import TypeAlias

from utils import (
PackageInfo,
colored,
get_all_testcase_directories,
get_recursive_requirements,
print_error,
print_success_msg,
read_dependencies,
testcase_dir_from_package_name,
)

Expand Down Expand Up @@ -81,13 +81,6 @@ def package_with_test_cases(package_name: str) -> PackageInfo:
)


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"
Expand Down
10 changes: 10 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
# ====================================================================
Expand Down