Skip to content
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

fix duration_ms to be correct #1

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions tap2junit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def extract_test_info_from_description(description):

def map_yaml_to_junit(test):
yaml = test.yaml or {}
# Even though the name is `duration_ms` the value is in seconds.
elapsed_sec = yaml.get("duration_ms", None)
duration_ms = yaml.get("duration_ms", None)
elapsed_sec = duration_ms if duration_ms is None else (duration_ms / 1000)
(test_class, test_name) = extract_test_info_from_description(test.description)
t = TestCase(test_name, classname=test_class, elapsed_sec=elapsed_sec)
if test.result == "ok":
Expand Down
41 changes: 28 additions & 13 deletions tap2junit/tap13.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def __init__(self, result, id, description=None, directive=None, comment=None):
class TAP13:
def __init__(self):
self.tests = []
self.__tests_counter = 0
self.__tests_counter = [0]
self._test_indentation = [0]
self.tests_planned = None

def _parse_yaml(self, line, in_yaml, in_yaml_block):
Expand All @@ -77,6 +78,14 @@ def _parse_yaml(self, line, in_yaml, in_yaml_block):

return in_yaml, in_yaml_block

def _handle_indentation(self, current_indentation):
if current_indentation > self._test_indentation[-1]:
self._test_indentation.append(current_indentation)
self.__tests_counter.append(0)
if current_indentation < self._test_indentation[-1]:
self._test_indentation.pop()
self.__tests_counter.pop()

def _parse(self, source):
seek_version = True
seek_plan = False
Expand Down Expand Up @@ -104,7 +113,8 @@ def _parse(self, source):
seek_version = False
seek_plan = True
seek_test = True
self.__tests_counter = 0
self.__tests_counter = [0]
self._test_indentation = [0]

for line in source:
if (
Expand All @@ -120,14 +130,16 @@ def _parse(self, source):
in_test = False
in_yaml = False
in_yaml_block = False
self.__tests_counter = 0
self.__tests_counter = [0]
self._test_indentation = [0]
# raise ValueError("Bad TAP format, multiple TAP headers")

if in_yaml:
in_yaml, in_yaml_block = self._parse_yaml(line, in_yaml, in_yaml_block)
continue

line = line.strip()
unstriped_line = line
line = unstriped_line.strip()

if in_test:
if RE_EXPLANATION.match(line):
Expand Down Expand Up @@ -163,38 +175,41 @@ def _parse(self, source):

# Stop processing if tests were found before the plan
# if plan is at the end, it must be last line -> stop processing
if self.__tests_counter > 0:
if len(self.__tests_counter) == 1 and self.__tests_counter[0] > 0:
break

if seek_test:
match = RE_TEST_LINE.match(line)
if match:
self.__tests_counter += 1
self._handle_indentation(len(unstriped_line) - len(line))
self.__tests_counter[-1] += 1
t_attrs = match.groupdict()
if t_attrs["id"] is None:
t_attrs["id"] = self.__tests_counter
t_attrs["id"] = self.__tests_counter[-1]
t_attrs["id"] = int(t_attrs["id"])
if t_attrs["id"] < self.__tests_counter:
if t_attrs["id"] < self.__tests_counter[-1]:
raise ValueError("Descending test id on line: %r" % line)
# according to TAP13 specs, missing tests must be handled as
# 'not ok' so here we add the missing tests in sequence
while t_attrs["id"] > self.__tests_counter:
while t_attrs["id"] > self.__tests_counter[-1]:
self.tests.append(
Test(
"not ok",
self.__tests_counter,
self.__tests_counter[-1],
comment="DIAG: Test %s not present"
% self.__tests_counter,
% self.__tests_counter[-1],
)
)
self.__tests_counter += 1
self.__tests_counter[-1] += 1
t = Test(**t_attrs)
if t.result == "Bail out!":
t.result = "not ok"
# according to TAP13 specs, everything after this is an
# explanation of why testing must be stopped
t.diagnostics = t.diagnostics or t.description
t.description = "Bail out for Test %s" % self.__tests_counter
t.description = (
"Bail out for Test %s" % self.__tests_counter[-1]
)
self.tests.append(t)
in_test = True
continue
Expand Down
50 changes: 50 additions & 0 deletions test/fixtures/test-nested.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
TAP version 13
# Subtest: parent
# Subtest: top level 1
ok 1 - top level 1
---
duration_ms: 0.340575089
...
# Subtest: top level 2
ok 2 - top level 2
---
duration_ms: 0.30303944
...
# Subtest: nested
# Subtest: nested 1
ok 1 - nested 1
---
duration_ms: 2.367745206
...
# Subtest: nested 2
not ok 2 - nested 2
---
duration_ms: 2.332323873
failureType: 'cancelledByParent'
error: 'Promise resolution is still pending but the event loop has already resolved'
code: 'ERR_TEST_FAILURE'
stack: |-
process.emit (node:events:513:28)
...
1..2
not ok 3 - nested
---
duration_ms: 2.367870901
failureType: 'fail'
error: 'Promise resolution is still pending but the event loop has already resolved'
code: 'ERR_TEST_FAILURE'
stack: |-
process.emit (node:events:513:28)
...
# Subtest: top level 4
ok 4 - top level 4
---
duration_ms: 0.340575089
...
1..4
ok 1 - parent
---
duration_ms: 2.489501484
...
1..1
# tests 1
31 changes: 31 additions & 0 deletions test/output/test-nested.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<testsuites disabled="0" errors="0" failures="2" tests="7" time="0.010541631081999998">
<testsuite disabled="0" errors="0" failures="2" name="test/fixtures/test-nested" skipped="0" tests="7" time="0.010541631081999998" hostname="{HOSTNAME}">
<testcase name="- top level 1" time="0.000341"/>
<testcase name="- top level 2" time="0.000303"/>
<testcase name="- nested 1" time="0.002368"/>
<testcase name="- nested 2" time="0.002332">
<failure type="failure" message=" (0)">
---
code: ERR_TEST_FAILURE
duration_ms: 2.332323873
error: Promise resolution is still pending but the event loop has already resolved
failureType: cancelledByParent
...
</failure>
</testcase>
<testcase name="- nested" time="0.002368">
<failure type="failure" message=" (0)">
---
code: ERR_TEST_FAILURE
duration_ms: 2.367870901
error: Promise resolution is still pending but the event loop has already resolved
failureType: fail
...
</failure>
<system-err>['# Subtest: top level 4']</system-err>
</testcase>
<testcase name="- top level 4" time="0.000341"/>
<testcase name="- parent" time="0.002490"/>
</testsuite>
</testsuites>
Loading