summaryrefslogtreecommitdiff
path: root/coverage/files.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2017-02-20 20:26:03 -0500
committerNed Batchelder <ned@nedbatchelder.com>2017-02-20 20:26:03 -0500
commit0af66e7cd0de5935739b3650de573d7acb0728ec (patch)
tree0fc96dcd4ca3d1609b9343465dd62a8a95e3c7c8 /coverage/files.py
parent66af7e3d24084829850b8bb6d671ddb0094a0331 (diff)
downloadpython-coveragepy-git-0af66e7cd0de5935739b3650de573d7acb0728ec.tar.gz
Clarify how TreeMatcher works.
Diffstat (limited to 'coverage/files.py')
-rw-r--r--coverage/files.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/coverage/files.py b/coverage/files.py
index af2fe52f..d2c2b894 100644
--- a/coverage/files.py
+++ b/coverage/files.py
@@ -191,25 +191,31 @@ def prep_patterns(patterns):
class TreeMatcher(object):
- """A matcher for files in a tree."""
- def __init__(self, directories):
- self.dirs = list(directories)
+ """A matcher for files in a tree.
+
+ Construct with a list of paths, either files or directories. Paths match
+ with the `match` method if they are one of the files, or if they are
+ somewhere in a subtree rooted at one of the directories.
+
+ """
+ def __init__(self, paths):
+ self.paths = list(paths)
def __repr__(self):
- return "<TreeMatcher %r>" % self.dirs
+ return "<TreeMatcher %r>" % self.paths
def info(self):
"""A list of strings for displaying when dumping state."""
- return self.dirs
+ return self.paths
def match(self, fpath):
"""Does `fpath` indicate a file in one of our trees?"""
- for d in self.dirs:
- if fpath.startswith(d):
- if fpath == d:
+ for p in self.paths:
+ if fpath.startswith(p):
+ if fpath == p:
# This is the same file!
return True
- if fpath[len(d)] == os.sep:
+ if fpath[len(p)] == os.sep:
# This is a file in the directory
return True
return False