From 850f6e8d016cd65e72f10f6f430bfdcf4debcac8 Mon Sep 17 00:00:00 2001 From: elazar Date: Mon, 31 Jul 2017 01:11:21 +0300 Subject: [PATCH 1/2] move testparse to pytest --- mypy/test/data.py | 3 +++ mypy/test/testparse.py | 20 ++++++++++++++------ runtests.py | 1 + 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/mypy/test/data.py b/mypy/test/data.py index 11a890ef8450..b15dcd95171f 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -556,6 +556,9 @@ def repr_failure(self, excinfo: Any) -> str: class DataSuite: + def __init__(self, *, update_data: bool = False) -> None: + self.update_data = update_data + @classmethod def cases(cls) -> List[DataDrivenTestCase]: return [] diff --git a/mypy/test/testparse.py b/mypy/test/testparse.py index d6789c034a84..ef9632a34372 100644 --- a/mypy/test/testparse.py +++ b/mypy/test/testparse.py @@ -7,25 +7,29 @@ from mypy import defaults from mypy.myunit import Suite, AssertionFailure from mypy.test.helpers import assert_string_arrays_equal -from mypy.test.data import parse_test_cases, DataDrivenTestCase +from mypy.test.data import parse_test_cases, DataDrivenTestCase, DataSuite from mypy.test import config from mypy.parse import parse from mypy.errors import CompileError from mypy.options import Options -class ParserSuite(Suite): +class ParserSuite(DataSuite): parse_files = ['parse.test', 'parse-python2.test'] - def cases(self) -> List[DataDrivenTestCase]: + @classmethod + def cases(cls) -> List[DataDrivenTestCase]: # The test case descriptions are stored in data files. c = [] # type: List[DataDrivenTestCase] - for f in self.parse_files: + for f in cls.parse_files: c += parse_test_cases( os.path.join(config.test_data_prefix, f), test_parser) return c + def run_case(self, testcase: DataDrivenTestCase) -> None: + test_parser(testcase) + def test_parser(testcase: DataDrivenTestCase) -> None: """Perform a single parser test case. @@ -57,13 +61,17 @@ def test_parser(testcase: DataDrivenTestCase) -> None: INPUT_FILE_NAME = 'file' -class ParseErrorSuite(Suite): - def cases(self) -> List[DataDrivenTestCase]: +class ParseErrorSuite(DataSuite): + @classmethod + def cases(cls) -> List[DataDrivenTestCase]: # Test case descriptions are in an external file. return parse_test_cases(os.path.join(config.test_data_prefix, 'parse-errors.test'), test_parse_error) + def run_case(self, testcase: DataDrivenTestCase) -> None: + test_parse_error(testcase) + def test_parse_error(testcase: DataDrivenTestCase) -> None: try: diff --git a/runtests.py b/runtests.py index e10850ef76ce..fdb824fd7864 100755 --- a/runtests.py +++ b/runtests.py @@ -204,6 +204,7 @@ def add_imports(driver: Driver) -> None: 'testdiff', 'testfinegrained', 'testmerge', + 'testparse', ]] From 248bc53889c88a189891d57c4d32baafdb8025e0 Mon Sep 17 00:00:00 2001 From: elazar Date: Tue, 1 Aug 2017 21:31:15 +0300 Subject: [PATCH 2/2] always initialize update_data --- mypy/test/data.py | 2 +- mypy/test/testcheck.py | 2 -- mypy/test/testdeps.py | 2 -- mypy/test/testdiff.py | 2 -- mypy/test/testfinegrained.py | 3 --- mypy/test/testmerge.py | 1 + 6 files changed, 2 insertions(+), 10 deletions(-) diff --git a/mypy/test/data.py b/mypy/test/data.py index b15dcd95171f..a9ae1fde37bd 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -556,7 +556,7 @@ def repr_failure(self, excinfo: Any) -> str: class DataSuite: - def __init__(self, *, update_data: bool = False) -> None: + def __init__(self, *, update_data: bool) -> None: self.update_data = update_data @classmethod diff --git a/mypy/test/testcheck.py b/mypy/test/testcheck.py index 3aae19f1b40f..4ac59bd94f57 100644 --- a/mypy/test/testcheck.py +++ b/mypy/test/testcheck.py @@ -82,8 +82,6 @@ class TypeCheckSuite(DataSuite): - def __init__(self, *, update_data: bool = False) -> None: - self.update_data = update_data @classmethod def cases(cls) -> List[DataDrivenTestCase]: diff --git a/mypy/test/testdeps.py b/mypy/test/testdeps.py index a648782428a1..d6580c40d65b 100644 --- a/mypy/test/testdeps.py +++ b/mypy/test/testdeps.py @@ -20,8 +20,6 @@ class GetDependenciesSuite(DataSuite): - def __init__(self, *, update_data: bool) -> None: - pass @classmethod def cases(cls) -> List[DataDrivenTestCase]: diff --git a/mypy/test/testdiff.py b/mypy/test/testdiff.py index 84e5389ba4a2..3f9d2345e787 100644 --- a/mypy/test/testdiff.py +++ b/mypy/test/testdiff.py @@ -20,8 +20,6 @@ class ASTDiffSuite(DataSuite): - def __init__(self, *, update_data: bool) -> None: - pass @classmethod def cases(cls) -> List[DataDrivenTestCase]: diff --git a/mypy/test/testfinegrained.py b/mypy/test/testfinegrained.py index fff2e18d26ba..7e442d545566 100644 --- a/mypy/test/testfinegrained.py +++ b/mypy/test/testfinegrained.py @@ -35,9 +35,6 @@ class FineGrainedSuite(DataSuite): - def __init__(self, *, update_data: bool) -> None: - pass - @classmethod def cases(cls) -> List[DataDrivenTestCase]: c = [] # type: List[DataDrivenTestCase] diff --git a/mypy/test/testmerge.py b/mypy/test/testmerge.py index ec437bb45e3a..4694865d284a 100644 --- a/mypy/test/testmerge.py +++ b/mypy/test/testmerge.py @@ -37,6 +37,7 @@ class ASTMergeSuite(DataSuite): def __init__(self, *, update_data: bool) -> None: + super().__init__(update_data=update_data) self.str_conv = StrConv(show_ids=True) assert self.str_conv.id_mapper is not None self.id_mapper = self.str_conv.id_mapper # type: IdMapper