Skip to content

Commit c517b86

Browse files
authored
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.
1 parent c170056 commit c517b86

13 files changed

+12
-36
lines changed

mypy/test/data.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ def parse_test_case(case: DataDrivenTestCase) -> None:
207207
for file_path, contents in files:
208208
expand_errors(contents.split("\n"), output, file_path)
209209

210+
seen_files = set()
211+
for file, _ in files:
212+
if file in seen_files:
213+
raise ValueError(
214+
f"{case.file}, line {first_item.line}: Duplicated filename {file}. Did you include"
215+
" it multiple times?"
216+
)
217+
218+
seen_files.add(file)
219+
210220
case.input = input
211221
case.output = output
212222
case.output2 = output2

test-data/unit/check-attr.test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,8 +1714,6 @@ class C:
17141714
# Note that for this test, the 'Value of type "int" is not indexable' errors are silly,
17151715
# and a consequence of Callable etc. being set to an int in the test stub.
17161716
b = attr.ib(type=Callable[[], C])
1717-
[builtins fixtures/bool.pyi]
1718-
17191717
[file b.py]
17201718
import attr
17211719
import a

test-data/unit/check-enum.test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,6 @@ class Foo(bytes, Enum):
13451345
a = Foo.A
13461346
reveal_type(a.value) # N: Revealed type is "Any"
13471347
reveal_type(a._value_) # N: Revealed type is "Any"
1348-
[builtins fixtures/__new__.pyi]
13491348
[builtins fixtures/primitives.pyi]
13501349
[typing fixtures/typing-medium.pyi]
13511350

@@ -1368,7 +1367,6 @@ class Bar(Foo):
13681367
a = Bar.A
13691368
reveal_type(a.value) # N: Revealed type is "Any"
13701369
reveal_type(a._value_) # N: Revealed type is "Any"
1371-
[builtins fixtures/__new__.pyi]
13721370
[builtins fixtures/primitives.pyi]
13731371
[typing fixtures/typing-medium.pyi]
13741372

test-data/unit/check-functools.test

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Ord() <= 1 # E: Unsupported operand types for <= ("Ord" and "int")
2020
Ord() == 1
2121
Ord() > 1 # E: Unsupported operand types for > ("Ord" and "int")
2222
Ord() >= 1 # E: Unsupported operand types for >= ("Ord" and "int")
23-
[builtins fixtures/ops.pyi]
2423
[builtins fixtures/dict.pyi]
2524

2625
[case testTotalOrderingLambda]
@@ -43,7 +42,6 @@ Ord() <= 1 # E: Unsupported operand types for <= ("Ord" and "int")
4342
Ord() == 1
4443
Ord() > 1 # E: Unsupported operand types for > ("Ord" and "int")
4544
Ord() >= 1 # E: Unsupported operand types for >= ("Ord" and "int")
46-
[builtins fixtures/ops.pyi]
4745
[builtins fixtures/dict.pyi]
4846

4947
[case testTotalOrderingNonCallable]
@@ -59,8 +57,6 @@ class Ord(object):
5957
Ord() <= Ord() # E: Unsupported left operand type for <= ("Ord")
6058
Ord() > Ord() # E: "int" not callable
6159
Ord() >= Ord() # E: Unsupported left operand type for >= ("Ord")
62-
63-
[builtins fixtures/ops.pyi]
6460
[builtins fixtures/dict.pyi]
6561

6662
[case testTotalOrderingReturnNotBool]
@@ -79,8 +75,6 @@ reveal_type(Ord() <= Ord()) # N: Revealed type is "Any"
7975
reveal_type(Ord() == Ord()) # N: Revealed type is "builtins.bool"
8076
reveal_type(Ord() > Ord()) # N: Revealed type is "Any"
8177
reveal_type(Ord() >= Ord()) # N: Revealed type is "Any"
82-
83-
[builtins fixtures/ops.pyi]
8478
[builtins fixtures/dict.pyi]
8579

8680
[case testTotalOrderingAllowsAny]
@@ -105,7 +99,6 @@ Ord() <= 1 # E: Unsupported left operand type for <= ("Ord")
10599
Ord() == 1
106100
Ord() > 1
107101
Ord() >= 1 # E: Unsupported left operand type for >= ("Ord")
108-
[builtins fixtures/ops.pyi]
109102
[builtins fixtures/dict.pyi]
110103

111104
[case testCachedProperty]
@@ -151,5 +144,4 @@ def f(d: D[C]) -> None:
151144
reveal_type(d.__gt__) # N: Revealed type is "def (other: Any) -> builtins.bool"
152145

153146
d: D[int] # E: Type argument "int" of "D" must be a subtype of "C"
154-
[builtins fixtures/ops.pyi]
155147
[builtins fixtures/dict.pyi]

test-data/unit/check-isinstance.test

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,10 +2670,9 @@ if type(x) == int == str:
26702670
else:
26712671
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]"
26722672

2673-
# mypy shows an error about "Unsupported left operand type for !=" if we don't include this
2674-
[builtins fixtures/typing-medium.pyi]
26752673
# mypy thinks int isn't defined unless we include this
26762674
[builtins fixtures/primitives.pyi]
2675+
26772676
[case testTypeNotEqualsCheck]
26782677
from typing import Union
26792678

@@ -2683,8 +2682,6 @@ if type(x) != int:
26832682
else:
26842683
reveal_type(x) # N: Revealed type is "builtins.int"
26852684

2686-
# mypy shows an error about "Unsupported left operand type for !=" if we don't include this
2687-
[builtins fixtures/typing-medium.pyi]
26882685
# mypy thinks int isn't defined unless we include this
26892686
[builtins fixtures/primitives.pyi]
26902687

test-data/unit/check-modules.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3216,7 +3216,6 @@ class Bar(Foo):
32163216
from a import Foo
32173217
class Bar(Foo):
32183218
def frobnicate(self, *args) -> None: pass # type: ignore[override] # I know
3219-
[builtins fixtures/tuple.pyi]
32203219
[builtins fixtures/dict.pyi]
32213220
[out1]
32223221
tmp/b.py:3: error: Signature of "frobnicate" incompatible with supertype "Foo"

test-data/unit/check-parameter-specification.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ def three(**kwargs: int) -> int: ...
539539

540540
@expects_int_first # Accepted
541541
def four(*args: int) -> int: ...
542-
[builtins fixtures/tuple.pyi]
543542
[builtins fixtures/dict.pyi]
544543

545544
[case testParamSpecTwiceSolving]

test-data/unit/check-protocols.test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,7 +2280,6 @@ def func2(arg: Optional[A]) -> None: ...
22802280
x: B
22812281
func1(x)
22822282
func2(x)
2283-
[builtins fixtures/tuple.pyi]
22842283
[builtins fixtures/dict.pyi]
22852284
[out]
22862285
main:14: error: Argument 1 to "func1" has incompatible type "B"; expected "A"
@@ -3191,7 +3190,6 @@ class NoneCompatible3(Protocol):
31913190

31923191
class C(NoneCompatible3): ...
31933192
C() # E: Cannot instantiate abstract class "C" with abstract attributes "f", "g" and "h"
3194-
[builtins fixtures/tuple.pyi]
31953193
[builtins fixtures/classmethod.pyi]
31963194

31973195
[case testEmptyBodyWithFinal]

test-data/unit/check-singledispatch.test

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ def f(arg) -> None:
180180
@f.register
181181
def g(arg: Mapping) -> None:
182182
pass
183-
184-
[builtins fixtures/args.pyi]
185-
[builtins fixtures/list.pyi]
186183
[builtins fixtures/dict.pyi]
187184

188185
[case testIncorrectArgumentsInSingledispatchFunctionDefinition]

test-data/unit/check-slots.test

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class WithVariable:
2626
self.a = 1
2727
self.b = 2
2828
self.c = 3
29-
[builtins fixtures/tuple.pyi]
3029
[builtins fixtures/list.pyi]
3130

3231

@@ -332,7 +331,6 @@ b.extra = 'extra'
332331
main:22: error: Trying to assign name "c" that is not in "__slots__" of type "__main__.B"
333332
main:43: error: Trying to assign name "c" that is not in "__slots__" of type "__main__.B"
334333
main:47: error: "B" has no attribute "extra"
335-
[builtins fixtures/tuple.pyi]
336334
[builtins fixtures/property.pyi]
337335

338336

@@ -363,7 +361,6 @@ a.c = custom_obj
363361
a.d = custom_obj
364362
a.e = custom_obj
365363
[out]
366-
[builtins fixtures/tuple.pyi]
367364
[builtins fixtures/dict.pyi]
368365

369366

@@ -473,7 +470,6 @@ class A:
473470
self.a = 1
474471
self.b = 2
475472
self.missing = 3
476-
[builtins fixtures/tuple.pyi]
477473
[builtins fixtures/list.pyi]
478474

479475

@@ -486,7 +482,6 @@ class A:
486482
self.a = 1
487483
self.b = 2
488484
self.missing = 3
489-
[builtins fixtures/tuple.pyi]
490485
[builtins fixtures/set.pyi]
491486

492487

@@ -499,7 +494,6 @@ class A:
499494
self.a = 1
500495
self.b = 2
501496
self.missing = 3
502-
[builtins fixtures/tuple.pyi]
503497
[builtins fixtures/dict.pyi]
504498

505499

0 commit comments

Comments
 (0)