Skip to content

Commit

Permalink
Kettle keeps hitting "malformed" xml (#19687)
Browse files Browse the repository at this point in the history
* Kettle keeps hitting "malformed" xml

Kettle parses xml from GCS buckets.

* Update tests to reflect handling of bad xml

* Can't log with f-strings

* Change handling of bad xml
  • Loading branch information
MushuEE authored Oct 27, 2020
1 parent b20afc5 commit 421bd13
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
11 changes: 5 additions & 6 deletions kettle/make_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,12 @@ def set_elapsed(self):
def parse_junit(xml):
"""Generate failed tests as a series of dicts. Ignore skipped tests."""
# NOTE: this is modified from gubernator/view_build.py

try:
tree = ET.fromstring(xml)
except ET.ParseError:
print("Malformed xml, skipping")
return [] #return empty itterator to skip results for this test

yield from [] #return empty itterator to skip results for this test
return

# pylint: disable=redefined-outer-name

Expand All @@ -184,16 +183,16 @@ def parse_result(child_node):

if tree.tag == 'testsuite':
for child in tree.findall('testcase'):
name = child.attrib['name']
name = child.attrib.get('name', '<unspecified>')
time, failure_text, skipped = parse_result(child)
if skipped:
continue
yield make_result(name, time, failure_text)
elif tree.tag == 'testsuites':
for testsuite in tree:
suite_name = testsuite.attrib.get('name', 'unknown')
suite_name = testsuite.attrib.get('name', '<unspecified>')
for child in testsuite.findall('testcase'):
name = '%s %s' % (suite_name, child.attrib['name'])
name = '%s %s' % (suite_name, child.attrib.get('name', '<unspecified>'))
time, failure_text, skipped = parse_result(child)
if skipped:
continue
Expand Down
24 changes: 19 additions & 5 deletions kettle/make_json_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,29 +636,43 @@ class ParseJsonTest(unittest.TestCase):
'kettle/testdata/junit_no_suite_name.xml',
[{'failed': True,
'failure_text': 'simple_test.go:186: Running tests in file plumbing',
'name': 'unknown TestSimpleFile',
'name': '<unspecified> TestSimpleFile',
'time': 0.0},
{'name': 'unknown TestSimpleFile/plumbing/min/min_program', 'time': 0.0},
{'name': 'unknown TestSimpleFile/plumbing/eval_results/error_result',
{'name': '<unspecified> TestSimpleFile/plumbing/min/min_program', 'time': 0.0},
{'name': '<unspecified> TestSimpleFile/plumbing/eval_results/error_result',
'time': 0.0}],
),
('Failure as Message',
'kettle/testdata/failure_message.xml',
[{'failed': True,
'failure_text': 'simple_test.go:186: Running tests in file plumbing',
'name': 'unknown TestSimpleFile',
'name': '<unspecified> TestSimpleFile',
'time': 0.0}],
),
('Failure as Text',
'kettle/testdata/failure_text.xml',
[{'failed': True,
'failure_text': 'simple_test.go:186: Running tests in file plumbing',
'name': 'unknown TestSimpleFile',
'name': '<unspecified> TestSimpleFile',
'time': 0.0}],
),
('Malformed XML',
'kettle/testdata/malformed.xml',
[],
),
('Malformed Testcase',
'kettle/testdata/malformed_no_testcase_name.xml',
[{'name': 'TearDown Previous', 'time': 2.065e-05},
{'name': 'Up', 'time': 6.342e-06},
{'name': 'test setup', 'time': 5.298e-06},
{'failed': True,
'failure_text': 'error during go run',
'name': 'Node Tests',
'time': 654.279097299},
{'name': '<unspecified>', 'time': 5.399023835},
{'name': '<unspecified>', 'time': 1.21e-05},
{'name': 'Deferred TearDown', 'time': 2.17e-07},
{'name': 'Timeout', 'time': 3900.0}],
)
])
def test_parse_junit(self, _, path, expected):
Expand Down
12 changes: 12 additions & 0 deletions kettle/testdata/malformed_no_testcase_name.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<testsuite failures="1" tests="7" time="662.614119181">
<testcase classname="e2e.go" name="TearDown Previous" time="2.065e-05"/>
<testcase classname="e2e.go" name="Up" time="6.342e-06"/>
<testcase classname="e2e.go" name="test setup" time="5.298e-06"/>
<testcase classname="e2e.go" name="Node Tests" time="654.279097299">
<failure>error during go run</failure>
</testcase>
<testcase classname="e2e.go" time="5.399023835"/>
<testcase classname="e2e.go" time="1.21e-05"/>
<testcase classname="e2e.go" name="Deferred TearDown" time="2.17e-07"/>
<testcase classname="e2e.go" name="Timeout" time="3900"/>
</testsuite>

0 comments on commit 421bd13

Please sign in to comment.