From c517b86b9ba7487e7758f187cf31478e7aeaad47 Mon Sep 17 00:00:00 2001 From: EXPLOSION Date: Sun, 26 Mar 2023 05:38:43 +0000 Subject: [PATCH] Check for duplicated files in tests (#14960) I didn't realize `builtins` tags in tests add two of the same file, rendering the first call of it useless! Anyways, now I know, and this PR should raise an error for anyone in similar straits. I believe I fixed all the tests? The error message is a bit... intimidating (for some reason raising a ValueError here makes some assert trip later on which has a long traceback) but I decided to imitate the other error messages nearby. --- mypy/test/data.py | 10 ++++++++++ test-data/unit/check-attr.test | 2 -- test-data/unit/check-enum.test | 2 -- test-data/unit/check-functools.test | 8 -------- test-data/unit/check-isinstance.test | 5 +---- test-data/unit/check-modules.test | 1 - test-data/unit/check-parameter-specification.test | 1 - test-data/unit/check-protocols.test | 2 -- test-data/unit/check-singledispatch.test | 3 --- test-data/unit/check-slots.test | 6 ------ test-data/unit/check-typevar-values.test | 5 ----- test-data/unit/fine-grained-modules.test | 2 +- test-data/unit/fine-grained.test | 1 - 13 files changed, 12 insertions(+), 36 deletions(-) diff --git a/mypy/test/data.py b/mypy/test/data.py index 5edc68f78a88..717ebdc9ebb2 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -207,6 +207,16 @@ def parse_test_case(case: DataDrivenTestCase) -> None: for file_path, contents in files: expand_errors(contents.split("\n"), output, file_path) + seen_files = set() + for file, _ in files: + if file in seen_files: + raise ValueError( + f"{case.file}, line {first_item.line}: Duplicated filename {file}. Did you include" + " it multiple times?" + ) + + seen_files.add(file) + case.input = input case.output = output case.output2 = output2 diff --git a/test-data/unit/check-attr.test b/test-data/unit/check-attr.test index 89eab92ebabd..3ca804943010 100644 --- a/test-data/unit/check-attr.test +++ b/test-data/unit/check-attr.test @@ -1714,8 +1714,6 @@ class C: # Note that for this test, the 'Value of type "int" is not indexable' errors are silly, # and a consequence of Callable etc. being set to an int in the test stub. b = attr.ib(type=Callable[[], C]) -[builtins fixtures/bool.pyi] - [file b.py] import attr import a diff --git a/test-data/unit/check-enum.test b/test-data/unit/check-enum.test index 80a7ca7ff99f..b62ed3d94210 100644 --- a/test-data/unit/check-enum.test +++ b/test-data/unit/check-enum.test @@ -1345,7 +1345,6 @@ class Foo(bytes, Enum): a = Foo.A reveal_type(a.value) # N: Revealed type is "Any" reveal_type(a._value_) # N: Revealed type is "Any" -[builtins fixtures/__new__.pyi] [builtins fixtures/primitives.pyi] [typing fixtures/typing-medium.pyi] @@ -1368,7 +1367,6 @@ class Bar(Foo): a = Bar.A reveal_type(a.value) # N: Revealed type is "Any" reveal_type(a._value_) # N: Revealed type is "Any" -[builtins fixtures/__new__.pyi] [builtins fixtures/primitives.pyi] [typing fixtures/typing-medium.pyi] diff --git a/test-data/unit/check-functools.test b/test-data/unit/check-functools.test index f95b823a5291..ebfe86f2b241 100644 --- a/test-data/unit/check-functools.test +++ b/test-data/unit/check-functools.test @@ -20,7 +20,6 @@ Ord() <= 1 # E: Unsupported operand types for <= ("Ord" and "int") Ord() == 1 Ord() > 1 # E: Unsupported operand types for > ("Ord" and "int") Ord() >= 1 # E: Unsupported operand types for >= ("Ord" and "int") -[builtins fixtures/ops.pyi] [builtins fixtures/dict.pyi] [case testTotalOrderingLambda] @@ -43,7 +42,6 @@ Ord() <= 1 # E: Unsupported operand types for <= ("Ord" and "int") Ord() == 1 Ord() > 1 # E: Unsupported operand types for > ("Ord" and "int") Ord() >= 1 # E: Unsupported operand types for >= ("Ord" and "int") -[builtins fixtures/ops.pyi] [builtins fixtures/dict.pyi] [case testTotalOrderingNonCallable] @@ -59,8 +57,6 @@ class Ord(object): Ord() <= Ord() # E: Unsupported left operand type for <= ("Ord") Ord() > Ord() # E: "int" not callable Ord() >= Ord() # E: Unsupported left operand type for >= ("Ord") - -[builtins fixtures/ops.pyi] [builtins fixtures/dict.pyi] [case testTotalOrderingReturnNotBool] @@ -79,8 +75,6 @@ reveal_type(Ord() <= Ord()) # N: Revealed type is "Any" reveal_type(Ord() == Ord()) # N: Revealed type is "builtins.bool" reveal_type(Ord() > Ord()) # N: Revealed type is "Any" reveal_type(Ord() >= Ord()) # N: Revealed type is "Any" - -[builtins fixtures/ops.pyi] [builtins fixtures/dict.pyi] [case testTotalOrderingAllowsAny] @@ -105,7 +99,6 @@ Ord() <= 1 # E: Unsupported left operand type for <= ("Ord") Ord() == 1 Ord() > 1 Ord() >= 1 # E: Unsupported left operand type for >= ("Ord") -[builtins fixtures/ops.pyi] [builtins fixtures/dict.pyi] [case testCachedProperty] @@ -151,5 +144,4 @@ def f(d: D[C]) -> None: reveal_type(d.__gt__) # N: Revealed type is "def (other: Any) -> builtins.bool" d: D[int] # E: Type argument "int" of "D" must be a subtype of "C" -[builtins fixtures/ops.pyi] [builtins fixtures/dict.pyi] diff --git a/test-data/unit/check-isinstance.test b/test-data/unit/check-isinstance.test index 0722ee8d91e5..2d010b8ba38d 100644 --- a/test-data/unit/check-isinstance.test +++ b/test-data/unit/check-isinstance.test @@ -2670,10 +2670,9 @@ if type(x) == int == str: else: reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]" -# mypy shows an error about "Unsupported left operand type for !=" if we don't include this -[builtins fixtures/typing-medium.pyi] # mypy thinks int isn't defined unless we include this [builtins fixtures/primitives.pyi] + [case testTypeNotEqualsCheck] from typing import Union @@ -2683,8 +2682,6 @@ if type(x) != int: else: reveal_type(x) # N: Revealed type is "builtins.int" -# mypy shows an error about "Unsupported left operand type for !=" if we don't include this -[builtins fixtures/typing-medium.pyi] # mypy thinks int isn't defined unless we include this [builtins fixtures/primitives.pyi] diff --git a/test-data/unit/check-modules.test b/test-data/unit/check-modules.test index 4b8308310ae6..1bf0e4874926 100644 --- a/test-data/unit/check-modules.test +++ b/test-data/unit/check-modules.test @@ -3216,7 +3216,6 @@ class Bar(Foo): from a import Foo class Bar(Foo): def frobnicate(self, *args) -> None: pass # type: ignore[override] # I know -[builtins fixtures/tuple.pyi] [builtins fixtures/dict.pyi] [out1] tmp/b.py:3: error: Signature of "frobnicate" incompatible with supertype "Foo" diff --git a/test-data/unit/check-parameter-specification.test b/test-data/unit/check-parameter-specification.test index 7ef0485f7841..fe66b18fbfea 100644 --- a/test-data/unit/check-parameter-specification.test +++ b/test-data/unit/check-parameter-specification.test @@ -539,7 +539,6 @@ def three(**kwargs: int) -> int: ... @expects_int_first # Accepted def four(*args: int) -> int: ... -[builtins fixtures/tuple.pyi] [builtins fixtures/dict.pyi] [case testParamSpecTwiceSolving] diff --git a/test-data/unit/check-protocols.test b/test-data/unit/check-protocols.test index 3b8e668c7546..182745b99e40 100644 --- a/test-data/unit/check-protocols.test +++ b/test-data/unit/check-protocols.test @@ -2280,7 +2280,6 @@ def func2(arg: Optional[A]) -> None: ... x: B func1(x) func2(x) -[builtins fixtures/tuple.pyi] [builtins fixtures/dict.pyi] [out] main:14: error: Argument 1 to "func1" has incompatible type "B"; expected "A" @@ -3191,7 +3190,6 @@ class NoneCompatible3(Protocol): class C(NoneCompatible3): ... C() # E: Cannot instantiate abstract class "C" with abstract attributes "f", "g" and "h" -[builtins fixtures/tuple.pyi] [builtins fixtures/classmethod.pyi] [case testEmptyBodyWithFinal] diff --git a/test-data/unit/check-singledispatch.test b/test-data/unit/check-singledispatch.test index 8fe049437c57..45bf1ca9cbf2 100644 --- a/test-data/unit/check-singledispatch.test +++ b/test-data/unit/check-singledispatch.test @@ -180,9 +180,6 @@ def f(arg) -> None: @f.register def g(arg: Mapping) -> None: pass - -[builtins fixtures/args.pyi] -[builtins fixtures/list.pyi] [builtins fixtures/dict.pyi] [case testIncorrectArgumentsInSingledispatchFunctionDefinition] diff --git a/test-data/unit/check-slots.test b/test-data/unit/check-slots.test index 8beb0d8bf3f7..b7ce5e596101 100644 --- a/test-data/unit/check-slots.test +++ b/test-data/unit/check-slots.test @@ -26,7 +26,6 @@ class WithVariable: self.a = 1 self.b = 2 self.c = 3 -[builtins fixtures/tuple.pyi] [builtins fixtures/list.pyi] @@ -332,7 +331,6 @@ b.extra = 'extra' main:22: error: Trying to assign name "c" that is not in "__slots__" of type "__main__.B" main:43: error: Trying to assign name "c" that is not in "__slots__" of type "__main__.B" main:47: error: "B" has no attribute "extra" -[builtins fixtures/tuple.pyi] [builtins fixtures/property.pyi] @@ -363,7 +361,6 @@ a.c = custom_obj a.d = custom_obj a.e = custom_obj [out] -[builtins fixtures/tuple.pyi] [builtins fixtures/dict.pyi] @@ -473,7 +470,6 @@ class A: self.a = 1 self.b = 2 self.missing = 3 -[builtins fixtures/tuple.pyi] [builtins fixtures/list.pyi] @@ -486,7 +482,6 @@ class A: self.a = 1 self.b = 2 self.missing = 3 -[builtins fixtures/tuple.pyi] [builtins fixtures/set.pyi] @@ -499,7 +494,6 @@ class A: self.a = 1 self.b = 2 self.missing = 3 -[builtins fixtures/tuple.pyi] [builtins fixtures/dict.pyi] diff --git a/test-data/unit/check-typevar-values.test b/test-data/unit/check-typevar-values.test index a4a4d68bd9fe..83340c52b63b 100644 --- a/test-data/unit/check-typevar-values.test +++ b/test-data/unit/check-typevar-values.test @@ -660,8 +660,6 @@ T = TypeVar("T", bound=Union[Data, Dict[str, str]]) def f(data: T) -> None: reveal_type(data["x"]) # N: Revealed type is "Union[builtins.int, builtins.str]" - -[builtins fixtures/tuple.pyi] [builtins fixtures/dict.pyi] [case testTypeVarWithTypedDictValueInIndexExpression] @@ -677,7 +675,6 @@ T = TypeVar("T", Data, Dict[str, str]) def f(data: T) -> None: _: Union[str, int] = data["x"] -[builtins fixtures/tuple.pyi] [builtins fixtures/dict.pyi] [case testSelfTypeVarIndexExpr] @@ -699,8 +696,6 @@ class Indexable: def m(self: T) -> T: return self["foo"] - -[builtins fixtures/tuple.pyi] [builtins fixtures/classmethod.pyi] [case testTypeVarWithValueDeferral] diff --git a/test-data/unit/fine-grained-modules.test b/test-data/unit/fine-grained-modules.test index f76ced64341b..9b13d718bbe6 100644 --- a/test-data/unit/fine-grained-modules.test +++ b/test-data/unit/fine-grained-modules.test @@ -1806,7 +1806,7 @@ import b [file b.py] [file c.py] x = 1 -[file b.py] +[file b.py.2] 1+'x' [file c.py.2] x = '2' diff --git a/test-data/unit/fine-grained.test b/test-data/unit/fine-grained.test index 58339828677d..d32ae320ca64 100644 --- a/test-data/unit/fine-grained.test +++ b/test-data/unit/fine-grained.test @@ -989,7 +989,6 @@ import attr class A: a: int other: int -[builtins fixtures/list.pyi] [file a.py.3] import attr