forked from platformio/platformio-core
Improve doctest results parser
This commit is contained in:
@ -24,14 +24,10 @@ class DoctestTestCaseParser:
|
|||||||
self._name_tokens = []
|
self._name_tokens = []
|
||||||
|
|
||||||
def parse(self, line):
|
def parse(self, line):
|
||||||
if line.strip().startswith("[doctest]"):
|
|
||||||
return None
|
|
||||||
if self.is_divider(line):
|
if self.is_divider(line):
|
||||||
return self._on_divider()
|
return self._on_divider()
|
||||||
|
if not self._tmp_tc or line.strip().startswith("[doctest]"):
|
||||||
if not self._tmp_tc:
|
return None
|
||||||
self._tmp_tc = TestCase("", TestStatus.PASSED, stdout="")
|
|
||||||
self._name_tokens = []
|
|
||||||
|
|
||||||
self._tmp_tc.stdout += line
|
self._tmp_tc.stdout += line
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
@ -60,24 +56,26 @@ class DoctestTestCaseParser:
|
|||||||
return line.startswith("===") and line.endswith("===")
|
return line.startswith("===") and line.endswith("===")
|
||||||
|
|
||||||
def _on_divider(self):
|
def _on_divider(self):
|
||||||
# if the first unprocessed test case
|
test_case = None
|
||||||
if not self._tmp_tc:
|
if self._tmp_tc:
|
||||||
return None
|
test_case = TestCase(
|
||||||
test_case = TestCase(
|
name=self._tmp_tc.name.strip(),
|
||||||
name=self._tmp_tc.name,
|
status=self._tmp_tc.status,
|
||||||
status=self._tmp_tc.status,
|
message=(self._tmp_tc.message or "").strip() or None,
|
||||||
message=self._tmp_tc.message,
|
source=self._tmp_tc.source,
|
||||||
source=self._tmp_tc.source,
|
stdout=self._tmp_tc.stdout.strip(),
|
||||||
stdout=self._tmp_tc.stdout,
|
)
|
||||||
)
|
|
||||||
self._tmp_tc = None
|
self._tmp_tc = TestCase("", TestStatus.PASSED, stdout="")
|
||||||
|
self._name_tokens = []
|
||||||
return test_case
|
return test_case
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_source(line):
|
def parse_source(line):
|
||||||
assert line.endswith(":"), line
|
if not line.endswith(":"):
|
||||||
file_, line = line[:-1].rsplit(":", 1)
|
return None
|
||||||
return TestCaseSource(file_, int(line))
|
filename, line = line[:-1].rsplit(":", 1)
|
||||||
|
return TestCaseSource(filename, int(line))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_name(tokens):
|
def parse_name(tokens):
|
||||||
@ -86,7 +84,7 @@ class DoctestTestCaseParser:
|
|||||||
if token.startswith("TEST ") and ":" in token:
|
if token.startswith("TEST ") and ":" in token:
|
||||||
token = token[token.index(":") + 1 :]
|
token = token[token.index(":") + 1 :]
|
||||||
cleaned_tokens.append(token.strip())
|
cleaned_tokens.append(token.strip())
|
||||||
return " -> ".join(cleaned_tokens)
|
return "/".join(cleaned_tokens)
|
||||||
|
|
||||||
def _parse_assert(self, line):
|
def _parse_assert(self, line):
|
||||||
status_tokens = [
|
status_tokens = [
|
||||||
@ -121,7 +119,6 @@ class DoctestTestRunner(TestRunnerBase):
|
|||||||
|
|
||||||
test_case = self._tc_parser.parse(line)
|
test_case = self._tc_parser.parse(line)
|
||||||
if test_case:
|
if test_case:
|
||||||
self._tc_parser = DoctestTestCaseParser()
|
|
||||||
click.echo(test_case.humanize())
|
click.echo(test_case.humanize())
|
||||||
self.test_suite.add_case(test_case)
|
self.test_suite.add_case(test_case)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user