diff options
-rw-r--r-- | CHANGES.txt | 5 | ||||
-rw-r--r-- | coverage/files.py | 14 | ||||
-rw-r--r-- | test/test_html.py | 23 |
3 files changed, 32 insertions, 10 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 6ba1f349..679f1ed8 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -52,6 +52,10 @@ Version 3.6b1 - On Windows, files are now reported in their correct case, fixing `issue 89`_ and `issue 203`_. +- If a file is missing during reporting, the path shown in the error message + is now correct, rather than an incorrect path in the current directory. + Fixes `issue 60`_. + - Running an HTML report in Python 3 in the same directory as an old Python 2 HTML report would fail with a UnicodeDecodeError. This issue (`issue 193`_) is now fixed. @@ -81,6 +85,7 @@ Version 3.6b1 - Other minor bugs fixed: `issue 153`_. +.. _issue 60: https://bitbucket.org/ned/coveragepy/issue/60/incorrect-path-to-orphaned-pyc-files .. _issue 67: https://bitbucket.org/ned/coveragepy/issue/67/xml-report-filenames-may-be-generated .. _issue 82: https://bitbucket.org/ned/coveragepy/issue/82/tokenerror-when-generating-html-report .. _issue 89: https://bitbucket.org/ned/coveragepy/issue/89/on-windows-all-packages-are-reported-in diff --git a/coverage/files.py b/coverage/files.py index 40af7bf7..3a3a7732 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -34,19 +34,15 @@ class FileLocator(object): """ if filename not in self.canonical_filename_cache: - f = filename - if os.path.isabs(f) and not os.path.exists(f): - if self.get_zip_data(f) is None: - f = os.path.basename(f) - if not os.path.isabs(f): + if not os.path.isabs(filename): for path in [os.curdir] + sys.path: if path is None: continue - g = os.path.join(path, f) - if os.path.exists(g): - f = g + f = os.path.join(path, filename) + if os.path.exists(f): + filename = f break - cf = abs_file(f) + cf = abs_file(filename) self.canonical_filename_cache[filename] = cf return self.canonical_filename_cache[filename] diff --git a/test/test_html.py b/test/test_html.py index 29106562..2f1dc5d2 100644 --- a/test/test_html.py +++ b/test/test_html.py @@ -3,7 +3,7 @@ import os.path, sys import coverage -from coverage.misc import NotPython +from coverage.misc import NotPython, NoSource sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k from coveragetest import CoverageTest @@ -287,3 +287,24 @@ class HtmlWithUnparsableFilesTest(CoverageTest): cov.stop() cov.html_report() self.assert_exists("htmlcov/index.html") + + +class HtmlTest(CoverageTest): + """Moar HTML tests.""" + + def test_missing_source_file_incorrect_message(self): + # https://bitbucket.org/ned/coveragepy/issue/60 + self.make_file("thefile.py", "import sub.another\n") + self.make_file("sub/__init__.py", "") + self.make_file("sub/another.py", "print('another')\n") + cov = coverage.coverage() + cov.start() + self.import_local_file('thefile') + cov.stop() + os.remove("sub/another.py") + + missing_file = os.path.join(self.temp_dir, "sub", "another.py") + self.assertRaisesRegexp(NoSource, + "No source for code: '%s'" % missing_file, + cov.html_report + ) |