diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-01-17 17:18:23 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-01-17 17:18:23 -0500 |
commit | 3955b9ca60db8bbe976bfa352a784bb8f08fa1e0 (patch) | |
tree | e41ad09af01e4e412f180d412450ca7019813d75 | |
parent | a7fc111387f1f782f3404a21c103cac4812f9e74 (diff) | |
download | python-coveragepy-git-3955b9ca60db8bbe976bfa352a784bb8f08fa1e0.tar.gz |
Clean up the module->file logic
-rw-r--r-- | CHANGES.txt | 3 | ||||
-rw-r--r-- | coverage/codeunit.py | 24 |
2 files changed, 14 insertions, 13 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 77ffdb9e..0f0e9ab3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -10,6 +10,9 @@ Latest describe a/b/c.py as "a/b/c". Now it is shown as "a/b/c.py". This allows for better support of non-Python files. +- When looking for the source for a frame, check if the file exists. On + Windows, .pyw files are no longer recorded as .py files. + - Empty files are now reported as 100% covered in the XML report, not 0% covered (`issue 345`_). diff --git a/coverage/codeunit.py b/coverage/codeunit.py index e75018d8..6eae36d6 100644 --- a/coverage/codeunit.py +++ b/coverage/codeunit.py @@ -21,25 +21,23 @@ class CodeUnit(FileReporter): self.file_locator = file_locator or FileLocator() if hasattr(morf, '__file__'): - f = morf.__file__ + filename = morf.__file__ else: - f = morf - f = self._adjust_filename(f) - self.filename = self.file_locator.canonical_filename(f) + filename = morf + filename = self._adjust_filename(filename) + self.filename = self.file_locator.canonical_filename(filename) if hasattr(morf, '__name__'): - n = morf.__name__ - n = n.replace(".", os.sep) + ".py" + name = morf.__name__ + name = name.replace(".", os.sep) + ".py" self.relative = True else: - n = f #os.path.splitext(f)[0] - rel = self.file_locator.relative_filename(n) - if os.path.isabs(n): - self.relative = (rel != n) + name = self.file_locator.relative_filename(filename) + if os.path.isabs(filename): + self.relative = (name != filename) else: self.relative = True - n = rel - self.name = n + self.name = name def _adjust_filename(self, f): # TODO: This shouldn't be in the base class, right? @@ -52,7 +50,7 @@ class CodeUnit(FileReporter): the same directory, but need to differentiate same-named files from different directories. - For example, the file a/b/c.py will return 'a_b_c' + For example, the file a/b/c.py will return 'a_b_c_py' """ root = os.path.splitdrive(self.name)[1] |