def make_testgroups(self, results_collection): testgroups = [] for context in results_collection.contexts: coll = results_collection.subset(lambda t: t.context == context) passed = coll.tests_with_result('PASS') failed = coll.tests_with_result('UNEXPECTED-FAIL') unexpected_passes = coll.tests_with_result('UNEXPECTED-PASS') errors = coll.tests_with_result('ERROR') skipped = coll.tests_with_result('SKIPPED') known_fails = coll.tests_with_result('KNOWN-FAIL') testgroup = RESTfulAutologTestGroup( testgroup=context.testgroup, os=context.os, platform=context.arch, harness=context.harness, server=self.es_server, restserver=self.rest_server, machine=context.hostname, logfile=context.logfile, ) testgroup.add_test_suite( testsuite=results_collection.suite_name, elapsedtime=coll.time_taken, passed=count(passed), failed=count(failed) + count(errors) + count(unexpected_passes), todo=count(skipped) + count(known_fails), ) testgroup.set_primary_product( tree=context.tree, revision=context.revision, productname=context.product, buildtype=context.buildtype, ) # need to call this again since we already used the generator for f in coll.tests_with_result('UNEXPECTED-FAIL'): testgroup.add_test_failure( test=long_name(f), text='\n'.join(f.output), status=f.result, ) testgroups.append(testgroup) return testgroups
def serialize(self, results_collection, file_obj): """ Writes the xUnit formatted results to the given file object """ def _extract_xml(test_result, text='', result='Pass'): if not isinstance(text, basestring): text = '\n'.join(text) cls_name = test_result.test_class # if the test class is not already created, create it if cls_name not in classes: cls = doc.createElement('class') cls.setAttribute('name', cls_name) assembly.appendChild(cls) classes[cls_name] = cls t = doc.createElement('test') t.setAttribute('name', test_result.name) t.setAttribute('result', result) if result == 'Fail': f = doc.createElement('failure') st = doc.createElement('stack-trace') st.appendChild(doc.createTextNode(text)) f.appendChild(st) t.appendChild(f) elif result == 'Skip': r = doc.createElement('reason') msg = doc.createElement('message') msg.appendChild(doc.createTextNode(text)) r.appendChild(msg) t.appendChild(f) cls = classes[cls_name] cls.appendChild(t) doc = dom.Document() failed = sum([count(results_collection.tests_with_result(t)) for t in TestResult.FAIL_RESULTS]) passed = count(results_collection.tests_with_result('PASS')) skipped = count(results_collection.tests_with_result('SKIPPED')) assembly = doc.createElement('assembly') assembly.setAttribute('name', results_collection.suite_name) assembly.setAttribute('time', str(results_collection.time_taken)) assembly.setAttribute('total', str(len(results_collection))) assembly.setAttribute('passed', str(passed)) assembly.setAttribute('failed', str(failed)) assembly.setAttribute('skipped', str(skipped)) classes = {} # str -> xml class element for tr in results_collection.tests_with_result('ERROR'): _extract_xml(tr, text=tr.output, result='Fail') for tr in results_collection.tests_with_result('UNEXPECTED-FAIL'): _extract_xml(tr, text=tr.output, result='Fail') for tr in results_collection.tests_with_result('UNEXPECTED-PASS'): _extract_xml(tr, text='UNEXPECTED-PASS', result='Fail') for tr in results_collection.tests_with_result('SKIPPED'): _extract_xml(tr, text=tr.output, result='Skip') for tr in results_collection.tests_with_result('KNOWN-FAIL'): _extract_xml(tr, text=tr.output, result='Pass') for tr in results_collection.tests_with_result('PASS'): _extract_xml(tr, result='Pass') for cls in classes.itervalues(): assembly.appendChild(cls) doc.appendChild(assembly) file_obj.write(doc.toxml(encoding='utf-8'))
def serialize(self, results_collection, file_obj): """ Writes the xUnit formatted results to the given file object """ def _extract_xml(test_result, text='', result='Pass'): if not isinstance(text, string_types): text = '\n'.join(text) cls_name = test_result.test_class # if the test class is not already created, create it if cls_name not in classes: cls = doc.createElement('class') cls.setAttribute('name', cls_name) assembly.appendChild(cls) classes[cls_name] = cls t = doc.createElement('test') t.setAttribute('name', test_result.name) t.setAttribute('result', result) if result == 'Fail': f = doc.createElement('failure') st = doc.createElement('stack-trace') st.appendChild(doc.createTextNode(text)) f.appendChild(st) t.appendChild(f) elif result == 'Skip': r = doc.createElement('reason') msg = doc.createElement('message') msg.appendChild(doc.createTextNode(text)) r.appendChild(msg) t.appendChild(f) cls = classes[cls_name] cls.appendChild(t) doc = dom.Document() failed = sum([count(results_collection.tests_with_result(t)) for t in TestResult.FAIL_RESULTS]) passed = count(results_collection.tests_with_result('PASS')) skipped = count(results_collection.tests_with_result('SKIPPED')) assembly = doc.createElement('assembly') assembly.setAttribute('name', results_collection.suite_name) assembly.setAttribute('time', str(results_collection.time_taken)) assembly.setAttribute('total', str(len(results_collection))) assembly.setAttribute('passed', str(passed)) assembly.setAttribute('failed', str(failed)) assembly.setAttribute('skipped', str(skipped)) classes = {} # str -> xml class element for tr in results_collection.tests_with_result('ERROR'): _extract_xml(tr, text=tr.output, result='Fail') for tr in results_collection.tests_with_result('UNEXPECTED-FAIL'): _extract_xml(tr, text=tr.output, result='Fail') for tr in results_collection.tests_with_result('UNEXPECTED-PASS'): _extract_xml(tr, text='UNEXPECTED-PASS', result='Fail') for tr in results_collection.tests_with_result('SKIPPED'): _extract_xml(tr, text=tr.output, result='Skip') for tr in results_collection.tests_with_result('KNOWN-FAIL'): _extract_xml(tr, text=tr.output, result='Pass') for tr in results_collection.tests_with_result('PASS'): _extract_xml(tr, result='Pass') for cls in classes.itervalues(): assembly.appendChild(cls) doc.appendChild(assembly) file_obj.write(doc.toxml(encoding='utf-8'))
from parsec import joint from base import pid, count from parsing import * RadFET = pid(0x35) >> joint(field('Status', byte), field( 'Temperature', uint32), field('Voltages', count(uint32, 3))).bind(to_dict) RadFET >>= label_as('RadFET')
from parsec import joint from base import pid, count from parsing import * ExperimentalSunSStatus = joint( field('ALS_ACK', uint16), field('ALS_Presence', uint16), field('ALS_ADC_Valid', uint16), ) ExperimentalSunSStatus >>= to_dict SingleALS = count(uint16, 4) ALSs = count(SingleALS, 3) Temperatures = joint( field('Structure', uint16), field('A', uint16), field('B', uint16), field('C', uint16), field('D', uint16), ).bind(to_dict) ExperimentalSunSPrimary = pid(0x11) \ >> joint( field('WhoAmI ', byte), field('Status', ExperimentalSunSStatus), field('VisibleLight', ALSs), field('Temperatures', Temperatures), ).bind(to_dict) ExperimentalSunSPrimary >>= label_as('ExpSunS.Primary')