summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-08-22 10:03:33 -0400
committerNed Batchelder <ned@nedbatchelder.com>2018-08-24 06:54:17 -0400
commit7f5fb57e3e264f134c162dfb25c92e2b2d0e79e0 (patch)
tree6102f4cff83c1d5653ef86742052ab287cd1b69b
parent6df4275aa5e15e0f9033946837c1168a7dec00d5 (diff)
downloadpython-coveragepy-git-7f5fb57e3e264f134c162dfb25c92e2b2d0e79e0.tar.gz
Stop using farm/src for HTML tests.
-rw-r--r--coverage/html.py2
-rw-r--r--tests/farm/html/gold_other/blah_blah_other_py.html4
-rw-r--r--tests/farm/html/gold_other/index.html2
-rw-r--r--tests/goldtest.py6
-rw-r--r--tests/test_html.py484
-rw-r--r--tests/test_xml.py13
-rw-r--r--tox.ini2
7 files changed, 352 insertions, 161 deletions
diff --git a/coverage/html.py b/coverage/html.py
index 2acc2656..5c835684 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -68,7 +68,7 @@ def read_data(fname):
def write_html(fname, html):
"""Write `html` to `fname`, properly encoded."""
- html = re.sub(r"(\A\s+)|(\s+$)", "", html, flags=re.MULTILINE)
+ html = re.sub(r"(\A\s+)|(\s+$)", "", html, flags=re.MULTILINE) #+ "\n"
with open(fname, "wb") as fout:
fout.write(html.encode('ascii', 'xmlcharrefreplace'))
diff --git a/tests/farm/html/gold_other/blah_blah_other_py.html b/tests/farm/html/gold_other/blah_blah_other_py.html
index 4beb2a07..17b7ed3d 100644
--- a/tests/farm/html/gold_other/blah_blah_other_py.html
+++ b/tests/farm/html/gold_other/blah_blah_other_py.html
@@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=emulateIE7" />
- <title>Coverage for /Users/ned/coverage/trunk/tests/farm/html/othersrc/other.py: 100%</title>
+ <title>Coverage for TEST_TMPDIR/othersrc/other.py: 100%</title>
<link rel="stylesheet" href="style.css" type="text/css">
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.hotkeys.js"></script>
@@ -16,7 +16,7 @@
<body class="pyfile">
<div id="header">
<div class="content">
- <h1>Coverage for <b>/Users/ned/coverage/trunk/tests/farm/html/othersrc/other.py</b> :
+ <h1>Coverage for <b>TEST_TMPDIR/othersrc/other.py</b> :
<span class="pc_cov">100%</span>
</h1>
<img id="keyboard_icon" src="keybd_closed.png" alt="Show keyboard shortcuts" />
diff --git a/tests/farm/html/gold_other/index.html b/tests/farm/html/gold_other/index.html
index 27c194cf..486506f6 100644
--- a/tests/farm/html/gold_other/index.html
+++ b/tests/farm/html/gold_other/index.html
@@ -60,7 +60,7 @@
</tfoot>
<tbody>
<tr class="file">
- <td class="name left"><a href="_Users_ned_coverage_trunk_tests_farm_html_othersrc_other_py.html">/Users/ned/coverage/trunk/tests/farm/html/othersrc/other.py</a></td>
+ <td class="name left"><a href="_TEST_TMPDIR_othersrc_other_py.html">TEST_TMPDIR/othersrc/other.py</a></td>
<td>1</td>
<td>0</td>
<td>0</td>
diff --git a/tests/goldtest.py b/tests/goldtest.py
index 8f24f239..af471a14 100644
--- a/tests/goldtest.py
+++ b/tests/goldtest.py
@@ -8,13 +8,17 @@ import sys
from unittest_mixins import change_dir # pylint: disable=unused-import
-from tests.coveragetest import CoverageTest
+from tests.coveragetest import CoverageTest, TESTS_DIR
from tests.test_farm import clean
# Import helpers, eventually test_farm.py will go away.
from tests.test_farm import ( # pylint: disable=unused-import
compare, contains, doesnt_contain, contains_any,
)
+def gold_path(path):
+ """Get a path to a gold file for comparison."""
+ return os.path.join(TESTS_DIR, "farm", path)
+
class CoverageGoldTest(CoverageTest):
"""A test based on gold files."""
diff --git a/tests/test_html.py b/tests/test_html.py
index 9706cd33..d872c1b4 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -20,7 +20,7 @@ import coverage.html
from coverage.misc import CoverageException, NotPython, NoSource
from tests.coveragetest import CoverageTest, TESTS_DIR
-from tests.goldtest import CoverageGoldTest
+from tests.goldtest import gold_path
from tests.goldtest import change_dir, compare, contains, doesnt_contain, contains_any
@@ -579,6 +579,8 @@ def compare_html(dir1, dir2):
(r'/Users/ned/coverage/trunk/tests', 'TESTS_DIR'),
(flat_rootname(unicode_class(TESTS_DIR)), '_TESTS_DIR'),
(flat_rootname(u'/Users/ned/coverage/trunk/tests'), '_TESTS_DIR'),
+ (re.escape(os.getcwd()), 'TEST_TMPDIR'),
+ (flat_rootname(unicode_class(os.getcwd())), '_TEST_TMPDIR'),
]
if env.WINDOWS:
# For file paths...
@@ -586,25 +588,32 @@ def compare_html(dir1, dir2):
return compare(dir1, dir2, file_pattern="*.html", scrubs=scrubs)
-class HtmlGoldTests(CoverageGoldTest):
+class HtmlGoldTests(CoverageTest):
"""Tests of HTML reporting that use gold files."""
- root_dir = 'tests/farm/html'
-
def test_a(self):
- self.output_dir("out/a")
+ self.make_file("a.py", """\
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
- with change_dir("src"):
- # pylint: disable=import-error
- cov = coverage.Coverage()
- cov.start()
- import a # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(a, directory='../out/a')
+ # A test file for HTML reporting by coverage.py.
- compare_html("gold_a", "out/a")
+ if 1 < 2:
+ # Needed a < to look at HTML entities.
+ a = 3
+ else:
+ a = 4
+ """)
+
+ cov = coverage.Coverage()
+ cov.start()
+ import a # pragma: nested # pylint: disable=import-error
+ cov.stop() # pragma: nested
+ cov.html_report(a, directory='out')
+
+ compare_html("out", gold_path("html/gold_a"))
contains(
- "out/a/a_py.html",
+ "out/a_py.html",
('<span class="key">if</span> <span class="num">1</span> '
'<span class="op">&lt;</span> <span class="num">2</span>'),
(' <span class="nam">a</span> '
@@ -612,26 +621,57 @@ class HtmlGoldTests(CoverageGoldTest):
'<span class="pc_cov">67%</span>',
)
contains(
- "out/a/index.html",
+ "out/index.html",
'<a href="a_py.html">a.py</a>',
'<span class="pc_cov">67%</span>',
'<td class="right" data-ratio="2 3">67%</td>',
)
def test_b_branch(self):
- self.output_dir("out/b_branch")
+ self.make_file("b.py", """\
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+ # A test file for HTML reporting by coverage.py.
+
+ def one(x):
+ # This will be a branch that misses the else.
+ if x < 2:
+ a = 3
+ else:
+ a = 4
+
+ one(1)
+
+ def two(x):
+ # A missed else that branches to "exit"
+ if x:
+ a = 5
+
+ two(1)
+
+ def three():
+ try:
+ # This if has two branches, *neither* one taken.
+ if name_error_this_variable_doesnt_exist:
+ a = 1
+ else:
+ a = 2
+ except:
+ pass
+
+ three()
+ """)
- with change_dir("src"):
- # pylint: disable=import-error
- cov = coverage.Coverage(branch=True)
- cov.start()
- import b # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(b, directory="../out/b_branch")
+ cov = coverage.Coverage(branch=True)
+ cov.start()
+ import b # pragma: nested # pylint: disable=import-error
+ cov.stop() # pragma: nested
+ cov.html_report(b, directory="out")
- compare_html("gold_b_branch", "out/b_branch")
+ compare_html("out", gold_path("html/gold_b_branch"))
contains(
- "out/b_branch/b_py.html",
+ "out/b_py.html",
('<span class="key">if</span> <span class="nam">x</span> '
'<span class="op">&lt;</span> <span class="num">2</span>'),
(' <span class="nam">a</span> <span class="op">=</span> '
@@ -652,126 +692,211 @@ class HtmlGoldTests(CoverageGoldTest):
'because the condition on line 25 was never false</span>'),
)
contains(
- "out/b_branch/index.html",
+ "out/index.html",
'<a href="b_py.html">b.py</a>',
'<span class="pc_cov">70%</span>',
'<td class="right" data-ratio="16 23">70%</td>',
)
def test_bom(self):
- self.output_dir("out/bom")
+ self.make_file("bom.py", bytes=b"""\
+\xef\xbb\xbf# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
- with change_dir("src"):
- # It's important that the source file really have a BOM, which can
- # get lost, so check that it's really there.
- with open("bom.py", "rb") as f:
- first_three = f.read(3)
- assert first_three == b"\xef\xbb\xbf"
-
- # pylint: disable=import-error
- cov = coverage.Coverage()
- cov.start()
- import bom # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(bom, directory="../out/bom")
+# A Python source file in utf-8, with BOM.
+math = "3\xc3\x974 = 12, \xc3\xb72 = 6\xc2\xb10"
+
+import sys
+
+if sys.version_info >= (3, 0):
+ assert len(math) == 18
+ assert len(math.encode('utf-8')) == 21
+else:
+ assert len(math) == 21
+ assert len(math.decode('utf-8')) == 18
+""".replace(b"\n", b"\r\n"))
+
+ # It's important that the source file really have a BOM, which can
+ # get lost, so check that it's really there, and that we have \r\n
+ # line endings.
+ with open("bom.py", "rb") as f:
+ data = f.read()
+ assert data[:3] == b"\xef\xbb\xbf"
+ assert data.count(b"\r\n") == 14
- compare_html("gold_bom", "out/bom")
+ cov = coverage.Coverage()
+ cov.start()
+ import bom # pragma: nested # pylint: disable=import-error
+ cov.stop() # pragma: nested
+ cov.html_report(bom, directory="out")
+
+ compare_html("out", gold_path("html/gold_bom"))
contains(
- "out/bom/bom_py.html",
+ "out/bom_py.html",
'<span class="str">"3&#215;4 = 12, &#247;2 = 6&#177;0"</span>',
)
def test_isolatin1(self):
- self.output_dir("out/isolatin1")
+ self.make_file("isolatin1.py", bytes=b"""\
+# -*- coding: iso8859-1 -*-
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
- with change_dir("src"):
- # pylint: disable=import-error
- cov = coverage.Coverage()
- cov.start()
- import isolatin1 # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(isolatin1, directory="../out/isolatin1")
+# A Python source file in another encoding.
- compare_html("gold_isolatin1", "out/isolatin1")
+math = "3\xd74 = 12, \xf72 = 6\xb10"
+assert len(math) == 18
+""")
+
+ cov = coverage.Coverage()
+ cov.start()
+ import isolatin1 # pragma: nested # pylint: disable=import-error
+ cov.stop() # pragma: nested
+ cov.html_report(isolatin1, directory="out")
+
+ compare_html("out", gold_path("html/gold_isolatin1"))
contains(
- "out/isolatin1/isolatin1_py.html",
+ "out/isolatin1_py.html",
'<span class="str">"3&#215;4 = 12, &#247;2 = 6&#177;0"</span>',
)
+ def make_main_etc(self):
+ self.make_file("main.py", """\
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+ import m1
+ import m2
+ import m3
+
+ a = 5
+ b = 6
+
+ assert m1.m1a == 1
+ assert m2.m2a == 1
+ assert m3.m3a == 1
+ """)
+ self.make_file("m1.py", """\
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+ m1a = 1
+ m1b = 2
+ """)
+ self.make_file("m2.py", """\
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+ m2a = 1
+ m2b = 2
+ """)
+ self.make_file("m3.py", """\
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+ m3a = 1
+ m3b = 2
+ """)
+
def test_omit_1(self):
- self.output_dir("out/omit_1")
+ self.make_main_etc()
- with change_dir("src"):
- # pylint: disable=import-error
- cov = coverage.Coverage(include=["./*"])
- cov.start()
- import main # pragma: nested # pylint: disable=unused-variable
- cov.stop() # pragma: nested
- cov.html_report(directory="../out/omit_1")
+ cov = coverage.Coverage(include=["./*"])
+ cov.start()
+ import main # pragma: nested # pylint: disable=unused-variable, import-error
+ cov.stop() # pragma: nested
+ cov.html_report(directory="out")
- compare_html("gold_omit_1", "out/omit_1")
+ compare_html("out", gold_path("html/gold_omit_1"))
def test_omit_2(self):
- self.output_dir("out/omit_2")
+ self.make_main_etc()
- with change_dir("src"):
- # pylint: disable=import-error
- cov = coverage.Coverage(include=["./*"])
- cov.start()
- import main # pragma: nested # pylint: disable=unused-variable
- cov.stop() # pragma: nested
- cov.html_report(directory="../out/omit_2", omit=["m1.py"])
+ cov = coverage.Coverage(include=["./*"])
+ cov.start()
+ import main # pragma: nested # pylint: disable=unused-variable, import-error
+ cov.stop() # pragma: nested
+ cov.html_report(directory="out", omit=["m1.py"])
- compare_html("gold_omit_2", "out/omit_2")
+ compare_html("out", gold_path("html/gold_omit_2"))
def test_omit_3(self):
- self.output_dir("out/omit_3")
+ self.make_main_etc()
- with change_dir("src"):
- # pylint: disable=import-error
- cov = coverage.Coverage(include=["./*"])
- cov.start()
- import main # pragma: nested # pylint: disable=unused-variable
- cov.stop() # pragma: nested
- cov.html_report(directory="../out/omit_3", omit=["m1.py", "m2.py"])
+ cov = coverage.Coverage(include=["./*"])
+ cov.start()
+ import main # pragma: nested # pylint: disable=unused-variable, import-error
+ cov.stop() # pragma: nested
+ cov.html_report(directory="out", omit=["m1.py", "m2.py"])
- compare_html("gold_omit_3", "out/omit_3")
+ compare_html("out", gold_path("html/gold_omit_3"))
def test_omit_4(self):
- self.output_dir("out/omit_4")
+ self.make_main_etc()
+ self.make_file("omit4.ini", """\
+ [report]
+ omit = m2.py
+ """)
- with change_dir("src"):
- # pylint: disable=import-error
- cov = coverage.Coverage(config_file="omit4.ini", include=["./*"])
- cov.start()
- import main # pragma: nested # pylint: disable=unused-variable
- cov.stop() # pragma: nested
- cov.html_report(directory="../out/omit_4")
+ cov = coverage.Coverage(config_file="omit4.ini", include=["./*"])
+ cov.start()
+ import main # pragma: nested # pylint: disable=unused-variable, import-error
+ cov.stop() # pragma: nested
+ cov.html_report(directory="out")
- compare_html("gold_omit_4", "out/omit_4")
+ compare_html("out", gold_path("html/gold_omit_4"))
def test_omit_5(self):
- self.output_dir("out/omit_5")
+ self.make_main_etc()
+ self.make_file("omit5.ini", """\
+ [report]
+ omit =
+ fooey
+ gooey, m[23]*, kablooey
+ helloworld
+
+ [html]
+ directory = out/omit_5
+ """)
- with change_dir("src"):
- # pylint: disable=import-error
- cov = coverage.Coverage(config_file="omit5.ini", include=["./*"])
- cov.start()
- import main # pragma: nested # pylint: disable=unused-variable
- cov.stop() # pragma: nested
- cov.html_report()
+ cov = coverage.Coverage(config_file="omit5.ini", include=["./*"])
+ cov.start()
+ import main # pragma: nested # pylint: disable=unused-variable, import-error
+ cov.stop() # pragma: nested
+ cov.html_report()
- compare_html("gold_omit_5", "out/omit_5")
+ compare_html("out/omit_5", gold_path("html/gold_omit_5"))
def test_other(self):
- self.output_dir("out/other")
+ self.make_file("src/here.py", """\
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+ # A test file for HTML reporting by coverage.py.
+
+ import other
+
+ if 1 < 2:
+ h = 3
+ else:
+ h = 4
+ """)
+ self.make_file("othersrc/other.py", """\
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+ # A file in another directory. We're checking that it ends up in the
+ # HTML report.
+
+ print("This is the other src!")
+ """)
with change_dir("src"):
- # pylint: disable=import-error
+ sys.path.insert(0, "") # pytest sometimes has this, sometimes not!?
sys.path.insert(0, "../othersrc")
cov = coverage.Coverage(include=["./*", "../othersrc/*"])
cov.start()
- import here # pragma: nested # pylint: disable=unused-variable
+ import here # pragma: nested # pylint: disable=unused-variable, import-error
cov.stop() # pragma: nested
cov.html_report(directory="../out/other")
@@ -779,7 +904,7 @@ class HtmlGoldTests(CoverageGoldTest):
for p in glob.glob("out/other/*_other_py.html"):
os.rename(p, "out/other/blah_blah_other_py.html")
- compare_html("gold_other", "out/other")
+ compare_html("out/other", gold_path("html/gold_other"))
contains(
"out/other/index.html",
'<a href="here_py.html">here.py</a>',
@@ -787,19 +912,53 @@ class HtmlGoldTests(CoverageGoldTest):
)
def test_partial(self):
- self.output_dir("out/partial")
+ self.make_file("partial.py", """\
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
- with change_dir("src"):
- # pylint: disable=import-error
- cov = coverage.Coverage(config_file="partial.ini")
- cov.start()
- import partial # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(partial, directory="../out/partial")
+ # partial branches and excluded lines
+
+ a = 6
+
+ while True:
+ break
+
+ while 1:
+ break
+
+ while a: # pragma: no branch
+ break
+
+ if 0:
+ never_happen()
+
+ if 1:
+ a = 21
- compare_html("gold_partial", "out/partial")
+ if a == 23:
+ raise AssertionError("Can't")
+ """)
+ self.make_file("partial.ini", """\
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+ [run]
+ branch = True
+
+ [report]
+ exclude_lines =
+ raise AssertionError
+ """)
+
+ cov = coverage.Coverage(config_file="partial.ini")
+ cov.start()
+ import partial # pragma: nested # pylint: disable=import-error
+ cov.stop() # pragma: nested
+ cov.html_report(partial, directory="out")
+
+ compare_html("out", gold_path("html/gold_partial"))
contains(
- "out/partial/partial_py.html",
+ "out/partial_py.html",
'<p id="t8" class="stm run hide_run">',
'<p id="t11" class="stm run hide_run">',
'<p id="t14" class="stm run hide_run">',
@@ -809,29 +968,40 @@ class HtmlGoldTests(CoverageGoldTest):
'<p id="t24" class="exc">',
)
contains(
- "out/partial/index.html",
+ "out/index.html",
'<a href="partial_py.html">partial.py</a>',
)
contains(
- "out/partial/index.html",
+ "out/index.html",
'<span class="pc_cov">100%</span>'
)
def test_styled(self):
- self.output_dir("out/styled")
+ self.make_file("a.py", """\
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
- with change_dir("src"):
- # pylint: disable=import-error
- cov = coverage.Coverage()
- cov.start()
- import a # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(a, directory="../out/styled", extra_css="extra.css")
+ # A test file for HTML reporting by coverage.py.
+
+ if 1 < 2:
+ # Needed a < to look at HTML entities.
+ a = 3
+ else:
+ a = 4
+ """)
+
+ self.make_file("extra.css", "/* Doesn't matter what goes in here, it gets copied. */")
- compare_html("gold_styled", "out/styled")
- compare("gold_styled", "out/styled", size_within=10, file_pattern="*.css")
+ cov = coverage.Coverage()
+ cov.start()
+ import a # pragma: nested # pylint: disable=import-error
+ cov.stop() # pragma: nested
+ cov.html_report(a, directory="out", extra_css="extra.css")
+
+ compare_html("out", gold_path("html/gold_styled"))
+ compare("out", gold_path("html/gold_styled"), size_within=10, file_pattern="*.css")
contains(
- "out/styled/a_py.html",
+ "out/a_py.html",
'<link rel="stylesheet" href="extra.css" type="text/css">',
('<span class="key">if</span> <span class="num">1</span> '
'<span class="op">&lt;</span> <span class="num">2</span>'),
@@ -840,55 +1010,75 @@ class HtmlGoldTests(CoverageGoldTest):
'<span class="pc_cov">67%</span>'
)
contains(
- "out/styled/index.html",
+ "out/index.html",
'<link rel="stylesheet" href="extra.css" type="text/css">',
'<a href="a_py.html">a.py</a>',
'<span class="pc_cov">67%</span>'
)
def test_tabbed(self):
- self.output_dir("out/tabbed")
+ # The file contents would look like this with 8-space tabs:
+ # x = 1
+ # if x:
+ # a = "tabbed" # aligned comments
+ # if x: # look nice
+ # b = "no spaces" # when they
+ # c = "done" # line up.
+ self.make_file("tabbed.py", """\
+ x = 1
+ if x:
+ \ta = "Tabbed"\t\t\t\t# Aligned comments
+ \tif x:\t\t\t\t\t# look nice
+ \t\tb = "No spaces"\t\t\t# when they
+ \tc = "Done"\t\t\t\t# line up.
+ """)
- with change_dir("src"):
- # pylint: disable=import-error
- cov = coverage.Coverage()
- cov.start()
- import tabbed # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(tabbed, directory="../out/tabbed")
+ cov = coverage.Coverage()
+ cov.start()
+ import tabbed # pragma: nested # pylint: disable=import-error
+ cov.stop() # pragma: nested
+ cov.html_report(tabbed, directory="out")
# Editors like to change things, make sure our source file still has tabs.
- contains("src/tabbed.py", "\tif x:\t\t\t\t\t# look nice")
+ contains("tabbed.py", "\tif x:\t\t\t\t\t# look nice")
contains(
- "out/tabbed/tabbed_py.html",
+ "out/tabbed_py.html",
'> <span class="key">if</span> '
'<span class="nam">x</span><span class="op">:</span>'
' '
'<span class="com"># look nice</span>'
)
- doesnt_contain("out/tabbed/tabbed_py.html", "\t")
+ doesnt_contain("out/tabbed_py.html", "\t")
def test_unicode(self):
- self.output_dir("out/unicode")
+ self.make_file("unicode.py", """\
+ # -*- coding: utf-8 -*-
+ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
- with change_dir("src"):
- # pylint: disable=import-error, redefined-builtin
- cov = coverage.Coverage()
- cov.start()
- import unicode # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(unicode, directory="../out/unicode")
+ # A Python source file with exotic characters.
+
+ upside_down = "ʎd˙ǝbɐɹǝʌoɔ"
+ surrogate = "db40,dd00: x󠄀"
+ """)
+
+ # pylint: disable=import-error, redefined-builtin
+ cov = coverage.Coverage()
+ cov.start()
+ import unicode # pragma: nested
+ cov.stop() # pragma: nested
+ cov.html_report(unicode, directory="out")
- compare_html("gold_unicode", "out/unicode")
+ compare_html("out", gold_path("html/gold_unicode"))
contains(
- "out/unicode/unicode_py.html",
+ "out/unicode_py.html",
'<span class="str">"&#654;d&#729;&#477;b&#592;&#633;&#477;&#652;o&#596;"</span>',
)
contains_any(
- "out/unicode/unicode_py.html",
+ "out/unicode_py.html",
'<span class="str">"db40,dd00: x&#56128;&#56576;"</span>',
'<span class="str">"db40,dd00: x&#917760;"</span>',
)
diff --git a/tests/test_xml.py b/tests/test_xml.py
index dd2de007..65c1a48b 100644
--- a/tests/test_xml.py
+++ b/tests/test_xml.py
@@ -12,8 +12,8 @@ import coverage
from coverage.backward import import_local_file
from coverage.files import abs_file
-from tests.coveragetest import CoverageTest, TESTS_DIR
-from tests.goldtest import change_dir, compare
+from tests.coveragetest import CoverageTest
+from tests.goldtest import change_dir, compare, gold_path
from tests.helpers import re_line, re_lines
@@ -309,9 +309,6 @@ def clean(text, scrub=None):
return text
-def farm_dir(path):
- return os.path.join(TESTS_DIR, "farm", path)
-
class XmlGoldTest(CoverageTest):
"""Tests of XML reporting that use gold files."""
@@ -331,7 +328,7 @@ class XmlGoldTest(CoverageTest):
cov.xml_report(a, outfile="coverage.xml")
source_path = coverage.files.relative_directory().rstrip(r"\/")
- compare(".", farm_dir("html/gold_x_xml"), left_extra=True, scrubs=[
+ compare(".", gold_path("html/gold_x_xml"), left_extra=True, scrubs=[
(r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
(r' version="[-.\w]+"', ' version="VERSION"'),
(r'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_path),
@@ -360,7 +357,7 @@ class XmlGoldTest(CoverageTest):
cov.xml_report(a)
source_path = coverage.files.relative_directory().rstrip(r"\/")
- compare("xml_2", farm_dir("html/gold_x_xml"), scrubs=[
+ compare("xml_2", gold_path("html/gold_x_xml"), scrubs=[
(r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
(r' version="[-.\w]+"', ' version="VERSION"'),
(r'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_path),
@@ -385,7 +382,7 @@ class XmlGoldTest(CoverageTest):
cov.xml_report(y, outfile="y_xml_branch/coverage.xml")
source_path = coverage.files.relative_directory().rstrip(r"\/")
- compare("y_xml_branch", farm_dir("html/gold_y_xml_branch"), scrubs=[
+ compare("y_xml_branch", gold_path("html/gold_y_xml_branch"), scrubs=[
(r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
(r' version="[-.\w]+"', ' version="VERSION"'),
(r'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_path),
diff --git a/tox.ini b/tox.ini
index bbc00f3a..f6917f8b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -17,7 +17,7 @@ deps =
setuptools==40.0.0
mock==2.0.0
PyContracts==1.8.3
- unittest-mixins==1.5
+ unittest-mixins==1.6
#-e/Users/ned/unittest_mixins
# gevent 1.3 causes a failure: https://bitbucket.org/ned/coveragepy/issues/663/gevent-132-on-windows-fails
py{27,34,35,36}: gevent==1.2.2