summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-08-31 07:51:51 -0400
committerNed Batchelder <ned@nedbatchelder.com>2015-08-31 07:51:51 -0400
commit5dd82ca787d03339288c22c9ac4bc51895ea522c (patch)
treea89343caf78174f2069ed4b7da587e10738487f4 /tests
parent8d67c509f0a1dfaa2fb7fe10ced8b9c4b6642f2b (diff)
downloadpython-coveragepy-5dd82ca787d03339288c22c9ac4bc51895ea522c.tar.gz
Convert farm html tests to goldtests.
Diffstat (limited to 'tests')
-rw-r--r--tests/farm/html/run_a.py29
-rw-r--r--tests/farm/html/run_a_xml_1.py25
-rw-r--r--tests/farm/html/run_a_xml_2.py25
-rw-r--r--tests/farm/html/run_b_branch.py32
-rw-r--r--tests/farm/html/run_bom.py24
-rw-r--r--tests/farm/html/run_isolatin1.py24
-rw-r--r--tests/farm/html/run_omit_1.py15
-rw-r--r--tests/farm/html/run_omit_2.py15
-rw-r--r--tests/farm/html/run_omit_3.py15
-rw-r--r--tests/farm/html/run_omit_4.py15
-rw-r--r--tests/farm/html/run_omit_5.py15
-rw-r--r--tests/farm/html/run_other.py29
-rw-r--r--tests/farm/html/run_partial.py34
-rw-r--r--tests/farm/html/run_styled.py31
-rw-r--r--tests/farm/html/run_tabbed.py27
-rw-r--r--tests/farm/html/run_unicode.py27
-rw-r--r--tests/farm/html/run_y_xml_branch.py25
-rw-r--r--tests/farm/html/src/omit5.ini2
-rw-r--r--tests/farm/html/src/run_a_xml_2.ini2
-rw-r--r--tests/goldtest.py42
-rw-r--r--tests/test_html.py301
-rw-r--r--tests/test_xml.py62
22 files changed, 375 insertions, 441 deletions
diff --git a/tests/farm/html/run_a.py b/tests/farm/html/run_a.py
deleted file mode 100644
index 1ec6220..0000000
--- a/tests/farm/html/run_a.py
+++ /dev/null
@@ -1,29 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-def html_it():
- """Run coverage.py and make an HTML report for a."""
- import coverage
- cov = coverage.Coverage()
- cov.start()
- import a # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(a, directory="../html_a")
-
-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("gold_a", "html_a", size_within=10, file_pattern="*.html")
-contains("html_a/a_py.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>',
- '<span class="pc_cov">67%</span>'
- )
-contains("html_a/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>',
- )
-
-clean("html_a")
diff --git a/tests/farm/html/run_a_xml_1.py b/tests/farm/html/run_a_xml_1.py
deleted file mode 100644
index 5bf2f46..0000000
--- a/tests/farm/html/run_a_xml_1.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-source_path = None
-
-def html_it():
- """Run coverage.py and make an XML report for a."""
- import coverage, coverage.files
- cov = coverage.Coverage()
- cov.start()
- import a # pragma: nested
- cov.stop() # pragma: nested
- cov.xml_report(a, outfile="../xml_1/coverage.xml")
- global source_path
- source_path = coverage.files.relative_directory().rstrip('/')
-
-runfunc(html_it, rundir="src")
-
-compare("gold_x_xml", "xml_1", scrubs=[
- (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
- (r' version="[-.\w]+"', ' version="VERSION"'),
- (r'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_path),
- (r'/coverage.readthedocs.org/?[-.\w/]*', '/coverage.readthedocs.org/VER'),
- ])
-clean("xml_1")
diff --git a/tests/farm/html/run_a_xml_2.py b/tests/farm/html/run_a_xml_2.py
deleted file mode 100644
index 5d8778f..0000000
--- a/tests/farm/html/run_a_xml_2.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-source_path = None
-
-def html_it():
- """Run coverage.py and make an XML report for a."""
- import coverage, coverage.files
- cov = coverage.Coverage(config_file="run_a_xml_2.ini")
- cov.start()
- import a # pragma: nested
- cov.stop() # pragma: nested
- cov.xml_report(a)
- global source_path
- source_path = coverage.files.relative_directory().rstrip('/')
-
-runfunc(html_it, rundir="src")
-
-compare("gold_x_xml", "xml_2", scrubs=[
- (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
- (r' version="[-.\w]+"', ' version="VERSION"'),
- (r'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_path),
- (r'/coverage.readthedocs.org/?[-.\w/]*', '/coverage.readthedocs.org/VER'),
- ])
-clean("xml_2")
diff --git a/tests/farm/html/run_b_branch.py b/tests/farm/html/run_b_branch.py
deleted file mode 100644
index 382e311..0000000
--- a/tests/farm/html/run_b_branch.py
+++ /dev/null
@@ -1,32 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-def html_it():
- """Run coverage.py with branches and make an HTML report for b."""
- import coverage
- cov = coverage.Coverage(branch=True)
- cov.start()
- import b # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(b, directory="../html_b_branch")
-
-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("gold_b_branch", "html_b_branch", size_within=10, file_pattern="*.html")
-contains("html_b_branch/b_py.html",
- '<span class="key">if</span> <span class="nam">x</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>',
- '<span class="pc_cov">70%</span>',
- '<span class="annotate" title="Line 8 was executed, but never jumped to line 11">8&#x202F;&#x219B;&#x202F;11 [?]</span>',
- '<span class="annotate" title="Line 17 was executed, but never jumped to the function exit">17&#x202F;&#x219B;&#x202F;exit [?]</span>',
- '<span class="annotate" title="Line 25 was executed, but never jumped to line 26 or line 28">25&#x202F;&#x219B;&#x202F;26,&nbsp;&nbsp; 25&#x202F;&#x219B;&#x202F;28 [?]</span>',
- )
-contains("html_b_branch/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>',
- )
-
-clean("html_b_branch")
diff --git a/tests/farm/html/run_bom.py b/tests/farm/html/run_bom.py
deleted file mode 100644
index a34fab9..0000000
--- a/tests/farm/html/run_bom.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-import sys
-
-def html_it():
- """Run coverage.py and make an HTML report for bom.py."""
- import coverage
- cov = coverage.Coverage()
- cov.start()
- import bom # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(bom, directory="../html_bom")
-
-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("gold_bom", "html_bom", size_within=10, file_pattern="*.html")
-contains("html_bom/bom_py.html",
- '<span class="str">&quot;3&#215;4 = 12, &#247;2 = 6&#177;0&quot;</span>',
- )
-
-clean("html_bom")
diff --git a/tests/farm/html/run_isolatin1.py b/tests/farm/html/run_isolatin1.py
deleted file mode 100644
index 6729a27..0000000
--- a/tests/farm/html/run_isolatin1.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-import sys
-
-def html_it():
- """Run coverage.py and make an HTML report for isolatin1.py."""
- import coverage
- cov = coverage.Coverage()
- cov.start()
- import isolatin1 # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(isolatin1, directory="../html_isolatin1")
-
-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("gold_isolatin1", "html_isolatin1", size_within=10, file_pattern="*.html")
-contains("html_isolatin1/isolatin1_py.html",
- '<span class="str">&quot;3&#215;4 = 12, &#247;2 = 6&#177;0&quot;</span>',
- )
-
-clean("html_isolatin1")
diff --git a/tests/farm/html/run_omit_1.py b/tests/farm/html/run_omit_1.py
deleted file mode 100644
index 137d37c..0000000
--- a/tests/farm/html/run_omit_1.py
+++ /dev/null
@@ -1,15 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-def html_it():
- """Run coverage.py and make an HTML report for main."""
- import coverage
- cov = coverage.Coverage(include=["./*"])
- cov.start()
- import main # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(directory="../html_omit_1")
-
-runfunc(html_it, rundir="src")
-compare("gold_omit_1", "html_omit_1", size_within=10, file_pattern="*.html")
-clean("html_omit_1")
diff --git a/tests/farm/html/run_omit_2.py b/tests/farm/html/run_omit_2.py
deleted file mode 100644
index dd021b9..0000000
--- a/tests/farm/html/run_omit_2.py
+++ /dev/null
@@ -1,15 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-def html_it():
- """Run coverage.py and make an HTML report for main."""
- import coverage
- cov = coverage.Coverage(include=["./*"])
- cov.start()
- import main # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(directory="../html_omit_2", omit=["m1.py"])
-
-runfunc(html_it, rundir="src")
-compare("gold_omit_2", "html_omit_2", size_within=10, file_pattern="*.html")
-clean("html_omit_2")
diff --git a/tests/farm/html/run_omit_3.py b/tests/farm/html/run_omit_3.py
deleted file mode 100644
index 96ed082..0000000
--- a/tests/farm/html/run_omit_3.py
+++ /dev/null
@@ -1,15 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-def html_it():
- """Run coverage.py and make an HTML report for main."""
- import coverage
- cov = coverage.Coverage(include=["./*"])
- cov.start()
- import main # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(directory="../html_omit_3", omit=["m1.py", "m2.py"])
-
-runfunc(html_it, rundir="src")
-compare("gold_omit_3", "html_omit_3", size_within=10, file_pattern="*.html")
-clean("html_omit_3")
diff --git a/tests/farm/html/run_omit_4.py b/tests/farm/html/run_omit_4.py
deleted file mode 100644
index b212ef4..0000000
--- a/tests/farm/html/run_omit_4.py
+++ /dev/null
@@ -1,15 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-def html_it():
- """Run coverage.py and make an HTML report for main."""
- import coverage
- cov = coverage.Coverage(config_file="omit4.ini", include=["./*"])
- cov.start()
- import main # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(directory="../html_omit_4")
-
-runfunc(html_it, rundir="src")
-compare("gold_omit_4", "html_omit_4", size_within=10, file_pattern="*.html")
-clean("html_omit_4")
diff --git a/tests/farm/html/run_omit_5.py b/tests/farm/html/run_omit_5.py
deleted file mode 100644
index ed61d20..0000000
--- a/tests/farm/html/run_omit_5.py
+++ /dev/null
@@ -1,15 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-def html_it():
- """Run coverage.py and make an HTML report for main."""
- import coverage
- cov = coverage.Coverage(config_file="omit5.ini", include=["./*"])
- cov.start()
- import main # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report()
-
-runfunc(html_it, rundir="src")
-compare("gold_omit_5", "html_omit_5", size_within=10, file_pattern="*.html")
-clean("html_omit_5")
diff --git a/tests/farm/html/run_other.py b/tests/farm/html/run_other.py
deleted file mode 100644
index 92753d4..0000000
--- a/tests/farm/html/run_other.py
+++ /dev/null
@@ -1,29 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-def html_it():
- """Run coverage.py and make an HTML report for everything."""
- import coverage
- cov = coverage.Coverage(include=["./*", "../othersrc/*"])
- cov.start()
- import here # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(directory="../html_other")
-
-runfunc(html_it, rundir="src", addtopath="../othersrc")
-
-# Different platforms will name the "other" file differently. Rename it
-import os, glob
-
-for p in glob.glob("html_other/*_other_py.html"):
- os.rename(p, "html_other/blah_blah_other_py.html")
-
-# HTML files will change often. Check that the sizes are reasonable,
-# and check that certain key strings are in the output.
-compare("gold_other", "html_other", size_within=10, file_pattern="*.html")
-contains("html_other/index.html",
- '<a href="here_py.html">here.py</a>',
- 'other_py.html">', 'other.py</a>',
- )
-
-clean("html_other")
diff --git a/tests/farm/html/run_partial.py b/tests/farm/html/run_partial.py
deleted file mode 100644
index fedf708..0000000
--- a/tests/farm/html/run_partial.py
+++ /dev/null
@@ -1,34 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-import sys
-
-def html_it():
- """Run coverage.py and make an HTML report for partial."""
- import coverage
- cov = coverage.Coverage(branch=True)
- cov.start()
- import partial # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(partial, directory="../html_partial")
-
-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("gold_partial", "html_partial", size_within=10, file_pattern="*.html")
-contains("html_partial/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">',
- # The "if 0" and "if 1" statements are optimized away.
- '<p id="t17" class="pln">',
- )
-contains("html_partial/index.html",
- '<a href="partial_py.html">partial.py</a>',
- )
-contains("html_partial/index.html",
- '<span class="pc_cov">100%</span>'
- )
-
-clean("html_partial")
diff --git a/tests/farm/html/run_styled.py b/tests/farm/html/run_styled.py
deleted file mode 100644
index eeebfe6..0000000
--- a/tests/farm/html/run_styled.py
+++ /dev/null
@@ -1,31 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-def html_it():
- """Run coverage.py and make an HTML report for a."""
- import coverage
- cov = coverage.Coverage()
- cov.start()
- import a # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(a, directory="../html_styled", extra_css="extra.css")
-
-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("gold_styled", "html_styled", size_within=10, file_pattern="*.html")
-compare("gold_styled", "html_styled", size_within=10, file_pattern="*.css")
-contains("html_styled/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>',
- '&nbsp; &nbsp; <span class="nam">a</span> <span class="op">=</span> <span class="num">3</span>',
- '<span class="pc_cov">67%</span>'
- )
-contains("html_styled/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>'
- )
-
-clean("html_styled")
diff --git a/tests/farm/html/run_tabbed.py b/tests/farm/html/run_tabbed.py
deleted file mode 100644
index 6dacff5..0000000
--- a/tests/farm/html/run_tabbed.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-def html_it():
- """Run coverage.py and make an HTML report for tabbed."""
- import coverage
- cov = coverage.Coverage()
- cov.start()
- import tabbed # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(tabbed, directory="../html_tabbed")
-
-runfunc(html_it, rundir="src")
-
-# 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("html_tabbed/tabbed_py.html",
- '>&nbsp; &nbsp; &nbsp; &nbsp; <span class="key">if</span> '
- '<span class="nam">x</span><span class="op">:</span>'
- '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '
- '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; '
- '<span class="com"># look nice</span>'
- )
-
-doesnt_contain("html_tabbed/tabbed_py.html", "\t")
-clean("html_tabbed")
diff --git a/tests/farm/html/run_unicode.py b/tests/farm/html/run_unicode.py
deleted file mode 100644
index 888d7e5..0000000
--- a/tests/farm/html/run_unicode.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-def html_it():
- """Run coverage.py and make an HTML report for unicode.py."""
- import coverage
- cov = coverage.Coverage()
- cov.start()
- import unicode # pragma: nested
- cov.stop() # pragma: nested
- cov.html_report(unicode, directory="../html_unicode")
-
-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("gold_unicode", "html_unicode", size_within=10, file_pattern="*.html")
-contains("html_unicode/unicode_py.html",
- '<span class="str">&quot;&#654;d&#729;&#477;b&#592;&#633;&#477;&#652;o&#596;&quot;</span>',
- )
-
-contains_any("html_unicode/unicode_py.html",
- '<span class="str">&quot;db40,dd00: x&#56128;&#56576;&quot;</span>',
- '<span class="str">&quot;db40,dd00: x&#917760;&quot;</span>',
- )
-
-clean("html_unicode")
diff --git a/tests/farm/html/run_y_xml_branch.py b/tests/farm/html/run_y_xml_branch.py
deleted file mode 100644
index 921da9e..0000000
--- a/tests/farm/html/run_y_xml_branch.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
-
-source_path = None
-
-def xml_it():
- """Run coverage.py and make an XML report for y."""
- import coverage, coverage.files
- cov = coverage.Coverage(branch=True)
- cov.start()
- import y # pragma: nested
- cov.stop() # pragma: nested
- cov.xml_report(y, outfile="../xml_branch/coverage.xml")
- global source_path
- source_path = coverage.files.relative_directory().rstrip('/')
-
-runfunc(xml_it, rundir="src")
-
-compare("gold_y_xml_branch", "xml_branch", scrubs=[
- (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
- (r' version="[-.\w]+"', ' version="VERSION"'),
- (r'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_path),
- (r'/coverage.readthedocs.org/?[-.\w/]*', '/coverage.readthedocs.org/VER'),
- ])
-clean("xml_branch")
diff --git a/tests/farm/html/src/omit5.ini b/tests/farm/html/src/omit5.ini
index 3d8dbcf..3b6add2 100644
--- a/tests/farm/html/src/omit5.ini
+++ b/tests/farm/html/src/omit5.ini
@@ -8,4 +8,4 @@ omit =
helloworld
[html]
-directory = ../html_omit_5
+directory = ../out/omit_5
diff --git a/tests/farm/html/src/run_a_xml_2.ini b/tests/farm/html/src/run_a_xml_2.ini
index 5b5f18d..f632bd0 100644
--- a/tests/farm/html/src/run_a_xml_2.ini
+++ b/tests/farm/html/src/run_a_xml_2.ini
@@ -3,4 +3,4 @@
# Put all the XML output in xml_2
[xml]
-output = ../xml_2/coverage.xml
+output = ../out/xml_2/coverage.xml
diff --git a/tests/goldtest.py b/tests/goldtest.py
new file mode 100644
index 0000000..f3b3771
--- /dev/null
+++ b/tests/goldtest.py
@@ -0,0 +1,42 @@
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+
+"""A test base class for tests based on gold file comparison."""
+
+import os
+import sys
+
+from tests.coveragetest import CoverageTest
+
+from coverage.test_helpers import change_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,
+)
+
+
+class CoverageGoldTest(CoverageTest):
+ """A test based on gold files."""
+
+ run_in_temp_dir = False
+
+ def setUp(self):
+ super(CoverageGoldTest, self).setUp()
+ self.chdir(self.root_dir)
+ # Modules should be importable from the current directory.
+ sys.path.insert(0, '')
+
+ def output_dir(self, the_dir):
+ """Declare where the output directory is.
+
+ The output directory is deleted at the end of the test, unless the
+ COVERAGE_KEEP_OUTPUT environment variable is set.
+
+ """
+ self.addCleanup(self.cleanup_output_dir, the_dir)
+
+ def cleanup_output_dir(self, the_dir):
+ """Clean up the output directory of the test."""
+ if not os.environ.get("COVERAGE_KEEP_OUTPUT"): # pragma: partial
+ clean(the_dir)
diff --git a/tests/test_html.py b/tests/test_html.py
index 360f967..13fdf9b 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -5,15 +5,20 @@
"""Tests that HTML generation is awesome."""
import datetime
+import glob
+import os
import os.path
import re
import sys
import coverage
+import coverage.files
import coverage.html
from coverage.misc import CoverageException, NotPython, NoSource
from tests.coveragetest import CoverageTest
+from tests.goldtest import CoverageGoldTest
+from tests.goldtest import change_dir, compare, contains, doesnt_contain, contains_any
class HtmlTestHelpers(CoverageTest):
@@ -468,50 +473,282 @@ class HtmlStaticFileTest(CoverageTest):
cov.html_report()
-class CoverageGoldTest(CoverageTest):
-
- run_in_temp_dir = False
-
- def setUp(self):
- super(CoverageGoldTest, self).setUp()
- self.chdir(self.root_dir)
- # Modules should be importable from the current directory.
- sys.path.insert(0, '')
-
- def output_dir(self, the_dir):
- self.addCleanup(self.cleanup_output_dir, the_dir)
-
- def cleanup_output_dir(self, the_dir):
- if not os.environ.get("COVERAGE_KEEP_OUTPUT"):
- clean(the_dir)
-
-from coverage.test_helpers import change_dir
-from tests.test_farm import clean, compare, contains
-
class HtmlGoldTests(CoverageGoldTest):
root_dir = 'tests/farm/html'
def test_a(self):
- self.output_dir("html_a")
+ self.output_dir("out/a")
with change_dir("src"):
cov = coverage.Coverage()
cov.start()
- import a
- cov.stop()
- cov.html_report(a, directory='../html_a')
-
- compare("gold_a", "html_a", size_within=10, file_pattern="*.html")
- contains("html_a/a_py.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>',
+ import a # pragma: nested
+ cov.stop() # pragma: nested
+ cov.html_report(a, directory='../out/a')
+
+ compare("gold_a", "out/a", size_within=10, file_pattern="*.html")
+ contains(
+ "out/a/a_py.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>'),
'<span class="pc_cov">67%</span>',
)
- contains("html_a/index.html",
+ contains(
+ "out/a/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")
+
+ with change_dir("src"):
+ cov = coverage.Coverage(branch=True)
+ cov.start()
+ import b # pragma: nested
+ cov.stop() # pragma: nested
+ cov.html_report(b, directory="../out/b_branch")
+
+ compare("gold_b_branch", "out/b_branch", size_within=10, file_pattern="*.html")
+ contains(
+ "out/b_branch/b_py.html",
+ ('<span class="key">if</span> <span class="nam">x</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>'),
+ '<span class="pc_cov">70%</span>',
+ ('<span class="annotate" title="Line 8 was executed, but never jumped to line 11">'
+ '8&#x202F;&#x219B;&#x202F;11 [?]</span>'),
+ ('<span class="annotate" title="Line 17 was executed, but never jumped '
+ 'to the function exit">17&#x202F;&#x219B;&#x202F;exit [?]</span>'),
+ ('<span class="annotate" title="Line 25 was executed, but never jumped '
+ 'to line 26 or line 28">25&#x202F;&#x219B;&#x202F;26,&nbsp;&nbsp; '
+ '25&#x202F;&#x219B;&#x202F;28 [?]</span>'),
+ )
+ contains(
+ "out/b_branch/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")
+
+ with change_dir("src"):
+ cov = coverage.Coverage()
+ cov.start()
+ import bom # pragma: nested
+ cov.stop() # pragma: nested
+ cov.html_report(bom, directory="../out/bom")
+
+ compare("gold_bom", "out/bom", size_within=10, file_pattern="*.html")
+ contains(
+ "out/bom/bom_py.html",
+ '<span class="str">&quot;3&#215;4 = 12, &#247;2 = 6&#177;0&quot;</span>',
+ )
+
+ def test_isolatin1(self):
+ self.output_dir("out/isolatin1")
+
+ with change_dir("src"):
+ cov = coverage.Coverage()
+ cov.start()
+ import isolatin1 # pragma: nested
+ cov.stop() # pragma: nested
+ cov.html_report(isolatin1, directory="../out/isolatin1")
+
+ compare("gold_isolatin1", "out/isolatin1", size_within=10, file_pattern="*.html")
+ contains(
+ "out/isolatin1/isolatin1_py.html",
+ '<span class="str">&quot;3&#215;4 = 12, &#247;2 = 6&#177;0&quot;</span>',
+ )
+
+ def test_omit_1(self):
+ self.output_dir("out/omit_1")
+
+ with change_dir("src"):
+ cov = coverage.Coverage(include=["./*"])
+ cov.start()
+ import main # pragma: nested
+ cov.stop() # pragma: nested
+ cov.html_report(directory="../out/omit_1")
+
+ compare("gold_omit_1", "out/omit_1", size_within=10, file_pattern="*.html")
+
+ def test_omit_2(self):
+ self.output_dir("out/omit_2")
+
+ with change_dir("src"):
+ cov = coverage.Coverage(include=["./*"])
+ cov.start()
+ import main # pragma: nested
+ cov.stop() # pragma: nested
+ cov.html_report(directory="../out/omit_2", omit=["m1.py"])
+
+ compare("gold_omit_2", "out/omit_2", size_within=10, file_pattern="*.html")
+
+ def test_omit_3(self):
+ self.output_dir("out/omit_3")
+
+ with change_dir("src"):
+ cov = coverage.Coverage(include=["./*"])
+ cov.start()
+ import main # pragma: nested
+ cov.stop() # pragma: nested
+ cov.html_report(directory="../out/omit_3", omit=["m1.py", "m2.py"])
+
+ compare("gold_omit_3", "out/omit_3", size_within=10, file_pattern="*.html")
+
+ def test_omit_4(self):
+ self.output_dir("out/omit_4")
+
+ with change_dir("src"):
+ cov = coverage.Coverage(config_file="omit4.ini", include=["./*"])
+ cov.start()
+ import main # pragma: nested
+ cov.stop() # pragma: nested
+ cov.html_report(directory="../out/omit_4")
+
+ compare("gold_omit_4", "out/omit_4", size_within=10, file_pattern="*.html")
+
+ def test_omit_5(self):
+ self.output_dir("out/omit_5")
+
+ with change_dir("src"):
+ cov = coverage.Coverage(config_file="omit5.ini", include=["./*"])
+ cov.start()
+ import main # pragma: nested
+ cov.stop() # pragma: nested
+ cov.html_report()
+
+ compare("gold_omit_5", "out/omit_5", size_within=10, file_pattern="*.html")
+
+ def test_other(self):
+ self.output_dir("out/other")
+
+ with change_dir("src"):
+ sys.path.insert(0, "../othersrc")
+ cov = coverage.Coverage(include=["./*", "../othersrc/*"])
+ cov.start()
+ import here # pragma: nested
+ cov.stop() # pragma: nested
+ cov.html_report(directory="../out/other")
+
+ # Different platforms will name the "other" file differently. Rename it
+ for p in glob.glob("out/other/*_other_py.html"):
+ os.rename(p, "out/other/blah_blah_other_py.html")
+
+ compare("gold_other", "out/other", size_within=10, file_pattern="*.html")
+ contains(
+ "out/other/index.html",
+ '<a href="here_py.html">here.py</a>',
+ 'other_py.html">', 'other.py</a>',
+ )
+
+ def test_partial(self):
+ self.output_dir("out/partial")
+
+ with change_dir("src"):
+ cov = coverage.Coverage(branch=True)
+ cov.start()
+ import partial # pragma: nested
+ cov.stop() # pragma: nested
+ cov.html_report(partial, directory="../out/partial")
+
+ compare("gold_partial", "out/partial", size_within=10, file_pattern="*.html")
+ contains(
+ "out/partial/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">',
+ # The "if 0" and "if 1" statements are optimized away.
+ '<p id="t17" class="pln">',
+ )
+ contains(
+ "out/partial/index.html",
+ '<a href="partial_py.html">partial.py</a>',
+ )
+ contains(
+ "out/partial/index.html",
+ '<span class="pc_cov">100%</span>'
+ )
+
+ def test_styled(self):
+ self.output_dir("out/styled")
+
+ with change_dir("src"):
+ cov = coverage.Coverage()
+ cov.start()
+ import a # pragma: nested
+ cov.stop() # pragma: nested
+ cov.html_report(a, directory="../out/styled", extra_css="extra.css")
+
+ compare("gold_styled", "out/styled", size_within=10, file_pattern="*.html")
+ compare("gold_styled", "out/styled", size_within=10, file_pattern="*.css")
+ contains(
+ "out/styled/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>'),
+ ('&nbsp; &nbsp; <span class="nam">a</span> <span class="op">=</span> '
+ '<span class="num">3</span>'),
+ '<span class="pc_cov">67%</span>'
+ )
+ contains(
+ "out/styled/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")
+
+ with change_dir("src"):
+ cov = coverage.Coverage()
+ cov.start()
+ import tabbed # pragma: nested
+ cov.stop() # pragma: nested
+ cov.html_report(tabbed, directory="../out/tabbed")
+
+ # 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(
+ "out/tabbed/tabbed_py.html",
+ '>&nbsp; &nbsp; &nbsp; &nbsp; <span class="key">if</span> '
+ '<span class="nam">x</span><span class="op">:</span>'
+ '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '
+ '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; '
+ '<span class="com"># look nice</span>'
+ )
+
+ doesnt_contain("out/tabbed/tabbed_py.html", "\t")
+
+ def test_unicode(self):
+ self.output_dir("out/unicode")
+
+ with change_dir("src"):
+ cov = coverage.Coverage()
+ cov.start()
+ import unicode # pragma: nested
+ cov.stop() # pragma: nested
+ cov.html_report(unicode, directory="../out/unicode")
+
+ compare("gold_unicode", "out/unicode", size_within=10, file_pattern="*.html")
+ contains(
+ "out/unicode/unicode_py.html",
+ ('<span class="str">&quot;&#654;d&#729;&#477;b&#592;&#633;&#477;&#652;o&#596;&quot;'
+ '</span>'),
+ )
+
+ contains_any(
+ "out/unicode/unicode_py.html",
+ '<span class="str">&quot;db40,dd00: x&#56128;&#56576;&quot;</span>',
+ '<span class="str">&quot;db40,dd00: x&#917760;&quot;</span>',
+ )
diff --git a/tests/test_xml.py b/tests/test_xml.py
index 3806c58..e46e5d6 100644
--- a/tests/test_xml.py
+++ b/tests/test_xml.py
@@ -9,6 +9,8 @@ import re
import coverage
from tests.coveragetest import CoverageTest
+from tests.goldtest import CoverageGoldTest
+from tests.goldtest import change_dir, compare, contains
class XmlTestHelpers(CoverageTest):
@@ -252,3 +254,63 @@ def clean(text, scrub=None):
text = re.sub(r"(?m)^\s+", "", text)
text = re.sub(r"\\", "/", text)
return text
+
+
+class XmlGoldTest(CoverageGoldTest):
+
+ # TODO: this should move out of html.
+ root_dir = 'tests/farm/html'
+
+ def test_a_xml_1(self):
+ self.output_dir("out/xml_1")
+
+ with change_dir("src"):
+ cov = coverage.Coverage()
+ cov.start()
+ import a # pragma: nested
+ cov.stop() # pragma: nested
+ cov.xml_report(a, outfile="../out/xml_1/coverage.xml")
+ source_path = coverage.files.relative_directory().rstrip('/')
+
+ compare("gold_x_xml", "out/xml_1", scrubs=[
+ (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
+ (r' version="[-.\w]+"', ' version="VERSION"'),
+ (r'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_path),
+ (r'/coverage.readthedocs.org/?[-.\w/]*', '/coverage.readthedocs.org/VER'),
+ ])
+
+ def test_a_xml_2(self):
+ self.output_dir("out/xml_2")
+
+ with change_dir("src"):
+ cov = coverage.Coverage(config_file="run_a_xml_2.ini")
+ cov.start()
+ import a # pragma: nested
+ cov.stop() # pragma: nested
+ cov.xml_report(a)
+ source_path = coverage.files.relative_directory().rstrip('/')
+
+ compare("gold_x_xml", "out/xml_2", scrubs=[
+ (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
+ (r' version="[-.\w]+"', ' version="VERSION"'),
+ (r'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_path),
+ (r'/coverage.readthedocs.org/?[-.\w/]*', '/coverage.readthedocs.org/VER'),
+ ])
+
+ def test_y_xml_branch(self):
+ self.output_dir("out/y_xml_branch")
+
+ with change_dir("src"):
+ cov = coverage.Coverage(branch=True)
+ cov.start()
+ import y # pragma: nested
+ cov.stop() # pragma: nested
+ cov.xml_report(y, outfile="../out/y_xml_branch/coverage.xml")
+ source_path = coverage.files.relative_directory().rstrip('/')
+
+ compare("gold_y_xml_branch", "out/y_xml_branch", scrubs=[
+ (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
+ (r' version="[-.\w]+"', ' version="VERSION"'),
+ (r'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_path),
+ (r'/coverage.readthedocs.org/?[-.\w/]*', '/coverage.readthedocs.org/VER'),
+ ])