summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt4
-rw-r--r--coverage/html.py31
-rw-r--r--coverage/htmlfiles/jquery.min.js (renamed from coverage/htmlfiles/jquery-1.4.3.min.js)0
-rw-r--r--tests/test_html.py41
4 files changed, 68 insertions, 8 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 829ad02f..795bc659 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -30,6 +30,9 @@ Change history for Coverage.py
issues a spurious warning about the trace function changing: "Trace function
changed, measurement is likely wrong: None." This fixes `issue 164`_.
+- Static files necessary for HTML reports are found in system-installed places,
+ to ease OS-level packaging of coverage.py. Closes `issue 259`.
+
- Source files with encoding declarations, but a blank first line, were not
decoded properly. Now they are. Thanks, Roger Hu.
@@ -43,6 +46,7 @@ Change history for Coverage.py
.. _issue 242: https://bitbucket.org/ned/coveragepy/issue/242/running-a-two-level-package-doesnt-work
.. _issue 218: https://bitbucket.org/ned/coveragepy/issue/218/run-command-does-not-respect-the-omit-flag
.. _issue 255: https://bitbucket.org/ned/coveragepy/issue/255/directory-level-__main__py-not-included-in
+.. _issue 259: https://bitbucket.org/ned/coveragepy/issue/259/allow-use-of-system-installed-third-party
.. _issue 264: https://bitbucket.org/ned/coveragepy/issue/264/coverage-wont-run-pyc-files
.. _issue 267: https://bitbucket.org/ned/coveragepy/issue/267/relative-path-aliases-dont-work
diff --git a/coverage/html.py b/coverage/html.py
index aef43be3..b5cef11e 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -10,9 +10,28 @@ from coverage.report import Reporter
from coverage.results import Numbers
from coverage.templite import Templite
+
+# Static files are looked for in a list of places.
+STATIC_PATH = [
+ # The place Debian puts system Javascript libraries.
+ "/usr/share/javascript",
+
+ # Our htmlfiles directory.
+ os.path.join(os.path.dirname(__file__), "htmlfiles"),
+]
+
def data_filename(fname):
- """Return the path to a data file of ours."""
- return os.path.join(os.path.split(__file__)[0], fname)
+ """Return the path to a data file of ours.
+
+ The file is searched for on `STATIC_PATH`, and the first place it's found,
+ is returned.
+
+ """
+ for static_dir in STATIC_PATH:
+ static_filename = os.path.join(static_dir, fname)
+ if os.path.exists(static_filename):
+ return static_filename
+ raise CoverageException("Couldn't find static file %r" % fname)
def data(fname):
"""Return the contents of a data file of ours."""
@@ -29,7 +48,7 @@ class HtmlReporter(Reporter):
# These files will be copied from the htmlfiles dir to the output dir.
STATIC_FILES = [
"style.css",
- "jquery-1.4.3.min.js",
+ "jquery.min.js",
"jquery.hotkeys.js",
"jquery.isonscreen.js",
"jquery.tablesorter.min.js",
@@ -48,7 +67,7 @@ class HtmlReporter(Reporter):
'__version__': coverage.__version__,
}
self.source_tmpl = Templite(
- data("htmlfiles/pyfile.html"), self.template_globals
+ data("pyfile.html"), self.template_globals
)
self.coverage = cov
@@ -100,7 +119,7 @@ class HtmlReporter(Reporter):
# The files we provide must always be copied.
for static in self.STATIC_FILES:
shutil.copyfile(
- data_filename("htmlfiles/" + static),
+ data_filename(static),
os.path.join(self.directory, static)
)
@@ -240,7 +259,7 @@ class HtmlReporter(Reporter):
def index_file(self):
"""Write the index.html file for this report."""
index_tmpl = Templite(
- data("htmlfiles/index.html"), self.template_globals
+ data("index.html"), self.template_globals
)
self.totals = sum([f['nums'] for f in self.files])
diff --git a/coverage/htmlfiles/jquery-1.4.3.min.js b/coverage/htmlfiles/jquery.min.js
index c941a5f7..c941a5f7 100644
--- a/coverage/htmlfiles/jquery-1.4.3.min.js
+++ b/coverage/htmlfiles/jquery.min.js
diff --git a/tests/test_html.py b/tests/test_html.py
index e44db970..e1d41d93 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
+ )