Skip to content

Commit

Permalink
Make sure there are no Nones in our list
Browse files Browse the repository at this point in the history
  • Loading branch information
Bachmann1234 committed Dec 18, 2018
1 parent 1982627 commit db3402e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions diff_cover/tests/test_violations_reporter.py
Expand Up @@ -6,6 +6,7 @@
import xml.etree.cElementTree as etree
from subprocess import Popen
from textwrap import dedent

import mock

import six
Expand Down Expand Up @@ -120,6 +121,32 @@ def test_non_python_violations(self):
)
)

def test_non_python_violations_empty_path(self):
"""
In the wild empty sources can happen. See https://github.com/Bachmann1234/diff-cover/issues/88
Best I can tell its mostly irrelevant but I mostly dont want it crashing
"""

xml = etree.fromstring('''
<coverage line-rate="0.178" branch-rate="0.348" version="1.9" timestamp="1545037553" lines-covered="675" lines-valid="3787" branches-covered="260" branches-valid="747">
<sources>
<source></source>
</sources>
</coverage>
''')

coverage = XmlCoverageReporter([xml])

self.assertEqual(
set(),
coverage.violations('')
)

self.assertEqual(
set(),
coverage.measured_lines('')
)

def test_two_inputs_first_violate(self):

# Construct the XML report
Expand Down
2 changes: 1 addition & 1 deletion diff_cover/violationsreporters/violations_reporter.py
Expand Up @@ -76,7 +76,7 @@ def _get_classes(self, xml_document, src_path):
# cobertura sometimes provides the sources for the measurements
# within it. If we have that we outta use it
sources = xml_document.findall('sources/source')
sources = [source.text for source in sources]
sources = [source.text for source in sources if source.text]
classes = [class_tree
for class_tree in xml_document.findall(".//class")
or []]
Expand Down

0 comments on commit db3402e

Please sign in to comment.