Skip to content

Commit fd43709

Browse files
AlexWaygoodAvasam
andcommitted
Improve pyright verification of test cases in CI.
Co-authored-by: Avasam <samuel.06@hotmail.com>
1 parent d755da8 commit fd43709

File tree

9 files changed

+16
-17
lines changed

9 files changed

+16
-17
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,20 @@ jobs:
146146
python-platform: ${{ matrix.python-platform }}
147147
python-version: ${{ matrix.python-version }}
148148
no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy.
149-
project: ./pyrightconfig.stricter.json
150149
- uses: jakebailey/pyright-action@v1
151150
with:
152151
version: ${{ steps.pyright_version.outputs.value }}
153152
python-platform: ${{ matrix.python-platform }}
154153
python-version: ${{ matrix.python-version }}
155154
no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy.
156-
project: ./pyrightconfig.testcases.json
155+
project: ./pyrightconfig.stricter.json
157156
- uses: jakebailey/pyright-action@v1
158157
with:
159158
version: ${{ steps.pyright_version.outputs.value }}
160159
python-platform: ${{ matrix.python-platform }}
161160
python-version: ${{ matrix.python-version }}
162161
no-comments: ${{ matrix.python-version != '3.10' || matrix.python-platform != 'Linux' }} # Having each job create the same comment is too noisy.
162+
project: ./pyrightconfig.testcases.json
163163

164164
stub-uploader:
165165
name: Run the stub_uploader tests

pyrightconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
"stdlib",
66
"stubs",
77
],
8+
"exclude": [
9+
// test cases use a custom config file
10+
"stubs/**/@tests/test_cases"
11+
],
812
"typeCheckingMode": "basic",
913
"strictListInference": true,
1014
"strictDictionaryInference": true,

pyrightconfig.stricter.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"stubs",
77
],
88
"exclude": [
9+
// test cases use a custom pyrightconfig file
10+
"stubs/**/@tests/test_cases",
911
"stdlib/distutils/command",
1012
"stdlib/lib2to3/refactor.pyi",
1113
"stdlib/_tkinter.pyi",

pyrightconfig.testcases.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"typeshedPath": ".",
44
"include": [
55
"test_cases",
6+
"stubs/**/@tests/test_cases"
67
],
78
"typeCheckingMode": "strict",
89
// Using unspecific "type ignore" comments in test_cases.

stubs/invoke/@tests/test_cases/check_task.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pyright: reportUnnecessaryTypeIgnoreComment=true
21
from __future__ import annotations
32

43
from invoke import Context, task

stubs/protobuf/@tests/test_cases/check_struct.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pyright: reportUnnecessaryTypeIgnoreComment=true
21
from __future__ import annotations
32

43
from google.protobuf.struct_pb2 import ListValue, Struct

stubs/regex/@tests/test_cases/check_finditer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# pyright: reportUnnecessaryTypeIgnoreComment=true
2-
31
from __future__ import annotations
42

53
from typing import List

stubs/requests/@tests/test_cases/check_post.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# pyright: reportUnnecessaryTypeIgnoreComment=true
2-
31
from __future__ import annotations
42

53
from collections.abc import Iterable

tests/check_consistent.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,22 @@ def check_stubs() -> None:
6565
allowed = {"METADATA.toml", "README", "README.md", "README.rst", "@tests"}
6666
assert_consistent_filetypes(dist, kind=".pyi", allowed=allowed)
6767

68+
tests_dir = dist / "@tests"
69+
if tests_dir.exists() and tests_dir.is_dir():
70+
py_files_present = bool([file for file in tests_dir.iterdir() if file.suffix == ".py"])
71+
error_message = "Test-case files must be in an `@tests/test_cases/` directory, not in the `@tests/` directory"
72+
assert not py_files_present, error_message
73+
6874

6975
def check_test_cases() -> None:
70-
for package_name, testcase_dir in get_all_testcase_directories():
76+
for _, testcase_dir in get_all_testcase_directories():
7177
assert_consistent_filetypes(testcase_dir, kind=".py", allowed={"README.md"}, allow_nonidentifier_filenames=True)
7278
bad_test_case_filename = 'Files in a `test_cases` directory must have names starting with "check_"; got "{}"'
7379
for file in testcase_dir.rglob("*.py"):
7480
assert file.stem.startswith("check_"), bad_test_case_filename.format(file)
7581
with open(file, encoding="UTF-8") as f:
7682
lines = {line.strip() for line in f}
7783
assert "from __future__ import annotations" in lines, "Test-case files should use modern typing syntax where possible"
78-
if package_name != "stdlib":
79-
pyright_setting_not_enabled_msg = (
80-
f'Third-party test-case file "{file}" must have '
81-
f'"# pyright: reportUnnecessaryTypeIgnoreComment=true" '
82-
f"at the top of the file"
83-
)
84-
has_pyright_setting_enabled = "# pyright: reportUnnecessaryTypeIgnoreComment=true" in lines
85-
assert has_pyright_setting_enabled, pyright_setting_not_enabled_msg
8684

8785

8886
def check_no_symlinks() -> None:

0 commit comments

Comments
 (0)