Debian Codegraph @

test-data/unit/fine-grained-blockers.test

raw
1 -- Test cases for fine-grained incremental mode and blocking errors
2 --
3 -- The comments in fine-grained.test explain how these tests work.
4
5 -- TODO:
6 -- - blocking error while other existing errors as well (that get preserved)
7 -- - differences in other modules + blocking error
8
9 [case testParseError]
10 import a
11 a.f()
12 [file a.py]
13 def f() -> None: pass
14 [file a.py.2]
15 def f(x: int) ->
16 [file a.py.3]
17 def f(x: int) -> None: pass
18 [file a.py.4]
19 def f() -> None: pass
20 [out]
21 ==
22 a.py:1: error: Expected ':'
23 ==
24 main:2: error: Missing positional argument "x" in call to "f"
25 ==
26
27 [case testParseErrorShowSource]
28 # flags: --pretty --show-error-codes
29 import a
30 a.f()
31 [file a.py]
32 def f() -> None: pass
33 [file a.py.2]
34 def f(x: int) ->
35 [file a.py.3]
36 def f(x: int) -> None: pass
37 [file a.py.4]
38 def f() -> None: pass
39 [out]
40 ==
41 a.py:1: error: Expected ':' [syntax]
42 def f(x: int) ->
43 ^
44 ==
45 main:3: error: Missing positional argument "x" in call to "f" [call-arg]
46 a.f()
47 ^~~~~
48 ==
49
50 [case testParseErrorMultipleTimes]
51 import a
52 a.f()
53 [file a.py]
54 def f() -> None: pass
55 [file a.py.2]
56 def f(x: int) ->
57 [file a.py.3]
58 def f(x: int
59 ) -> None
60 [file a.py.4]
61 def f(x: int) -> None: pass
62 [out]
63 ==
64 a.py:1: error: Expected ':'
65 ==
66 a.py:2: error: Expected ':'
67 ==
68 main:2: error: Missing positional argument "x" in call to "f"
69
70 [case testSemanticAnalysisBlockingError]
71 import a
72 a.f()
73 [file a.py]
74 def f() -> None: pass
75 [file a.py.2]
76 def f() -> None: pass
77 break
78 [file a.py.3]
79 def f(x: int) -> None: pass
80 [out]
81 ==
82 a.py:2: error: "break" outside loop
83 ==
84 main:2: error: Missing positional argument "x" in call to "f"
85
86 [case testBlockingErrorWithPreviousError]
87 import a
88 import b
89 a.f(1)
90 def g() -> None:
91 b.f(1)
92 [file a.py]
93 def f() -> None: pass
94 [file b.py]
95 def f() -> None: pass
96 [file a.py.2]
97 def f() -> None
98 [file a.py.3]
99 def f() -> None: pass
100 [out]
101 main:3: error: Too many arguments for "f"
102 main:5: error: Too many arguments for "f"
103 ==
104 a.py:1: error: Expected ':'
105 ==
106 main:3: error: Too many arguments for "f"
107 main:5: error: Too many arguments for "f"
108
109 [case testUpdateClassReferenceAcrossBlockingError]
110 import a
111 c: a.C
112
113 def f() -> None:
114 c.f()
115 [file a.py]
116 class C:
117 def f(self) -> None: pass
118 [file a.py.2]
119 error error
120 [file a.py.3]
121 class C:
122 def f(self, x: int) -> None: pass
123 [out]
124 ==
125 a.py:1: error: Invalid syntax
126 ==
127 main:5: error: Missing positional argument "x" in call to "f" of "C"
128 [out version==3.10.0]
129 ==
130 a.py:1: error: Invalid syntax. Perhaps you forgot a comma?
131 ==
132 main:5: error: Missing positional argument "x" in call to "f" of "C"
133
134 [case testAddFileWithBlockingError]
135 import a
136 a.f(1)
137 [file a.py.2]
138 x x
139 [file a.py.3]
140 def f() -> None: pass
141 [out]
142 main:1: error: Cannot find implementation or library stub for module named "a"
143 main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
144 ==
145 a.py:1: error: Invalid syntax
146 ==
147 main:2: error: Too many arguments for "f"
148 [out version==3.10.0]
149 main:1: error: Cannot find implementation or library stub for module named "a"
150 main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
151 ==
152 a.py:1: error: Invalid syntax. Perhaps you forgot a comma?
153 ==
154 main:2: error: Too many arguments for "f"
155
156 [case testModifyTwoFilesOneWithBlockingError1]
157 import a
158 [file a.py]
159 import b
160 def f() -> None: pass
161 b.g()
162 [file b.py]
163 import a
164 a.f()
165 def g() -> None: pass
166 [file a.py.2]
167 import b # Dummy edit
168 def f() -> None: pass
169 b.g()
170 [file b.py.2]
171 import a a # Syntax error
172 a.f()
173 def g() -> None: pass
174 [file b.py.3]
175 import a
176 a.f()
177 def g() -> None: pass
178 [out]
179 ==
180 b.py:1: error: Invalid syntax
181 ==
182
183 [case testModifyTwoFilesOneWithBlockingError2]
184 import a
185 [file a.py]
186 import b
187 def f() -> None: pass
188 b.g()
189 [file b.py]
190 import a
191 a.f()
192 def g() -> None: pass
193 [file a.py.2]
194 import b b
195 def f() -> None: pass
196 b.g()
197 [file b.py.2]
198 import a # Dummy edit
199 a.f()
200 def g() -> None: pass
201 [file a.py.3]
202 import b
203 def f() -> None: pass
204 b.g()
205 [out]
206 ==
207 a.py:1: error: Invalid syntax
208 ==
209
210 [case testBlockingErrorRemainsUnfixed]
211 import a
212 [file a.py]
213 import b
214 b.f()
215 [file b.py]
216 def f() -> None: pass
217 [file a.py.2]
218 x x
219 [file b.py.3]
220 def f(x: int) -> None: pass
221 [file a.py.4]
222 import b
223 b.f()
224 [out]
225 ==
226 a.py:1: error: Invalid syntax
227 ==
228 a.py:1: error: Invalid syntax
229 ==
230 a.py:2: error: Missing positional argument "x" in call to "f"
231 [out version==3.10.0]
232 ==
233 a.py:1: error: Invalid syntax. Perhaps you forgot a comma?
234 ==
235 a.py:1: error: Invalid syntax. Perhaps you forgot a comma?
236 ==
237 a.py:2: error: Missing positional argument "x" in call to "f"
238
239 [case testModifyTwoFilesIntroduceTwoBlockingErrors]
240 import a
241 [file a.py]
242 import b
243 def f() -> None: pass
244 b.g()
245 [file b.py]
246 import a
247 a.f()
248 def g() -> None: pass
249 [file a.py.2]
250 import b b
251 def f() -> None: pass
252 b.g()
253 [file b.py.2]
254 import a a
255 a.f()
256 def g() -> None: pass
257 [file a.py.3]
258 import b b
259 def f() -> None: pass
260 b.g()
261 [file b.py.3]
262 import a a
263 a.f()
264 def g() -> None: pass
265 [file a.py.4]
266 import b
267 def f() -> None: pass
268 b.g(1)
269 [file b.py.4]
270 import a
271 def g() -> None: pass
272 a.f(1)
273 [out]
274 ==
275 a.py:1: error: Invalid syntax
276 ==
277 a.py:1: error: Invalid syntax
278 ==
279 a.py:3: error: Too many arguments for "g"
280 b.py:3: error: Too many arguments for "f"
281
282 [case testDeleteFileWithBlockingError-only_when_nocache]
283 -- Different cache/no-cache tests because:
284 -- Error message ordering differs
285 import a
286 import b
287 [file a.py]
288 def f() -> None: pass
289 [file b.py]
290 import a
291 a.f()
292 [file a.py.2]
293 x x
294 [delete a.py.3]
295 [out]
296 ==
297 a.py:1: error: Invalid syntax
298 ==
299 main:1: error: Cannot find implementation or library stub for module named "a"
300 main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
301 b.py:1: error: Cannot find implementation or library stub for module named "a"
302 [out version==3.10.0]
303 ==
304 a.py:1: error: Invalid syntax. Perhaps you forgot a comma?
305 ==
306 main:1: error: Cannot find implementation or library stub for module named "a"
307 main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
308 b.py:1: error: Cannot find implementation or library stub for module named "a"
309
310 [case testDeleteFileWithBlockingError2-only_when_cache]
311 -- Different cache/no-cache tests because:
312 -- Error message ordering differs
313 import a
314 import b
315 [file a.py]
316 def f() -> None: pass
317 [file b.py]
318 import a
319 a.f()
320 [file a.py.2]
321 x x
322 [delete a.py.3]
323 [out]
324 ==
325 a.py:1: error: Invalid syntax
326 ==
327 b.py:1: error: Cannot find implementation or library stub for module named "a"
328 b.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
329 main:1: error: Cannot find implementation or library stub for module named "a"
330 [out version==3.10.0]
331 ==
332 a.py:1: error: Invalid syntax. Perhaps you forgot a comma?
333 ==
334 b.py:1: error: Cannot find implementation or library stub for module named "a"
335 b.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
336 main:1: error: Cannot find implementation or library stub for module named "a"
337
338 [case testModifyFileWhileBlockingErrorElsewhere]
339 import a
340 import b
341 [file a.py]
342 [file b.py]
343 import a
344 [file a.py.2]
345 x x
346 [file b.py.3]
347 import a
348 a.f()
349 1()
350 [file a.py.4]
351 [builtins fixtures/module.pyi]
352 [out]
353 ==
354 a.py:1: error: Invalid syntax
355 ==
356 a.py:1: error: Invalid syntax
357 ==
358 b.py:2: error: Module has no attribute "f"
359 b.py:3: error: "int" not callable
360 [out version==3.10.0]
361 ==
362 a.py:1: error: Invalid syntax. Perhaps you forgot a comma?
363 ==
364 a.py:1: error: Invalid syntax. Perhaps you forgot a comma?
365 ==
366 b.py:2: error: Module has no attribute "f"
367 b.py:3: error: "int" not callable
368
369 [case testImportBringsAnotherFileWithBlockingError1]
370 import a
371 [file a.py]
372 [file a.py.2]
373 import blocker
374 1()
375 [file a.py.3]
376 1()
377 def f() -> None: pass
378 [out]
379 ==
380 <ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: Invalid syntax
381 ==
382 a.py:1: error: "int" not callable
383 [out version==3.10.0]
384 ==
385 <ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: Invalid syntax. Perhaps you forgot a comma?
386 ==
387 a.py:1: error: "int" not callable
388
389 [case testImportBringsAnotherFileWithSemanticAnalysisBlockingError]
390 import a
391 [file a.py]
392 [file a.py.2]
393 import blocker2
394 1()
395 [file a.py.3]
396 1()
397 [out]
398 ==
399 <ROOT>/test-data/unit/lib-stub/blocker2.pyi:2: error: "continue" outside loop
400 ==
401 a.py:1: error: "int" not callable
402
403 [case testFixingBlockingErrorTriggersDeletion1-only_when_nocache]
404 -- Disabled in cache mdode:
405 -- Cache mode fails to produce the error in the final step, but this is
406 -- a manifestation of a bug that can occur in no-cache mode also.
407 import a
408
409 def g(x: a.A) -> None:
410 x.f()
411 [file a.py]
412 class A:
413 def f(self) -> None: pass
414 [delete a.py.2]
415 [file a.py.3]
416 class A: pass
417 [builtins fixtures/module.pyi]
418 [out]
419 ==
420 main:1: error: Cannot find implementation or library stub for module named "a"
421 main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
422 ==
423 main:4: error: "A" has no attribute "f"
424
425 [case testFixingBlockingErrorTriggersDeletion2]
426 from a import A
427
428 def g(x: A) -> None:
429 x.f()
430 [file a.py]
431 class A:
432 def f(self) -> None: pass
433 [delete a.py.2]
434 [file a.py.3]
435 [builtins fixtures/module.pyi]
436 [out]
437 ==
438 main:1: error: Cannot find implementation or library stub for module named "a"
439 main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
440 ==
441 main:1: error: Module "a" has no attribute "A"
442
443 [case testFixingBlockingErrorBringsInAnotherModuleWithBlocker]
444 import a
445 [file a.py]
446 [file a.py.2]
447 x y
448 [file a.py.3]
449 import blocker
450 1()
451 [file a.py.4]
452 import sys
453 1()
454 [builtins fixtures/tuple.pyi]
455 [out]
456 ==
457 a.py:1: error: Invalid syntax
458 ==
459 <ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: Invalid syntax
460 ==
461 a.py:2: error: "int" not callable
462 [out version==3.10.0]
463 ==
464 a.py:1: error: Invalid syntax. Perhaps you forgot a comma?
465 ==
466 <ROOT>/test-data/unit/lib-stub/blocker.pyi:2: error: Invalid syntax. Perhaps you forgot a comma?
467 ==
468 a.py:2: error: "int" not callable
469
470 [case testInitialBlocker]
471 # cmd: mypy a.py b.py
472 [file a.py]
473 1 1
474 [file b.py]
475 def f() -> int:
476 return ''
477 [file a.py.2]
478 x = 1
479 [file b.py.3]
480 def f() -> int:
481 return 0
482 [out]
483 a.py:1: error: Invalid syntax
484 ==
485 b.py:2: error: Incompatible return value type (got "str", expected "int")
486 ==
487 [out version==3.10.0]
488 a.py:1: error: Invalid syntax. Perhaps you forgot a comma?
489 ==
490 b.py:2: error: Incompatible return value type (got "str", expected "int")
491 ==
492
493 [case testDecodeErrorBlocker1-posix]
494 import a
495 a.f(1)
496 [file a.py]
497 def f(x: int) -> None: ...
498 [file a.py.2]
499 # coding: ascii
500 ä = 1
501 [file a.py.3]
502 def f(x: str) -> None: ...
503 [out]
504 ==
505 a.py: error: Cannot decode file: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128)
506 ==
507 main:2: error: Argument 1 to "f" has incompatible type "int"; expected "str"
508
509 [case testDecodeErrorBlocker2-windows]
510 import a
511 a.f(1)
512 [file a.py]
513 def f(x: int) -> None: ...
514 [file a.py.2]
515 # coding: ascii
516 ä = 1
517 [file a.py.3]
518 def f(x: str) -> None: ...
519 [out]
520 ==
521 a.py: error: Cannot decode file: 'ascii' codec can't decode byte 0xc3 in position 17: ordinal not in range(128)
522 ==
523 main:2: error: Argument 1 to "f" has incompatible type "int"; expected "str"
524
525 [case testDecodeErrorBlockerOnInitialRun-posix]
526 # Note that there's no test variant for Windows, since the above Windows test case is good enough.
527 import a
528 a.f(1)
529 [file a.py]
530 # coding: ascii
531 ä = 1
532 [file a.py.2]
533 def f(x: str) -> None: ...
534 [out]
535 a.py: error: Cannot decode file: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128)
536 ==
537 main:3: error: Argument 1 to "f" has incompatible type "int"; expected "str"