Skip to content

Commit

Permalink
Fix tests for Python 3.10.1 (2) (#11756)
Browse files Browse the repository at this point in the history
Followup to #11752. The syntax error changed between 3.10.0 and 3.10.1.
https://bugs.python.org/issue46004

I missed a few the first time around unfortunately.
https://bugs.python.org/issue46004

Instead of duplicating the original output, I chose to extend the test syntax 
introduced with #10404 and added support for == version checks.
  • Loading branch information
cdce8p authored and JukkaL committed Dec 16, 2021
1 parent d595468 commit 5919e92
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
20 changes: 15 additions & 5 deletions mypy/test/data.py
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
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
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
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

0 comments on commit 5919e92

Please sign in to comment.