Skip to content

Move testparse to pytest #3780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 1, 2017
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
3 changes: 3 additions & 0 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,9 @@ def repr_failure(self, excinfo: Any) -> str:


class DataSuite:
def __init__(self, *, update_data: bool) -> None:
self.update_data = update_data

@classmethod
def cases(cls) -> List[DataDrivenTestCase]:
return []
Expand Down
2 changes: 0 additions & 2 deletions mypy/test/testcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
2 changes: 0 additions & 2 deletions mypy/test/testdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@


class GetDependenciesSuite(DataSuite):
def __init__(self, *, update_data: bool) -> None:
pass

@classmethod
def cases(cls) -> List[DataDrivenTestCase]:
Expand Down
2 changes: 0 additions & 2 deletions mypy/test/testdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@


class ASTDiffSuite(DataSuite):
def __init__(self, *, update_data: bool) -> None:
pass

@classmethod
def cases(cls) -> List[DataDrivenTestCase]:
Expand Down
3 changes: 0 additions & 3 deletions mypy/test/testfinegrained.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@


class FineGrainedSuite(DataSuite):
def __init__(self, *, update_data: bool) -> None:
pass

Copy link
Contributor Author

@elazarg elazarg Aug 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or did you want here a call to super().__init__?

@classmethod
def cases(cls) -> List[DataDrivenTestCase]:
c = [] # type: List[DataDrivenTestCase]
Expand Down
1 change: 1 addition & 0 deletions mypy/test/testmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions mypy/test/testparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it actually matter whether this is a class method or an instance method? (I don't know -- can you tell me?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's called without an instance (line 515 in data.py, obj is the class itself); it could have been a static method. Better yet, it could not exist at all, since the needed information here is only the file names and 2-3 options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now it has to be a classmethod since it's this is how it's declared in DataSuite.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I think I realize what confused me. There's a class Suite with a cases() instance method, and a class DataSuite with a cases()` class method. The two are not directly related (though I suspect that some duck typing may still be going on). Anyway, no need to change this back. :-)

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.
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def add_imports(driver: Driver) -> None:
'testdiff',
'testfinegrained',
'testmerge',
'testparse',
]]


Expand Down