diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2010-05-23 16:09:44 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-05-23 16:09:44 -0400 |
commit | cd1b610a9645b0a3a53ce1c2779236c40e5d2164 (patch) | |
tree | 2a27b44eb82048020b5f83b487001d2d67e13bb6 /coverage/codeunit.py | |
parent | 88eef7d43f1056d8ff65ca260fa7f28e49f4bfc1 (diff) | |
download | python-coveragepy-cd1b610a9645b0a3a53ce1c2779236c40e5d2164.tar.gz |
Omit and include are now filename patterns rather than prefixes. BACKWARD INCOMPATIBLE change.
Diffstat (limited to 'coverage/codeunit.py')
-rw-r--r-- | coverage/codeunit.py | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/coverage/codeunit.py b/coverage/codeunit.py index a0da1a7..cc7c226 100644 --- a/coverage/codeunit.py +++ b/coverage/codeunit.py @@ -1,23 +1,21 @@ """Code unit (module) handling for Coverage.""" -import glob, os +import fnmatch, glob, os from coverage.backward import string_class, StringIO from coverage.misc import CoverageException -def code_unit_factory( - morfs, file_locator, omit_prefixes=None, include_prefixes=None - ): +def code_unit_factory(morfs, file_locator, omit=None, include=None): """Construct a list of CodeUnits from polymorphic inputs. `morfs` is a module or a filename, or a list of same. `file_locator` is a FileLocator that can help resolve filenames. - `include_prefixes` is a list of prefixes. Only CodeUnits that match those - prefixes will be included in the list. `omit_prefixes` is a list of - prefixes to omit from the list. + `include` is a list of filename patterns. Only CodeUnits that match those + patterns will be included in the list. `omit` is a list of patterns to omit + from the list. Returns a list of CodeUnit objects. @@ -38,24 +36,24 @@ def code_unit_factory( code_units = [CodeUnit(morf, file_locator) for morf in morfs] - if include_prefixes: - assert not isinstance(include_prefixes, string_class) # common mistake - prefixes = [file_locator.abs_file(p) for p in include_prefixes] + if include: + assert not isinstance(include, string_class) # common mistake + patterns = [file_locator.abs_file(p) for p in include] filtered = [] for cu in code_units: - for prefix in prefixes: - if cu.filename.startswith(prefix): + for pattern in patterns: + if fnmatch.fnmatch(cu.filename, pattern): filtered.append(cu) break code_units = filtered - if omit_prefixes: - assert not isinstance(omit_prefixes, string_class) # common mistake - prefixes = [file_locator.abs_file(p) for p in omit_prefixes] + if omit: + assert not isinstance(omit, string_class) # common mistake + patterns = [file_locator.abs_file(p) for p in omit] filtered = [] for cu in code_units: - for prefix in prefixes: - if cu.filename.startswith(prefix): + for pattern in patterns: + if fnmatch.fnmatch(cu.filename, pattern): break else: filtered.append(cu) |