Created
August 15, 2014 21:17
-
-
Save Tattoo/ebebab354e0844a12f8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from robot.api import ExecutionResult, ResultVisitor | |
from robot.result.keyword import Keyword | |
from robot.result.testsuite import TestSuite | |
class dotdict(dict): | |
def __getattr__(self, attr_name): | |
return self[attr_name] | |
def __setattr__(self, attr_name, value): | |
self[attr_name] = value | |
class DataCollector(ResultVisitor): | |
def __init__(self): | |
self.data = dotdict() | |
self.current_suite = None | |
self.current_test = None | |
def start_suite(self, suite): | |
self.current_suite = suite.name | |
self.data[self.current_suite] = [] | |
def end_suite(self, suite): | |
self.current_suite = None | |
def start_test(self, test): | |
self.current_test = dotdict(name=test.name, status=test.status, kws=[]) | |
def end_test(self, test): | |
self.data[self.current_suite].append(self.current_test) | |
self.current_test = None | |
def start_keyword(self, keyword): | |
if type(keyword.parent) == Keyword or type(keyword.parent) == TestSuite: | |
return | |
self.current_test.kws.append(dotdict(name=keyword.name, | |
args=keyword.args, | |
status=keyword.status, | |
message=' '.join([m.message for m | |
in keyword.messages]))) | |
def write(outfile, data): | |
out='"Suite","Test","Keyword","Status","Arguments","Messages"\n' | |
for suite, tests in data.iteritems(): | |
for test in tests: | |
out += '"%s","%s",,"%s",,\n' % (suite, test.name, test.status) | |
for kw in test.kws: | |
out += ',,"%s","%s","%s","%s"\n' % (kw.name, | |
kw.status, | |
'; '.join(kw.args), | |
kw.message) | |
with open(outfile, 'w') as f: | |
f.write(out) | |
if __name__ == '__main__': | |
if len(sys.argv) < 3: | |
sys.stdout.write('Provide input and output files!\n') | |
sys.exit(1) | |
infile, outfile = sys.argv[-2], sys.argv[-1] | |
sys.stdout.write('PARSING...') | |
result = ExecutionResult(infile) | |
sys.stdout.write('LET\'S DO THIS!\n') | |
visitor = DataCollector() | |
result.visit(visitor) | |
sys.stdout.write('WRITING: %s' % outfile) | |
write(outfile, visitor.data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment