summaryrefslogtreecommitdiff
path: root/tests/test_html.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2013-09-28 21:31:37 -0400
committerNed Batchelder <ned@nedbatchelder.com>2013-09-28 21:31:37 -0400
commitb9f30deffb0bf011e1a2b8d2ffc4887b3893ea8b (patch)
tree599b9b2b149f4238f5732473fdfdda317c6f6de2 /tests/test_html.py
parentf360498ba0294dfef288f5fff0e8a3ba291881b2 (diff)
downloadpython-coveragepy-b9f30deffb0bf011e1a2b8d2ffc4887b3893ea8b.tar.gz
Search a list of places to find HTML report static files. #259.
Diffstat (limited to 'tests/test_html.py')
-rw-r--r--tests/test_html.py41
1 files changed, 39 insertions, 2 deletions
diff --git a/tests/test_html.py b/tests/test_html.py
index e44db97..e1d41d9 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -3,7 +3,8 @@
import os.path, re, sys
import coverage
-from coverage.misc import NotPython, NoSource
+import coverage.html
+from coverage.misc import CoverageException, NotPython, NoSource
from tests.coveragetest import CoverageTest
@@ -290,7 +291,43 @@ class HtmlTest(CoverageTest):
missing_file = os.path.join(self.temp_dir, "sub", "another.py")
missing_file = os.path.realpath(missing_file)
- self.assertRaisesRegexp(NoSource,
+ self.assertRaisesRegexp(
+ NoSource,
"(?i)No source for code: '%s'" % re.escape(missing_file),
cov.html_report
)
+
+class HtmlStaticFileTest(CoverageTest):
+ """Tests of the static file copying for the HTML report."""
+
+ def setUp(self):
+ super(HtmlStaticFileTest, self).setUp()
+ self.original_path = list(coverage.html.STATIC_PATH)
+
+ def tearDown(self):
+ coverage.html.STATIC_PATH = self.original_path
+ super(HtmlStaticFileTest, self).tearDown()
+
+ def test_copying_static_files_from_system(self):
+ # Make a new place for static files.
+ self.make_file("static_here/jquery.min.js", "Not Really JQuery!")
+ coverage.html.STATIC_PATH.insert(0, "static_here")
+
+ self.make_file("main.py", "print(17)")
+ cov = coverage.coverage()
+ self.start_import_stop(cov, "main")
+ cov.html_report()
+ jquery = open("htmlcov/jquery.min.js").read()
+ self.assertEqual(jquery, "Not Really JQuery!")
+
+ def test_cant_find_static_files(self):
+ # Make the path point to useless places.
+ coverage.html.STATIC_PATH = ["/xyzzy"]
+
+ self.make_file("main.py", "print(17)")
+ cov = coverage.coverage()
+ self.start_import_stop(cov, "main")
+ self.assertRaisesRegexp(
+ CoverageException, "Couldn't find static file '.*'",
+ cov.html_report
+ )