diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-09-23 22:11:47 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-09-23 22:11:47 -0400 |
commit | e44f649ad61d6a7e717931628d2476284402484b (patch) | |
tree | 9a70873264cc7832e1156eaac5626f3ff6652408 | |
parent | c0f54c80150b65d650e85339e98c17d025625d24 (diff) | |
download | python-coveragepy-git-e44f649ad61d6a7e717931628d2476284402484b.tar.gz |
Get the test working properly, including adding a usable diff comparison when tests fail. Also make it all work under Py3k.
-rw-r--r-- | coverage/xmlreport.py | 5 | ||||
-rw-r--r-- | test/farm/html/gold_x_xml/coverage.xml (renamed from test/farm/html/gold_a_xml/coverage.xml) | 2 | ||||
-rw-r--r-- | test/farm/html/run_a.py | 2 | ||||
-rw-r--r-- | test/farm/html/run_x_xml.py (renamed from test/farm/html/run_a_xml.py) | 8 | ||||
-rw-r--r-- | test/farm/html/src/x.py | 7 | ||||
-rw-r--r-- | test/test_farm.py | 7 |
6 files changed, 19 insertions, 12 deletions
diff --git a/coverage/xmlreport.py b/coverage/xmlreport.py index 7fb2ba67..8d5e4ddc 100644 --- a/coverage/xmlreport.py +++ b/coverage/xmlreport.py @@ -3,6 +3,7 @@ import os, sys import xml.dom.minidom +from coverage.backward import sorted from coverage.report import Reporter @@ -103,9 +104,7 @@ class XmlReporter(Reporter): packageXml.appendChild(package) classes = doc.createElement("classes") package.appendChild(classes) - classNames = packageData[1].keys() - classNames.sort() - for className in classNames: + for className in sorted(packageData[1].keys()): classes.appendChild(packageData[1][className]) package.setAttribute("name", packageName.replace(os.sep, '.')) package.setAttribute("line-rate", str(packageData[2]/(packageData[3] or 1.0))) diff --git a/test/farm/html/gold_a_xml/coverage.xml b/test/farm/html/gold_x_xml/coverage.xml index 9c67a55c..510590ac 100644 --- a/test/farm/html/gold_a_xml/coverage.xml +++ b/test/farm/html/gold_x_xml/coverage.xml @@ -5,7 +5,7 @@ <packages>
<package branch-rate="0.0" complexity="0.0" line-rate="0.666666666667" name=".">
<classes>
- <class branch-rate="0.0" complexity="0.0" filename="c:\ned\coverage\trunk\test\farm\html\src\a.py" line-rate="0.666666666667" name="a">
+ <class branch-rate="0.0" complexity="0.0" filename="c:\ned\coverage\trunk\test\farm\html\src\x.py" line-rate="0.666666666667" name="x">
<lines>
<line branch="false" hits="1" number="3"/>
<line branch="false" hits="1" number="5"/>
diff --git a/test/farm/html/run_a.py b/test/farm/html/run_a.py index 4a8a0514..dc7719a2 100644 --- a/test/farm/html/run_a.py +++ b/test/farm/html/run_a.py @@ -11,7 +11,7 @@ runfunc(html_it, rundir="src") # HTML files will change often. Check that the sizes are reasonable, # and check that certain key strings are in the output. -compare("html", "gold_a", size_within=10) +compare("gold_a", "html", size_within=10) contains("html/a.html", "<span class='key'>if</span> <span class='num'>1</span> <span class='op'><</span> <span class='num'>2</span>", " <span class='nam'>a</span> <span class='op'>=</span> <span class='num'>3</span>", diff --git a/test/farm/html/run_a_xml.py b/test/farm/html/run_x_xml.py index 6df7dcd4..c1dbb163 100644 --- a/test/farm/html/run_a_xml.py +++ b/test/farm/html/run_x_xml.py @@ -1,11 +1,11 @@ def html_it(): - """Run coverage and make an XML report for a.""" + """Run coverage and make an XML report for x.""" import coverage cov = coverage.coverage() cov.start() - import a + import x cov.stop() - cov.xml_report(a, outfile=open("../xml/coverage.xml", 'w')) + cov.xml_report(x, outfile=open("../xml/coverage.xml", 'w')) import os if not os.path.exists("xml"): @@ -13,5 +13,5 @@ if not os.path.exists("xml"): runfunc(html_it, rundir="src") -compare("xml", "gold_a_xml") +compare("gold_x_xml", "xml") clean("xml") diff --git a/test/farm/html/src/x.py b/test/farm/html/src/x.py new file mode 100644 index 00000000..9e71aebd --- /dev/null +++ b/test/farm/html/src/x.py @@ -0,0 +1,7 @@ +# A test file for HTML reporting by coverage. + +if 1 < 2: + # Needed a < to look at HTML entities. + a = 3 +else: + a = 4 diff --git a/test/test_farm.py b/test/test_farm.py index 6200611d..01934dfd 100644 --- a/test/test_farm.py +++ b/test/test_farm.py @@ -1,6 +1,6 @@ """Run tests in the farm subdirectory. Designed for nose.""" -import filecmp, fnmatch, glob, os, shutil, sys +import difflib, filecmp, fnmatch, glob, os, shutil, sys sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k from backtest import run_command, execfile # pylint: disable-msg=W0622 @@ -218,10 +218,11 @@ class FarmTestCase(object): # ourselves. text_diff = [] for f in diff_files: - left = open(os.path.join(dir1, f), "r").read() - right = open(os.path.join(dir2, f), "r").read() + left = open(os.path.join(dir1, f), "r").readlines() + right = open(os.path.join(dir2, f), "r").readlines() if left != right: text_diff.append(f) + print("".join(list(difflib.Differ().compare(left, right)))) assert not text_diff, "Files differ: %s" % text_diff if not left_extra: |