-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
177 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import subprocess | ||
import textwrap | ||
from os.path import basename | ||
from tempfile import NamedTemporaryFile | ||
|
||
from mypy.test.config import test_data_prefix | ||
from mypy.test.helpers import Suite | ||
|
||
|
||
class UpdateDataSuite(Suite): | ||
def _update_test(self, testcase: str) -> str: | ||
with NamedTemporaryFile( | ||
mode="w+", dir=test_data_prefix, prefix="check-update-data-", suffix=".test" | ||
) as tmp_file: | ||
tmp_file.write(textwrap.dedent(testcase)) | ||
tmp_file.flush() | ||
test_nodeid = f"mypy/test/testcheck.py::TypeCheckSuite::{basename(tmp_file.name)}" | ||
res = subprocess.run( | ||
["pytest", "-n", "0", "-s", "--update-data", test_nodeid], capture_output=True | ||
) | ||
assert res.returncode == 1 | ||
tmp_file.seek(0) | ||
return tmp_file.read() | ||
|
||
def test_update_data(self) -> None: | ||
actual = self._update_test( | ||
""" | ||
[case testCorrect] | ||
s: str = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "str") | ||
[case testWrong] | ||
s: str = 42 # E: wrong error | ||
[case testMissingMultiline] | ||
s: str = 42; i: int = 'foo' | ||
[case testExtraneous] | ||
s: str = 'foo' # E: wrong error | ||
[case testExtraneousMultiline] | ||
s: str = 'foo' # E: foo \ | ||
# E: bar | ||
[case testExtraneousMultilineNonError] | ||
s: str = 'foo' # W: foo \ | ||
# N: bar | ||
[case testWrongMultipleFiles] | ||
import a, b | ||
s: str = 42 # E: foo | ||
[file a.py] | ||
s1: str = 42 # E: bar | ||
[file b.py] | ||
s2: str = 43 # E: baz | ||
[out] | ||
make sure we're not touching this | ||
[builtins fixtures/list.pyi] | ||
""" | ||
) | ||
|
||
# Assert | ||
assert actual == textwrap.dedent( | ||
""" | ||
[case testCorrect] | ||
s: str = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "str") | ||
[case testWrong] | ||
s: str = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "str") | ||
[case testMissingMultiline] | ||
s: str = 42; i: int = 'foo' # E: Incompatible types in assignment (expression has type "int", variable has type "str") \\ | ||
# E: Incompatible types in assignment (expression has type "str", variable has type "int") | ||
[case testExtraneous] | ||
s: str = 'foo' | ||
[case testExtraneousMultiline] | ||
s: str = 'foo' | ||
[case testExtraneousMultilineNonError] | ||
s: str = 'foo' | ||
[case testWrongMultipleFiles] | ||
import a, b | ||
s: str = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "str") | ||
[file a.py] | ||
s1: str = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "str") | ||
[file b.py] | ||
s2: str = 43 # E: Incompatible types in assignment (expression has type "int", variable has type "str") | ||
[out] | ||
make sure we're not touching this | ||
[builtins fixtures/list.pyi] | ||
""" | ||
) |