Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions mypy/test/testcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
'check-semanal-error.test',
'check-flags.test',
'check-incremental.test',
'check-serialize.test',
'check-bound.test',
'check-optional.test',
'check-fastparse.test',
Expand Down Expand Up @@ -90,27 +91,26 @@ def cases(cls) -> List[DataDrivenTestCase]:
return c

def run_case(self, testcase: DataDrivenTestCase) -> None:
incremental = 'incremental' in testcase.name.lower() or 'incremental' in testcase.file
incremental = ('incremental' in testcase.name.lower()
or 'incremental' in testcase.file
or 'serialize' in testcase.file)
optional = 'optional' in testcase.file
if incremental:
# Incremental tests are run once with a cold cache, once with a warm cache.
# Expect success on first run, errors from testcase.output (if any) on second run.
# We briefly sleep to make sure file timestamps are distinct.
self.clear_cache()
self.run_case_once(testcase, 1)
self.run_case_once(testcase, 2)
elif optional:
try:
old_strict_optional = experiments.STRICT_OPTIONAL
try:
if incremental:
# Incremental tests are run once with a cold cache, once with a warm cache.
# Expect success on first run, errors from testcase.output (if any) on second run.
# We briefly sleep to make sure file timestamps are distinct.
self.clear_cache()
self.run_case_once(testcase, 1)
self.run_case_once(testcase, 2)
elif optional:
experiments.STRICT_OPTIONAL = True
self.run_case_once(testcase)
finally:
experiments.STRICT_OPTIONAL = False
else:
try:
old_strict_optional = experiments.STRICT_OPTIONAL
else:
self.run_case_once(testcase)
finally:
experiments.STRICT_OPTIONAL = old_strict_optional
finally:
experiments.STRICT_OPTIONAL = old_strict_optional

def clear_cache(self) -> None:
dn = defaults.CACHE_DIR
Expand Down
47 changes: 2 additions & 45 deletions test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
-- all cases so we can avoid constantly having to annotate it. The list of
-- rechecked/stale files can be in any arbitrary order, or can be left empty
-- if no files should be rechecked/stale.
--
-- There are additional incremental mode test cases in check-serialize.test.

[case testIncrementalEmpty]
[rechecked]
Expand Down Expand Up @@ -1711,28 +1713,6 @@ main:1: error: Module 'ntcrash' has no attribute 'nope'
[out2]
main:1: error: Module 'ntcrash' has no attribute 'nope'

[case testIncrementalNamedTupleInMethod4]
from ntcrash import C
reveal_type(C().a)
reveal_type(C().b)
reveal_type(C().c)
[file ntcrash.py]
from typing import NamedTuple
class C:
def __init__(self) -> None:
A = NamedTuple('A', [('x', int)])
self.a = A(0)
self.b = A(0) # type: A
self.c = A
[out1]
main:2: error: Revealed type is 'Tuple[builtins.int, fallback=ntcrash.C.A@4]'
main:3: error: Revealed type is 'Tuple[builtins.int, fallback=ntcrash.C.A@4]'
main:4: error: Revealed type is 'def (x: builtins.int) -> Tuple[builtins.int, fallback=ntcrash.C.A@4]'
[out2]
main:2: error: Revealed type is 'Tuple[builtins.int, fallback=ntcrash.C.A@4]'
main:3: error: Revealed type is 'Tuple[builtins.int, fallback=ntcrash.C.A@4]'
main:4: error: Revealed type is 'def (x: builtins.int) -> Tuple[builtins.int, fallback=ntcrash.C.A@4]'

[case testIncrementalTypedDictInMethod]
from tdcrash import nope
[file tdcrash.py]
Expand Down Expand Up @@ -1775,29 +1755,6 @@ main:1: error: Module 'tdcrash' has no attribute 'nope'
[out2]
main:1: error: Module 'tdcrash' has no attribute 'nope'

[case testIncrementalTypedDictInMethod4]
from ntcrash import C
reveal_type(C().a)
reveal_type(C().b)
reveal_type(C().c)
[file ntcrash.py]
from mypy_extensions import TypedDict
class C:
def __init__(self) -> None:
A = TypedDict('A', {'x': int})
self.a = A(x=0)
self.b = A(x=0) # type: A
self.c = A
[builtins fixtures/dict.pyi]
[out1]
main:2: error: Revealed type is 'TypedDict(x=builtins.int, _fallback=typing.Mapping[builtins.str, builtins.int])'
main:3: error: Revealed type is 'TypedDict(x=builtins.int, _fallback=ntcrash.C.A@4)'
main:4: error: Revealed type is 'def () -> ntcrash.C.A@4'
[out2]
main:2: error: Revealed type is 'TypedDict(x=builtins.int, _fallback=typing.Mapping[builtins.str, builtins.int])'
main:3: error: Revealed type is 'TypedDict(x=builtins.int, _fallback=ntcrash.C.A@4)'
main:4: error: Revealed type is 'def () -> ntcrash.C.A@4'

[case testIncrementalInnerClassAttrInMethod]
import crash
nonexisting
Expand Down
Loading