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 | 2b369aa719d2a4b4e755c9030f1d0cc1dfeeeacb (patch) | |
tree | 361d0a995b5360a0170aff07cc87aa5afbc7562a /coverage/files.py | |
parent | 8fa9db9f86de0b7cbce45e0a5fe87e38e47212b7 (diff) | |
parent | b3ccb75241566c1e1a814ae99a84637fd0ac2b44 (diff) | |
download | python-coveragepy-git-2b369aa719d2a4b4e755c9030f1d0cc1dfeeeacb.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 03df1a71..3a298867 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): |