From 18d5669355d27e6ee70512535f073d1b8c912807 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 16 Dec 2021 12:31:29 +0100 Subject: [PATCH] Fix tests for Python 3.10.1 (2) (#11756) 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. --- mypy/test/data.py | 20 +++++++++++++++----- test-data/unit/check-errorcodes.test | 4 +--- test-data/unit/fine-grained-blockers.test | 18 +++++++++--------- test-data/unit/parse.test | 4 ++-- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/mypy/test/data.py b/mypy/test/data.py index 17cda87c1bd3..e886b11ffa8e 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -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 ) ) @@ -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: diff --git a/test-data/unit/check-errorcodes.test b/test-data/unit/check-errorcodes.test index 1ceafaed8dff..2f84ee1f4c6e 100644 --- a/test-data/unit/check-errorcodes.test +++ b/test-data/unit/check-errorcodes.test @@ -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] diff --git a/test-data/unit/fine-grained-blockers.test b/test-data/unit/fine-grained-blockers.test index 17a5c42c1128..66a68115afa5 100644 --- a/test-data/unit/fine-grained-blockers.test +++ b/test-data/unit/fine-grained-blockers.test @@ -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? == @@ -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 == @@ -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? == @@ -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? == @@ -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? == @@ -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? == @@ -411,7 +411,7 @@ def f() -> None: pass /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] == /test-data/unit/lib-stub/blocker.pyi:2: error: invalid syntax. Perhaps you forgot a comma? == @@ -490,7 +490,7 @@ a.py:1: error: invalid syntax /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? == @@ -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") diff --git a/test-data/unit/parse.test b/test-data/unit/parse.test index 7f3694120b12..ff892ce0ce05 100644 --- a/test-data/unit/parse.test +++ b/test-data/unit/parse.test @@ -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] @@ -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]