diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-04-19 08:16:50 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-04-19 08:16:50 -0400 |
commit | ca1b25a3089a7db3d5a08c2a317a2f689f2ff34f (patch) | |
tree | 8c947e89e203e9ff105f358809e453f49c45b087 /coverage/codeunit.py | |
parent | ffc86c415c32d5d2b55da35bb9a16e82e7d8e133 (diff) | |
download | python-coveragepy-ca1b25a3089a7db3d5a08c2a317a2f689f2ff34f.tar.gz |
Annotated files are only created for source files relative to the current directory. When writing to a separate file, annotation file names include the directory hierarchy flattened, so that same-named files won't collide.
Diffstat (limited to 'coverage/codeunit.py')
-rw-r--r-- | coverage/codeunit.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/coverage/codeunit.py b/coverage/codeunit.py index 96ed43b..3c3d30f 100644 --- a/coverage/codeunit.py +++ b/coverage/codeunit.py @@ -47,8 +47,11 @@ def code_unit_factory(morfs, file_locator, omit_prefixes=None): class CodeUnit: """Code unit: a filename or module. + Instance attributes: + `name` is a human-readable name for this code unit. `filename` is the os path from which we can read the source. + `relative` is a boolean. """ @@ -64,10 +67,26 @@ class CodeUnit: if hasattr(morf, '__name__'): n = morf.__name__ + self.relative = True else: n = os.path.splitext(morf)[0] - n = file_locator.relative_filename(n) + rel = file_locator.relative_filename(n) + self.relative = (rel != n) + n = rel self.name = n def __cmp__(self, other): return cmp(self.name, other.name) + + 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 might return 'a_b_c' + + """ + root = os.path.splitdrive(os.path.splitext(self.name)[0])[1] + return root.replace('\\', '_').replace('/', '_') |