From 1c6f56ab79405021a3f14778ffbe96201503798b Mon Sep 17 00:00:00 2001 From: Aleksa Svitlica Date: Mon, 23 Jan 2023 20:17:01 -0500 Subject: [PATCH] Cloud Policy: Remove xunitparser dependency To avoid an external dependency the required xunit parsing has been implemented directly in the policy. --- britney2/policies/cloud.py | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/britney2/policies/cloud.py b/britney2/policies/cloud.py index ebbd591..d62bbcd 100644 --- a/britney2/policies/cloud.py +++ b/britney2/policies/cloud.py @@ -6,7 +6,7 @@ import shutil import smtplib import socket import subprocess -import xunitparser +import xml.etree.ElementTree as ET from britney2 import SuiteClass from britney2.policies.policy import BasePolicy @@ -221,13 +221,38 @@ class CloudPolicy(BasePolicy): """ for file_path in results_file_paths: with open(file_path) as file: - ts, tr = xunitparser.parse(file) + xml = ET.parse(file) + root = xml.getroot() - for testcase, message in tr.failures: - self.store_test_result(self.failures, cloud, testcase.methodname, message) + if root.tag == "testsuites": + for testsuite in root: + self._parse_xunit_testsuite(cloud, testsuite) + else: + self._parse_xunit_testsuite(cloud, root) - for testcase, message in tr.errors: - self.store_test_result(self.errors, cloud, testcase.methodname, message) + def _parse_xunit_testsuite(self, cloud, root): + """Parses the xunit testsuite and stores any failure or error test results. + + :param cloud The name of the cloud, used for storing the results. + :param root An XML tree root. + """ + for el in root: + if el.tag == "testcase": + for e in el: + if e.tag == "failure": + type = e.attrib.get('type') + message = e.attrib.get('message') + info = "{}: {}".format(type, message) + self.store_test_result( + self.failures, cloud, el.attrib.get('name'), info + ) + if e.tag == "error": + type = e.attrib.get('type') + message = e.attrib.get('message') + info = "{}: {}".format(type, message) + self.store_test_result( + self.errors, cloud, el.attrib.get('name'), info + ) def store_test_result(self, results, cloud, test_name, message): """Adds the test to the results hash under the given cloud.