diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-04-10 09:50:01 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-04-10 10:19:00 -0400 |
commit | dc48d27937d4eb0ec5072b97dce54e7556618f8e (patch) | |
tree | 3156d5a9649333543aa0121c4fa0141d4f6cb8b6 | |
parent | 1b34415fe55c6cdd624d73c2ba57d5e690bbba17 (diff) | |
download | python-coveragepy-git-dc48d27937d4eb0ec5072b97dce54e7556618f8e.tar.gz |
fix: make TreeMatcher right for case-sensitive worlds
-rw-r--r-- | coverage/files.py | 6 | ||||
-rw-r--r-- | tests/test_files.py | 5 |
2 files changed, 9 insertions, 2 deletions
diff --git a/coverage/files.py b/coverage/files.py index 59b2bd61..1cf4b18e 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -216,17 +216,19 @@ class TreeMatcher(object): """ def __init__(self, paths): - self.paths = list(paths) + self.original_paths = list(paths) + self.paths = list(map(os.path.normcase, paths)) def __repr__(self): return "<TreeMatcher %r>" % self.paths def info(self): """A list of strings for displaying when dumping state.""" - return self.paths + return self.original_paths def match(self, fpath): """Does `fpath` indicate a file in one of our trees?""" + fpath = os.path.normcase(fpath) for p in self.paths: if fpath.startswith(p): if fpath == p: diff --git a/tests/test_files.py b/tests/test_files.py index 512e4294..2f1bb83b 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -151,16 +151,21 @@ class MatcherTest(CoverageTest): assert matches == matcher.match(canonical), msg def test_tree_matcher(self): + case_folding = env.WINDOWS matches_to_try = [ (self.make_file("sub/file1.py"), True), (self.make_file("sub/file2.c"), True), (self.make_file("sub2/file3.h"), False), (self.make_file("sub3/file4.py"), True), (self.make_file("sub3/file5.c"), False), + (self.make_file("sub4/File5.py"), case_folding), + (self.make_file("sub5/file6.py"), case_folding), ] trees = [ files.canonical_filename("sub"), files.canonical_filename("sub3/file4.py"), + files.canonical_filename("sub4/file5.py"), + files.canonical_filename("SUB5/file6.py"), ] tm = TreeMatcher(trees) assert tm.info() == trees |