def __init__(self, url, path='./', data='result.xml', debug=False): """Result class constructor.""" self.debugging = debug self.file = ''.join([path, '/', data]) self.run_id = os.getenv('RUNID') self.tree, self.root = self.get_tree() self.test_rail = TestRailAPI(url=url) self.test_set = self.test_rail.get_tests(run_id=int(self.run_id))
class Result(object): """Test Result Control.""" NEW_LINE = ''.join([chr(10), chr(13)]) def __init__(self, url, path='./', data='result.xml', debug=False): """Result class constructor.""" self.debugging = debug self.file = ''.join([path, '/', data]) self.run_id = os.getenv('RUNID') self.tree, self.root = self.get_tree() self.test_rail = TestRailAPI(url=url) self.test_set = self.test_rail.get_tests(run_id=int(self.run_id)) @classmethod def prod(cls, vals): """Non operator multiplier.""" return reduce(operator.mul, vals, 1) def get_tree(self): """Return the tree and the tree root.""" tree = ElementTree.parse(self.file) return tree, tree.getroot() def find_test_id(self, case_id, tests): """Return a test ID.""" # print('Test ID:', case_id) try: case = int(case_id) except ValueError: list_tests = [] for val in tests: list_tests.append(val['case_id']) print( 'Case "%s" is not a valid case ID in %s.' % (case_id, list_tests.sort()) ) return -1
class Result(object): """Test Result Control.""" NEW_LINE = ''.join([chr(10), chr(13)]) def __init__(self, url, path='./', data='result.xml', debug=False): """Result class constructor.""" self.debugging = debug self.file = ''.join([path, '/', data]) self.run_id = os.getenv('RUNID') self.tree, self.root = self.get_tree() self.test_rail = TestRailAPI(url=url) self.test_set = self.test_rail.get_tests(run_id=int(self.run_id)) @classmethod def prod(cls, vals): """Non operator multiplier.""" return reduce(operator.mul, vals, 1) def get_tree(self): """Return the tree and the tree root.""" tree = ElementTree.parse(self.file) return tree, tree.getroot() def find_test_id(self, case_id, tests): """Return a test ID.""" # print('Test ID:', case_id) try: case = int(case_id) except ValueError: list_tests = [] for val in tests: list_tests.append(val['case_id']) print( 'Case "%s" is not a valid case ID in %s.' % (case_id, list_tests.sort()) ) return -1 for test in tests: if case == test['case_id']: return test['id'] return -1 def get_status(self, string): """Return test status.""" if string == 'passed': return TestRailAPI.PASSED elif string == 'failure': return TestRailAPI.FAILED return TestRailAPI.UNTESTED def get_time_string(self, time): """Return the time string.""" to_string = '' new_time = int(float(time)) if new_time <= 0: return '1s' hours = int(new_time / 3600) new_time = new_time - Result.prod([hours, 3600]) minutes = int(new_time / 60) new_time = new_time - Result.prod([minutes, 60]) seconds = int(new_time) if hours > 0: to_string += '%sh ' % hours if minutes == 0 and seconds == 0: return to_string[:-1] if minutes > 0: to_string += '%sm ' % minutes if seconds == 0: return to_string[:-1] return to_string + '%ss' % seconds def retrieve_test_results(self): """Split the tree.""" for child in self.root: child.set( 'case', child.get('name').split('_')[-1] ) child.set( 'test', self.find_test_id(child.get('case'), self.test_set) ) sub = list(child.iter()) if len(sub) >= 2: if sub[1].tag == 'system-out': child.set('status', 'passed') else: child.set('status', sub[1].tag) message = sub[1].get('message') if 'message' in \ sub[1].attrib else '' parts = message.split( '_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ' + '_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _' ) reorder = 'Break Point:' + Result.NEW_LINE + \ parts[0] + Result.NEW_LINE if len(parts) > 1: final = str(parts[len(parts) - 1]) reorder = reorder + Result.NEW_LINE + \ 'Reason:' + Result.NEW_LINE reorder = reorder + \ final[:-operator.floordiv(len(final), 4)] reorder = reorder + Result.NEW_LINE child.set('message', reorder) child.set('text', sub[1].text) else: child.set('status', 'passed') child.set('message', '') child.set('text', '')