diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2014-11-24 21:30:04 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2014-11-24 21:30:04 -0500 |
commit | 414941cd8cb1e157eb1d5f629958f03c49e6be93 (patch) | |
tree | 22d3bd825e2561f80c91562379541b73a6f3edd5 /coverage/files.py | |
parent | d182230b96de38b3cd318cf74a84787e1fc9b90d (diff) | |
parent | 84505f77650e7c62ba47da5c2b93d291885e7a9b (diff) | |
download | python-coveragepy-414941cd8cb1e157eb1d5f629958f03c49e6be93.tar.gz |
Merged pull request 42, fixing issue #328.
Diffstat (limited to 'coverage/files.py')
-rw-r--r-- | coverage/files.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/coverage/files.py b/coverage/files.py index 03df1a7..3a29886 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -173,6 +173,39 @@ class TreeMatcher(object): return False +class ModuleMatcher(object): + """A matcher for modules in a tree.""" + def __init__(self, module_names): + self.modules = list(module_names) + + def __repr__(self): + return "<ModuleMatcher %r>" % (self.modules) + + def info(self): + """A list of strings for displaying when dumping state.""" + return self.modules + + def add(self, module): + """Add another directory to the list we match for.""" + self.modules.append(module) + + def match(self, module_name): + """Does `module_name` indicate a module in one of our packages? + """ + if not module_name: + return False + + for m in self.modules: + if module_name.startswith(m): + if module_name == m: + return True + if module_name[len(m)] == '.': + # This is a module in the package + return True + + return False + + class FnmatchMatcher(object): """A matcher for files by filename pattern.""" def __init__(self, pats): |