Skip to content

Commit

Permalink
Check for duplicated files in tests (#14960)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
A5rocks committed Mar 26, 2023
1 parent c170056 commit c517b86
Show file tree
Hide file tree
Showing 13 changed files with 12 additions and 36 deletions.
10 changes: 10 additions & 0 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions test-data/unit/check-attr.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions test-data/unit/check-enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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]

Expand Down
8 changes: 0 additions & 8 deletions test-data/unit/check-functools.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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]
5 changes: 1 addition & 4 deletions test-data/unit/check-isinstance.test
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]

Expand Down
1 change: 0 additions & 1 deletion test-data/unit/check-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 0 additions & 2 deletions test-data/unit/check-protocols.test
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 0 additions & 3 deletions test-data/unit/check-singledispatch.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 0 additions & 6 deletions test-data/unit/check-slots.test
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class WithVariable:
self.a = 1
self.b = 2
self.c = 3
[builtins fixtures/tuple.pyi]
[builtins fixtures/list.pyi]


Expand Down Expand Up @@ -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]


Expand Down Expand Up @@ -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]


Expand Down Expand Up @@ -473,7 +470,6 @@ class A:
self.a = 1
self.b = 2
self.missing = 3
[builtins fixtures/tuple.pyi]
[builtins fixtures/list.pyi]


Expand All @@ -486,7 +482,6 @@ class A:
self.a = 1
self.b = 2
self.missing = 3
[builtins fixtures/tuple.pyi]
[builtins fixtures/set.pyi]


Expand All @@ -499,7 +494,6 @@ class A:
self.a = 1
self.b = 2
self.missing = 3
[builtins fixtures/tuple.pyi]
[builtins fixtures/dict.pyi]


Expand Down
5 changes: 0 additions & 5 deletions test-data/unit/check-typevar-values.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -699,8 +696,6 @@ class Indexable:

def m(self: T) -> T:
return self["foo"]

[builtins fixtures/tuple.pyi]
[builtins fixtures/classmethod.pyi]

[case testTypeVarWithValueDeferral]
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/fine-grained-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 0 additions & 1 deletion test-data/unit/fine-grained.test
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,6 @@ import attr
class A:
a: int
other: int
[builtins fixtures/list.pyi]

[file a.py.3]
import attr
Expand Down

0 comments on commit c517b86

Please sign in to comment.