summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-09-23 22:11:47 -0400
committerNed Batchelder <ned@nedbatchelder.com>2009-09-23 22:11:47 -0400
commite44f649ad61d6a7e717931628d2476284402484b (patch)
tree9a70873264cc7832e1156eaac5626f3ff6652408 /test
parentc0f54c80150b65d650e85339e98c17d025625d24 (diff)
downloadpython-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.
Diffstat (limited to 'test')
-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.py2
-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.py7
-rw-r--r--test/test_farm.py7
5 files changed, 17 insertions, 9 deletions
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'>&lt;</span> <span class='num'>2</span>",
"&nbsp; &nbsp; <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: