summaryrefslogtreecommitdiff
path: root/tests/test_plugins.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2019-03-23 21:06:09 -0400
committerNed Batchelder <ned@nedbatchelder.com>2019-03-23 21:06:09 -0400
commita868dd01713cb3020bd768830fca7d1c0eef1720 (patch)
treeb2a0d2dd3af6e5d3bc62b196d2a8b59514b5af4d /tests/test_plugins.py
parent7e6716562f3b7818c19e06f5cd9c063c02cb7980 (diff)
downloadpython-coveragepy-git-a868dd01713cb3020bd768830fca7d1c0eef1720.tar.gz
Rewrite XML tests to use xml parsing instead of regexes
Diffstat (limited to 'tests/test_plugins.py')
-rw-r--r--tests/test_plugins.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/tests/test_plugins.py b/tests/test_plugins.py
index d3365a6d..14d07c1a 100644
--- a/tests/test_plugins.py
+++ b/tests/test_plugins.py
@@ -4,6 +4,7 @@
"""Tests for plugins."""
import os.path
+from xml.etree import ElementTree
import coverage
from coverage import env
@@ -455,14 +456,25 @@ class GoodFileTracerTest(FileTracerTest):
total = cov.xml_report(include=["*.html"], omit=["uni*.html"])
self.assertAlmostEqual(total, 36.36, places=2)
- with open("coverage.xml") as fxml:
- xml = fxml.read()
-
- for snip in [
- 'filename="bar_4.html" line-rate="0.5" name="bar_4.html"',
- 'filename="foo_7.html" line-rate="0.2857" name="foo_7.html"',
- ]:
- self.assertIn(snip, xml)
+ dom = ElementTree.parse("coverage.xml")
+ classes = {}
+ for elt in dom.findall(".//class"):
+ classes[elt.get('name')] = elt
+
+ assert classes['bar_4.html'].attrib == {
+ 'branch-rate': '1',
+ 'complexity': '0',
+ 'filename': 'bar_4.html',
+ 'line-rate': '0.5',
+ 'name': 'bar_4.html',
+ }
+ assert classes['foo_7.html'].attrib == {
+ 'branch-rate': '1',
+ 'complexity': '0',
+ 'filename': 'foo_7.html',
+ 'line-rate': '0.2857',
+ 'name': 'foo_7.html',
+ }
def test_defer_to_python(self):
# A plugin that measures, but then wants built-in python reporting.