Skip to content

Commit

Permalink
Refactor _convert method
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosgoce committed Jan 5, 2016
1 parent c71e643 commit 3a7bc75
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions junit_conversor/__init__.py
Expand Up @@ -35,22 +35,24 @@ def _convert(origin, destination):
testsuite.attrib["tests"] = str(len(parsed)) or "1"
testsuite.attrib["time"] = "1"

if len(parsed) < 1:
testcase = ET.SubElement(testsuite, "testcase", name="Flake8Tests")
else:
for file_name, errors in parsed.items():
testcase = ET.SubElement(testsuite, "testcase", name=file_name)

for error in errors:
ET.SubElement(testcase, "failure", file=error['file'],
line=error['line'], col=error['col'],
message=error['detail'],
type="flake8 %s" % error['code']) \
.text = "{0}:{1} {2}".format(error['line'],
error['col'],
error['detail'])
for file_name, errors in parsed.items():
testcase = ET.SubElement(testsuite, "testcase", name=file_name)

for error in errors:
kargs = {
"file": error['file'],
"line": error['line'],
"col": error['col'],
"message": error['detail'],
"type": "flake8 %s" % error['code']
}

text = "{0}:{1} {2}".format(error['line'], error['col'], error['detail'])

ET.SubElement(testcase, "failure", **kargs).text = text

tree = ET.ElementTree(testsuite)

if (2, 6) == sys.version_info[:2]: # py26
tree.write(destination, encoding='utf-8')
else:
Expand Down

0 comments on commit 3a7bc75

Please sign in to comment.