From 3fa1d99066ecbbd02b15885b18c6e99385733954 Mon Sep 17 00:00:00 2001 From: Zooko Ofsimplegeo Date: Mon, 19 Apr 2010 16:08:37 -0600 Subject: add a --require option to specify directories which are required to be at the beginning of the path for any file that is going to be included in code coverage make the --omit and --require options apply to code coverage generation as well as to reporting; This speeds up tests from 6 seconds to 1 second on my system, as well as making the resulting .coverage db include *only* the code that I care about, which helps with my code coverage progression/regression tool. --- coverage/codeunit.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'coverage/codeunit.py') diff --git a/coverage/codeunit.py b/coverage/codeunit.py index 9bf6dc9..51640b8 100644 --- a/coverage/codeunit.py +++ b/coverage/codeunit.py @@ -6,13 +6,16 @@ from coverage.backward import string_class, StringIO from coverage.misc import CoverageException -def code_unit_factory(morfs, file_locator, omit_prefixes=None): +def code_unit_factory(morfs, file_locator, omit_prefixes=None, require_prefixes=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. `omit_prefixes` is a list of prefixes. CodeUnits that match those prefixes will be omitted from the list. + `require_prefixes` is a list of prefixes. Only CodeUnits that match those prefixes + will be included in the list. + You are required to pass at most one of `omit_prefixes` and `require_prefixes`. Returns a list of CodeUnit objects. @@ -33,7 +36,18 @@ def code_unit_factory(morfs, file_locator, omit_prefixes=None): code_units = [CodeUnit(morf, file_locator) for morf in morfs] - if omit_prefixes: + if require_prefixes: + assert not isinstance(require_prefixes, string_class) # common mistake + prefixes = [file_locator.abs_file(p) for p in require_prefixes] + filtered = [] + for cu in code_units: + for prefix in prefixes: + if cu.filename.startswith(prefix): + filtered.append(cu) + break + + code_units = filtered + elif omit_prefixes: assert not isinstance(omit_prefixes, string_class) # common mistake prefixes = [file_locator.abs_file(p) for p in omit_prefixes] filtered = [] -- cgit v1.2.1