diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2013-09-30 07:21:52 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2013-09-30 07:21:52 -0400 |
commit | fcbc0ae92f7c6b4da951a86978148c0fbd9487de (patch) | |
tree | 2678d69fed289ab878e0fdc7910d4408f43ea526 /tests/test_xml.py | |
parent | 1f78825f1fdca394ea9689c84f67629bab5ff495 (diff) | |
download | python-coveragepy-fcbc0ae92f7c6b4da951a86978148c0fbd9487de.tar.gz |
Don't divide by zero if nothing to report. #250.
Diffstat (limited to 'tests/test_xml.py')
-rw-r--r-- | tests/test_xml.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/test_xml.py b/tests/test_xml.py index 1659aa0..0801bad 100644 --- a/tests/test_xml.py +++ b/tests/test_xml.py @@ -1,10 +1,12 @@ """Tests for XML reports from coverage.py.""" -import os, re +import os +import re import coverage from tests.coveragetest import CoverageTest + class XmlReportTest(CoverageTest): """Tests of the XML reports from coverage.py.""" @@ -77,8 +79,21 @@ class XmlReportTest(CoverageTest): doit_line = re_line(xml, "class.*doit") self.assertIn('filename="sub/doit.py"', doit_line) + def test_reporting_on_nothing(self): + # Used to raise a zero division error: + # https://bitbucket.org/ned/coveragepy/issue/250 + self.make_file("empty.py", "") + cov = coverage.coverage() + empty = self.start_import_stop(cov, "empty") + cov.xml_report([empty], outfile="-") + xml = self.stdout() + empty_line = re_line(xml, "class.*empty") + self.assertIn('filename="empty.py"', empty_line) + self.assertIn('line-rate="0"', empty_line) + def re_line(text, pat): """Return the one line in `text` that matches regex `pat`.""" lines = [l for l in text.splitlines() if re.search(pat, l)] + assert len(lines) == 1 return lines[0] |