summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2011-09-03 15:43:51 -0400
committerNed Batchelder <ned@nedbatchelder.com>2011-09-03 15:43:51 -0400
commitf5a27f754d464c9b4d88396cbfd54ff15c891b8c (patch)
tree0bd8e51c3f03e23b2e4a9fcdb2b187df7997b4aa
parentb07083717a4fb0717ebd070340cf97441fa8e515 (diff)
downloadpython-coveragepy-f5a27f754d464c9b4d88396cbfd54ff15c891b8c.tar.gz
Fix the [paths] feature to actually work for reporting.
-rw-r--r--CHANGES.txt6
-rw-r--r--coverage/control.py2
-rw-r--r--coverage/files.py8
-rw-r--r--test/test_process.py4
4 files changed, 17 insertions, 3 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 24171c7..0ca825f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,12 @@
Change history for Coverage.py
------------------------------
+
+- The ``[paths]`` feature unfortunately didn't work in real world situations
+ where you wanted to, you know, report on the combined data. Now all paths
+ stored in the combined file are canonicalized properly.
+
+
Version 3.5.1b1 --- 28 August 2011
----------------------------------
diff --git a/coverage/control.py b/coverage/control.py
index a77d805..d83e11b 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -469,7 +469,7 @@ class coverage(object):
"""
aliases = None
if self.config.paths:
- aliases = PathAliases()
+ aliases = PathAliases(self.file_locator)
for paths in self.config.paths.values():
result = paths[0]
for pattern in paths[1:]:
diff --git a/coverage/files.py b/coverage/files.py
index 7258acc..53dc099 100644
--- a/coverage/files.py
+++ b/coverage/files.py
@@ -139,9 +139,12 @@ class PathAliases(object):
A `PathAliases` object tracks a list of pattern/result pairs, and can
map a path through those aliases to produce a unified path.
+ `locator` is a FileLocator that is used to canonicalize the results.
+
"""
- def __init__(self):
+ def __init__(self, locator=None):
self.aliases = []
+ self.locator = locator
def add(self, pattern, result):
"""Add the `pattern`/`result` pair to the list of aliases.
@@ -191,12 +194,15 @@ class PathAliases(object):
in the alias.
"""
+ opath = path
for regex, result, pattern_sep, result_sep in self.aliases:
m = regex.match(path)
if m:
new = path.replace(m.group(0), result)
if pattern_sep != result_sep:
new = new.replace(pattern_sep, result_sep)
+ if self.locator:
+ new = self.locator.canonical_filename(new)
return new
return path
diff --git a/test/test_process.py b/test/test_process.py
index ed9e89f..4cf5524 100644
--- a/test/test_process.py
+++ b/test/test_process.py
@@ -175,7 +175,9 @@ class ProcessTest(CoverageTest):
data.read_file(".coverage")
summary = data.summary(fullpath=True)
self.assertEqual(len(summary), 1)
- self.assertEqual(list(summary.keys())[0], os.path.normpath('src/x.py'))
+ actual = os.path.abspath(list(summary.keys())[0])
+ expected = os.path.abspath('src/x.py')
+ self.assertEqual(actual, expected)
self.assertEqual(list(summary.values())[0], 6)
def test_missing_source_file(self):