summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/files.py12
-rw-r--r--tests/test_files.py5
2 files changed, 14 insertions, 3 deletions
diff --git a/coverage/files.py b/coverage/files.py
index 346043d..04ce9cb 100644
--- a/coverage/files.py
+++ b/coverage/files.py
@@ -302,6 +302,11 @@ class PathAliases(object):
def __init__(self):
self.aliases = []
+ def pprint(self): # pragma: debugging
+ """Dump the important parts of the PathAliases, for debugging."""
+ for regex, result, _, _ in self.aliases:
+ print("{0!r} --> {1!r}".format(regex.pattern, result))
+
def add(self, pattern, result):
"""Add the `pattern`/`result` pair to the list of aliases.
@@ -315,8 +320,10 @@ class PathAliases(object):
match an entire tree, and not just its root.
"""
+ if len(pattern) > 1:
+ pattern = pattern.rstrip(r"\/")
+
# The pattern can't end with a wildcard component.
- pattern = pattern.rstrip(r"\/")
if pattern.endswith("*"):
raise CoverageException("Pattern must not end with wildcards.")
pattern_sep = sep(pattern)
@@ -325,7 +332,8 @@ class PathAliases(object):
# unless it already is, or is meant to match any prefix.
if not pattern.startswith('*') and not isabs_anywhere(pattern):
pattern = abs_file(pattern)
- pattern += pattern_sep
+ if not pattern.endswith(pattern_sep):
+ pattern += pattern_sep
# Make a regex from the pattern. fnmatch always adds a \Z to
# match the whole string, which we don't want, so we remove the \Z.
diff --git a/tests/test_files.py b/tests/test_files.py
index dadb22b..a4ca02c 100644
--- a/tests/test_files.py
+++ b/tests/test_files.py
@@ -161,6 +161,9 @@ class PathAliasesTest(CoverageTest):
canonicalized paths.
"""
+ aliases.pprint()
+ print(inp)
+ print(out)
self.assertEqual(aliases.map(inp), files.canonical_filename(out))
def assert_unchanged(self, aliases, inp):
@@ -242,7 +245,7 @@ class PathAliasesTest(CoverageTest):
self.assert_mapped(aliases, '/foo/bar/d2/y.py', './mysrc2/y.py')
def test_dot(self):
- for d in ('.', '..', '../other', '~'):
+ for d in ('.', '..', '../other', '~', '/'):
aliases = PathAliases()
aliases.add(d, '/the/source')
the_file = os.path.join(d, 'a.py')