Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions junit_conversor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import xml.etree.cElementTree as ET
import sys
from collections import defaultdict
import xml.etree.cElementTree as ET


def _parse(file_name):
lines = tuple(open(file_name, 'r'))
parsed = defaultdict(list)
parsed = {}

for line in lines:
splitted = line.split(":", 3)
Expand All @@ -20,7 +19,8 @@ def _parse(file_name):
'code': splitted[3].strip()[:4]
}

parsed[error['file']].append(error)
case_name = '{file}:{line}:{col}:'.format(file=error['file'], line=error['line'], col=error['col'])
parsed[case_name] = error

return dict(parsed)

Expand All @@ -35,21 +35,19 @@ def _convert(origin, destination):
testsuite.attrib["tests"] = str(len(parsed)) or "1"
testsuite.attrib["time"] = "1"

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']
}
for case_name, error in parsed.items():
testcase = ET.SubElement(testsuite, "testcase", name=case_name)
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'])
text = "{0}:{1} {2}".format(error['line'], error['col'], error['detail'])

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

tree = ET.ElementTree(testsuite)

Expand Down
15 changes: 7 additions & 8 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def test_should_parse_a_flake8_file_with_errors(self):
parsed = _parse(failed_flake8)

self.assertEqual(parsed, {
"tests/subject/__init__.py": [
"tests/subject/__init__.py:1:1:":
{"file": "tests/subject/__init__.py", "line": "1", "col": "1", "detail": "F401 'os' imported but unused", "code": "F401"},
"tests/subject/__init__.py:3:1:":
{"file": "tests/subject/__init__.py", "line": "3", "col": "1", "detail": "E302 expected 2 blank lines, found 1", "code": "E302"},
],
"tests/subject/example.py": [
"tests/subject/example.py:4:1:":
{"file": "tests/subject/example.py", "line": "4", "col": "1", "detail": "E302 expected 2 blank lines, found 1", "code": "E302"},
"tests/subject/example.py:16:22:":
{"file": "tests/subject/example.py", "line": "16", "col": "22", "detail": "E203 whitespace before ':'", "code": "E203"},
]
})

def test_should_return_an_empty_dict_when_parsing_a_flake8_success_file(self):
Expand All @@ -56,13 +56,12 @@ def test_should_skip_invalid_lines(self):
parsed = _parse(failed_flake8_with_invalid_lines)

self.assertEqual(parsed, {
"tests/subject/__init__.py": [
"tests/subject/__init__.py:1:1:":
{"file": "tests/subject/__init__.py", "line": "1", "col": "1", "detail": "F401 'os' imported but unused", "code": "F401"},
"tests/subject/__init__.py:3:1:":
{"file": "tests/subject/__init__.py", "line": "3", "col": "1", "detail": "E302 expected 2 blank lines, found 1", "code": "E302"},
],
"tests/subject/example.py": [
"tests/subject/example.py:4:1:":
{"file": "tests/subject/example.py", "line": "4", "col": "1", "detail": "E302 expected 2 blank lines, found 1", "code": "E302"},
]
})


Expand Down