summaryrefslogtreecommitdiff
path: root/coverage/codeunit.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2010-05-23 16:09:44 -0400
committerNed Batchelder <ned@nedbatchelder.com>2010-05-23 16:09:44 -0400
commit039345d5c311d5d55ee6c93554959fd5685a862c (patch)
treef11ae9cf490e2550d8d8072de6a1ac0bf72549d8 /coverage/codeunit.py
parent762d67689a8ddc88195cdbb0787bc3e940ddbf85 (diff)
downloadpython-coveragepy-git-039345d5c311d5d55ee6c93554959fd5685a862c.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.py32
1 files changed, 15 insertions, 17 deletions
diff --git a/coverage/codeunit.py b/coverage/codeunit.py
index a0da1a71..cc7c226e 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)