summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-09-21 11:32:43 -0400
committerNed Batchelder <ned@nedbatchelder.com>2014-09-21 11:32:43 -0400
commit134b27ee390d5bb5c524e2fd6a1902eb2002ae2a (patch)
tree3e8caaca2ec4f432ea5d10205a2f220b0caf7d06
parentf491f4f37ff2e18090b1f8c74d20a95591f4fc81 (diff)
downloadpython-coveragepy-git-134b27ee390d5bb5c524e2fd6a1902eb2002ae2a.tar.gz
Make the Fnmatcher work right on Windows.
-rw-r--r--coverage/files.py7
-rw-r--r--tests/test_files.py8
2 files changed, 14 insertions, 1 deletions
diff --git a/coverage/files.py b/coverage/files.py
index 72c0bf92..40c126e9 100644
--- a/coverage/files.py
+++ b/coverage/files.py
@@ -177,7 +177,12 @@ class FnmatchMatcher(object):
"""A matcher for files by filename pattern."""
def __init__(self, pats):
self.pats = pats[:]
- self.re = re.compile(join_regex([fnmatch.translate(p) for p in pats]))
+ # fnmatch is platform-specific. On Windows, it does the Windows thing
+ # of treating / and \ as equivalent. But on other platforms, we need to
+ # take care of that ourselves.
+ fnpats = [fnmatch.translate(p) for p in pats]
+ fnpats = [p.replace(r"\/", r"[\\/]") for p in fnpats]
+ self.re = re.compile(join_regex(fnpats))
def __repr__(self):
return "<FnmatchMatcher %r>" % self.pats
diff --git a/tests/test_files.py b/tests/test_files.py
index 070430ff..648c76a9 100644
--- a/tests/test_files.py
+++ b/tests/test_files.py
@@ -99,6 +99,14 @@ class MatcherTest(CoverageTest):
self.assertMatches(fnm, "x123foo.txt", True)
self.assertMatches(fnm, "x798bar.txt", False)
+ def test_fnmatch_windows_paths(self):
+ # We should be able to match Windows paths even if we are running on
+ # a non-Windows OS.
+ fnm = FnmatchMatcher(["*/foo.py"])
+ self.assertMatches(fnm, r"dir\foo.py", True)
+ fnm = FnmatchMatcher([r"*\foo.py"])
+ self.assertMatches(fnm, r"dir\foo.py", True)
+
class PathAliasesTest(CoverageTest):
"""Tests for coverage/files.py:PathAliases"""