diff options
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/annotate.py | 3 | ||||
-rw-r--r-- | coverage/files.py | 14 | ||||
-rw-r--r-- | coverage/html.py | 13 | ||||
-rw-r--r-- | coverage/plugin.py | 18 |
4 files changed, 23 insertions, 25 deletions
diff --git a/coverage/annotate.py b/coverage/annotate.py index 4b4966e9..60772656 100644 --- a/coverage/annotate.py +++ b/coverage/annotate.py @@ -7,6 +7,7 @@ import io import os import re +from coverage.files import flat_rootname from coverage.report import Reporter class AnnotateReporter(Reporter): @@ -57,7 +58,7 @@ class AnnotateReporter(Reporter): excluded = sorted(analysis.excluded) if self.directory: - dest_file = os.path.join(self.directory, fr.flat_rootname()) + dest_file = os.path.join(self.directory, flat_rootname(fr.relative_filename())) if dest_file.endswith("_py"): dest_file = dest_file[:-3] + ".py" dest_file += ",cover" diff --git a/coverage/files.py b/coverage/files.py index e3ebd6ce..d2742a39 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -67,6 +67,20 @@ def canonical_filename(filename): return CANONICAL_FILENAME_CACHE[filename] +def flat_rootname(filename): + """A base for a flat filename to correspond to this file. + + Useful for writing files about the code where you want all the files in + 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_py' + + """ + name = os.path.splitdrive(filename)[1] + return re.sub(r"[\\/.:]", "_", name) + + if env.WINDOWS: _ACTUAL_PATH_CACHE = {} diff --git a/coverage/html.py b/coverage/html.py index 3a6c61c8..6d1bb434 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -12,6 +12,7 @@ import shutil import coverage from coverage import env from coverage.backward import iitems +from coverage.files import flat_rootname from coverage.misc import CoverageException, Hasher from coverage.report import Reporter from coverage.results import Numbers @@ -166,15 +167,15 @@ class HtmlReporter(Reporter): source = fr.source() # Find out if the file on disk is already correct. - flat_rootname = fr.flat_rootname() + rootname = flat_rootname(fr.relative_filename()) this_hash = self.file_hash(source.encode('utf-8'), fr) - that_hash = self.status.file_hash(flat_rootname) + that_hash = self.status.file_hash(rootname) if this_hash == that_hash: # Nothing has changed to require the file to be reported again. - self.files.append(self.status.index_info(flat_rootname)) + self.files.append(self.status.index_info(rootname)) return - self.status.set_file_hash(flat_rootname, this_hash) + self.status.set_file_hash(rootname, this_hash) # Get the numbers for this file. nums = analysis.numbers @@ -256,7 +257,7 @@ class HtmlReporter(Reporter): } html = spaceless(self.source_tmpl.render(template_values)) - html_filename = flat_rootname + ".html" + html_filename = rootname + ".html" html_path = os.path.join(self.directory, html_filename) self.write_html(html_path, html) @@ -267,7 +268,7 @@ class HtmlReporter(Reporter): 'relative_filename': fr.relative_filename(), } self.files.append(index_info) - self.status.set_index_info(flat_rootname, index_info) + self.status.set_index_info(rootname, index_info) def index_file(self): """Write the index.html file for this report.""" diff --git a/coverage/plugin.py b/coverage/plugin.py index f4182b0f..8cd6dd3f 100644 --- a/coverage/plugin.py +++ b/coverage/plugin.py @@ -3,9 +3,6 @@ """Plugin interfaces for coverage.py""" -import os -import re - from coverage import files from coverage.misc import _needs_to_implement @@ -226,18 +223,3 @@ class FileReporter(object): place. """ return False - - def flat_rootname(self): - """A base for a flat filename to correspond to this file. - - Useful for writing files about the code where you want all the files in - 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_py' - - You should not need to override this method. - - """ - name = os.path.splitdrive(self.relative_filename())[1] - return re.sub(r"[\\/.:]", "_", name) |