diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2010-08-28 18:53:10 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-08-28 18:53:10 -0400 |
commit | 0ce75ec8c128cc8c2e54e1f9053dd471ac48f2a7 (patch) | |
tree | a65404808e5423edef37a85c401d0a215567caaa /coverage/codeunit.py | |
parent | f0bbf65bfadf3eeafc9823efdd02d6bca10e445e (diff) | |
download | python-coveragepy-0ce75ec8c128cc8c2e54e1f9053dd471ac48f2a7.tar.gz |
Refactor the --omit and --include support during reporting, and add a test for --include.
Diffstat (limited to 'coverage/codeunit.py')
-rw-r--r-- | coverage/codeunit.py | 34 |
1 files changed, 3 insertions, 31 deletions
diff --git a/coverage/codeunit.py b/coverage/codeunit.py index 2d960e3..dfc4560 100644 --- a/coverage/codeunit.py +++ b/coverage/codeunit.py @@ -1,26 +1,21 @@ """Code unit (module) handling for Coverage.""" -import fnmatch, glob, os +import glob, os from coverage.backward import string_class, StringIO from coverage.misc import CoverageException -def code_unit_factory(morfs, file_locator, omit=None, include=None): +def code_unit_factory(morfs, file_locator): """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` 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. """ - # Be sure we have a list. if not isinstance(morfs, (list, tuple)): morfs = [morfs] @@ -36,31 +31,9 @@ def code_unit_factory(morfs, file_locator, omit=None, include=None): code_units = [CodeUnit(morf, file_locator) for morf in morfs] - 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 pattern in patterns: - if fnmatch.fnmatch(cu.filename, pattern): - filtered.append(cu) - break - code_units = filtered - - 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 pattern in patterns: - if fnmatch.fnmatch(cu.filename, pattern): - break - else: - filtered.append(cu) - code_units = filtered - return code_units + class CodeUnit(object): """Code unit: a filename or module. @@ -71,7 +44,6 @@ class CodeUnit(object): `relative` is a boolean. """ - def __init__(self, morf, file_locator): self.file_locator = file_locator |