diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-01-24 22:21:21 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-01-24 22:21:21 -0500 |
commit | b8166d18d4e48c9ae6c7b9e3ef0e9ec9b120e173 (patch) | |
tree | bdebb1fc5a5962ac9830b8f852f2ba3f7b4b5ef6 /coverage | |
parent | 8c03cb90d8d09c360d54fa1c277007685ee05a73 (diff) | |
download | python-coveragepy-git-b8166d18d4e48c9ae6c7b9e3ef0e9ec9b120e173.tar.gz |
Move flat_rootname to the base class
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/codeunit.py | 13 | ||||
-rw-r--r-- | coverage/plugin.py | 18 |
2 files changed, 12 insertions, 19 deletions
diff --git a/coverage/codeunit.py b/coverage/codeunit.py index 5e8712d8..ef7e8485 100644 --- a/coverage/codeunit.py +++ b/coverage/codeunit.py @@ -36,16 +36,3 @@ class CodeUnit(FileReporter): def _adjust_filename(self, f): # TODO: This shouldn't be in the base class, right? return f - - def flat_rootname(self): - """A base for a flat filename to correspond to this code unit. - - 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' - - """ - root = os.path.splitdrive(self.name)[1] - return root.replace('\\', '_').replace('/', '_').replace('.', '_') diff --git a/coverage/plugin.py b/coverage/plugin.py index c80a1a24..32d654e4 100644 --- a/coverage/plugin.py +++ b/coverage/plugin.py @@ -1,5 +1,7 @@ """Plugin interfaces for coverage.py""" +import re + from coverage.misc import _needs_to_implement @@ -206,10 +208,14 @@ class FileReporter(object): return False def flat_rootname(self): + """A base for a flat filename to correspond to this code unit. + + 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' + + """ # TODO: a better generic implementation? - return ( - self.filename - .replace('\\', '_') - .replace('/', '_') - .replace('.', '_') - ) + return re.sub(r"[\/.:]", "_", self.name) |