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 | 4d45dc8c234eee1b4bd6da9eac409d588eba9455 (patch) | |
tree | 387e5f55061359707d33b39681ad555d5e9ef0b5 /coverage/codeunit.py | |
parent | 89fbd04106100a4cc821cc41bac2e9301bda33ec (diff) | |
download | python-coveragepy-git-4d45dc8c234eee1b4bd6da9eac409d588eba9455.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.
--HG--
rename : test/farm/annotate/gold_anno_dir/a.py,cover => test/farm/annotate/gold_anno_dir/a_a.py,cover
rename : test/farm/annotate/gold_anno_dir/b.py,cover => test/farm/annotate/gold_anno_dir/b_b.py,cover
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 96ed43bb..3c3d30f5 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('/', '_') |