From 4d45dc8c234eee1b4bd6da9eac409d588eba9455 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 19 Apr 2009 08:16:50 -0400 Subject: 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 --- coverage/codeunit.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'coverage/codeunit.py') 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('/', '_') -- cgit v1.2.1