Skip to content
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

Fix tests for Python 3.10.1 (2) #11756

Merged
merged 2 commits into from
Dec 16, 2021
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
20 changes: 15 additions & 5 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ def parse_test_case(case: 'DataDrivenTestCase') -> None:
if arg == 'skip-path-normalization':
normalize_output = False
if arg.startswith("version"):
if arg[7:9] != ">=":
compare_op = arg[7:9]
if compare_op not in {">=", "=="}:
raise ValueError(
"{}, line {}: Only >= version checks are currently supported".format(
"{}, line {}: Only >= and == version checks are currently supported"
.format(
case.file, item.line
)
)
Expand All @@ -127,9 +129,17 @@ def parse_test_case(case: 'DataDrivenTestCase') -> None:
raise ValueError(
'{}, line {}: "{}" is not a valid python version'.format(
case.file, item.line, version_str))
if not sys.version_info >= version:
version_check = False

if compare_op == ">=":
version_check = sys.version_info >= version
elif compare_op == "==":
if not 1 < len(version) < 4:
raise ValueError(
'{}, line {}: Only minor or patch version checks '
'are currently supported with "==": "{}"'.format(
case.file, item.line, version_str
)
)
version_check = sys.version_info[:len(version)] == version
if version_check:
tmp_output = [expand_variables(line) for line in item.data]
if os.path.sep == '\\' and normalize_output:
Expand Down
4 changes: 1 addition & 3 deletions test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ reveal_type(1) # N: Revealed type is "Literal[1]?"
1 ''
[out]
main:1: error: invalid syntax [syntax]
[out version>=3.10]
[out version==3.10.0]
main:1: error: invalid syntax. Perhaps you forgot a comma? [syntax]
[out version>=3.10.1]
main:1: error: invalid syntax [syntax]

[case testErrorCodeSyntaxError2]
def f(): # E: Type signature has too many arguments [syntax]
Expand Down
18 changes: 9 additions & 9 deletions test-data/unit/fine-grained-blockers.test
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class C:
a.py:1: error: invalid syntax
==
main:5: error: Missing positional argument "x" in call to "f" of "C"
[out version>=3.10]
[out version==3.10.0]
==
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
==
Expand All @@ -176,7 +176,7 @@ main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missin
a.py:1: error: invalid syntax
==
main:2: error: Too many arguments for "f"
[out version>=3.10]
[out version==3.10.0]
main:1: error: Cannot find implementation or library stub for module named "a"
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
==
Expand Down Expand Up @@ -259,7 +259,7 @@ a.py:1: error: invalid syntax
a.py:1: error: invalid syntax
==
a.py:2: error: Missing positional argument "x" in call to "f"
[out version>=3.10]
[out version==3.10.0]
==
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
==
Expand Down Expand Up @@ -330,7 +330,7 @@ a.py:1: error: invalid syntax
main:1: error: Cannot find implementation or library stub for module named "a"
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
b.py:1: error: Cannot find implementation or library stub for module named "a"
[out version>=3.10]
[out version==3.10.0]
==
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
==
Expand Down Expand Up @@ -358,7 +358,7 @@ a.py:1: error: invalid syntax
b.py:1: error: Cannot find implementation or library stub for module named "a"
b.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
main:1: error: Cannot find implementation or library stub for module named "a"
[out version>=3.10]
[out version==3.10.0]
==
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
==
Expand Down Expand Up @@ -388,7 +388,7 @@ a.py:1: error: invalid syntax
==
b.py:2: error: Module has no attribute "f"
b.py:3: error: "int" not callable
[out version>=3.10]
[out version==3.10.0]
==
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
==
Expand All @@ -411,7 +411,7 @@ def f() -> None: pass
<ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax
==
a.py:1: error: "int" not callable
[out version>=3.10]
[out version==3.10.0]
==
<ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax. Perhaps you forgot a comma?
==
Expand Down Expand Up @@ -490,7 +490,7 @@ a.py:1: error: invalid syntax
<ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax
==
a.py:2: error: "int" not callable
[out version>=3.10]
[out version==3.10.0]
==
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
==
Expand All @@ -515,7 +515,7 @@ a.py:1: error: invalid syntax
==
b.py:2: error: Incompatible return value type (got "str", expected "int")
==
[out version>=3.10]
[out version==3.10.0]
a.py:1: error: invalid syntax. Perhaps you forgot a comma?
==
b.py:2: error: Incompatible return value type (got "str", expected "int")
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/parse.test
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ MypyFile:1(
x not y
[out]
main:1: error: invalid syntax
[out version>=3.10]
[out version==3.10.0]
main:1: error: invalid syntax. Perhaps you forgot a comma?

[case testNotIs]
Expand All @@ -946,7 +946,7 @@ x not is y # E: invalid syntax
1 ~ 2
[out]
main:1: error: invalid syntax
[out version>=3.10]
[out version==3.10.0]
main:1: error: invalid syntax. Perhaps you forgot a comma?

[case testSliceInList39]
Expand Down