-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Move testparse to pytest #3780
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I think I realize what confused me. There's a class |
||
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: | ||
|
There was a problem hiding this comment.
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__
?