| 1 |
-- Test cases for reporting errors when a test case uses a fixture with |
| 2 |
-- missing definitions. At least in the most common cases this should not |
| 3 |
-- result in an uncaught exception. These tests make sure that this behavior |
| 4 |
-- does not regress. |
| 5 |
-- |
| 6 |
-- NOTE: These tests do NOT test behavior of mypy outside tests. |
| 7 |
|
| 8 |
[case testVariableUndefinedUsingDefaultFixture] |
| 9 |
import m |
| 10 |
# This used to cause a crash since types.ModuleType is not available |
| 11 |
# by default. We fall back to 'object' now. |
| 12 |
m.x # E: "object" has no attribute "x" |
| 13 |
[file m.py] |
| 14 |
|
| 15 |
[case testSetMissingFromStubs] |
| 16 |
from typing import Set |
| 17 |
def f(x: Set[int]) -> None: pass |
| 18 |
[out] |
| 19 |
main:1: error: Module "typing" has no attribute "Set" |
| 20 |
main:1: note: Maybe your test fixture does not define "builtins.set"? |
| 21 |
main:1: note: Consider adding [builtins fixtures/set.pyi] to your test description |
| 22 |
|
| 23 |
[case testBaseExceptionMissingFromStubs] |
| 24 |
e: BaseException |
| 25 |
[out] |
| 26 |
main:1: error: Name "BaseException" is not defined |
| 27 |
main:1: note: Maybe your test fixture does not define "builtins.BaseException"? |
| 28 |
main:1: note: Consider adding [builtins fixtures/exception.pyi] to your test description |
| 29 |
|
| 30 |
[case testExceptionMissingFromStubs] |
| 31 |
e: Exception |
| 32 |
[out] |
| 33 |
main:1: error: Name "Exception" is not defined |
| 34 |
main:1: note: Maybe your test fixture does not define "builtins.Exception"? |
| 35 |
main:1: note: Consider adding [builtins fixtures/exception.pyi] to your test description |
| 36 |
|
| 37 |
[case testIsinstanceMissingFromStubs] |
| 38 |
if isinstance(1, int): |
| 39 |
pass |
| 40 |
[out] |
| 41 |
main:1: error: Name "isinstance" is not defined |
| 42 |
main:1: note: Maybe your test fixture does not define "builtins.isinstance"? |
| 43 |
main:1: note: Consider adding [builtins fixtures/isinstancelist.pyi] to your test description |
| 44 |
|
| 45 |
[case testTupleMissingFromStubs1] |
| 46 |
tuple() |
| 47 |
[out] |
| 48 |
main:1: error: Name "tuple" is not defined |
| 49 |
main:1: note: Maybe your test fixture does not define "builtins.tuple"? |
| 50 |
main:1: note: Consider adding [builtins fixtures/tuple.pyi] to your test description |
| 51 |
main:1: note: Did you forget to import it from "typing"? (Suggestion: "from typing import Tuple") |
| 52 |
|
| 53 |
[case testTupleMissingFromStubs2] |
| 54 |
tuple() |
| 55 |
from typing import Tuple |
| 56 |
x: Tuple[int, str] |
| 57 |
[out] |
| 58 |
main:1: error: Name "tuple" is not defined |
| 59 |
main:1: note: Maybe your test fixture does not define "builtins.tuple"? |
| 60 |
main:1: note: Consider adding [builtins fixtures/tuple.pyi] to your test description |
| 61 |
main:1: note: Did you forget to import it from "typing"? (Suggestion: "from typing import Tuple") |
| 62 |
main:3: error: Name "tuple" is not defined |
| 63 |
|
| 64 |
[case testClassmethodMissingFromStubs] |
| 65 |
class A: |
| 66 |
@classmethod |
| 67 |
def f(cls): pass |
| 68 |
[out] |
| 69 |
main:2: error: Name "classmethod" is not defined |
| 70 |
main:2: note: Maybe your test fixture does not define "builtins.classmethod"? |
| 71 |
main:2: note: Consider adding [builtins fixtures/classmethod.pyi] to your test description |
| 72 |
|
| 73 |
[case testPropertyMissingFromStubs] |
| 74 |
class A: |
| 75 |
@property |
| 76 |
def f(self): pass |
| 77 |
[out] |
| 78 |
main:2: error: Name "property" is not defined |
| 79 |
main:2: note: Maybe your test fixture does not define "builtins.property"? |
| 80 |
main:2: note: Consider adding [builtins fixtures/property.pyi] to your test description |