summaryrefslogtreecommitdiff
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
commit73791b3164a672ee69739b87dde927b0f4d4e428 (patch)
tree2c3290ac3f289a9bda04b23a793a9364504c30e9
parent460272b31fc0c6fa017cc53d1d3f2233b2db4ba3 (diff)
downloadpython-coveragepy-73791b3164a672ee69739b87dde927b0f4d4e428.tar.gz
Clarify how TreeMatcher works.
-rw-r--r--coverage/files.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/coverage/files.py b/coverage/files.py
index af2fe52..d2c2b89 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