From 43bf01f860dff446b30d5ca00bcd0dd1e41e9a09 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 19 Apr 2012 19:05:22 -0400 Subject: Refactor reporters so the config is part of construction, and is then available everywhere. --- coverage/report.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'coverage/report.py') diff --git a/coverage/report.py b/coverage/report.py index 5d187996..f6a9c2a8 100644 --- a/coverage/report.py +++ b/coverage/report.py @@ -7,15 +7,15 @@ from coverage.misc import CoverageException, NoSource, NotPython class Reporter(object): """A base class for all reporters.""" - def __init__(self, coverage, ignore_errors=False): + def __init__(self, coverage, config): """Create a reporter. - `coverage` is the coverage instance. `ignore_errors` controls how - skittish the reporter will be during file processing. + `coverage` is the coverage instance. `config` is an instance of + CoverageConfig, for controlling all sorts of behavior. """ self.coverage = coverage - self.ignore_errors = ignore_errors + self.config = config # The code units to report on. Set by find_code_units. self.code_units = [] @@ -24,19 +24,18 @@ class Reporter(object): # classes. self.directory = None - def find_code_units(self, morfs, config): + def find_code_units(self, morfs): """Find the code units we'll report on. - `morfs` is a list of modules or filenames. `config` is a - CoverageConfig instance. + `morfs` is a list of modules or filenames. """ morfs = morfs or self.coverage.data.measured_files() file_locator = self.coverage.file_locator self.code_units = code_unit_factory(morfs, file_locator) - if config.include: - patterns = [file_locator.abs_file(p) for p in config.include] + if self.config.include: + patterns = [file_locator.abs_file(p) for p in self.config.include] filtered = [] for cu in self.code_units: for pattern in patterns: @@ -45,8 +44,8 @@ class Reporter(object): break self.code_units = filtered - if config.omit: - patterns = [file_locator.abs_file(p) for p in config.omit] + if self.config.omit: + patterns = [file_locator.abs_file(p) for p in self.config.omit] filtered = [] for cu in self.code_units: for pattern in patterns: @@ -58,7 +57,7 @@ class Reporter(object): self.code_units.sort() - def report_files(self, report_fn, morfs, config, directory=None): + def report_files(self, report_fn, morfs, directory=None): """Run a reporting function on a number of morfs. `report_fn` is called for each relative morf in `morfs`. It is called @@ -69,10 +68,8 @@ class Reporter(object): where `code_unit` is the `CodeUnit` for the morf, and `analysis` is the `Analysis` for the morf. - `config` is a CoverageConfig instance. - """ - self.find_code_units(morfs, config) + self.find_code_units(morfs) if not self.code_units: raise CoverageException("No data to report.") @@ -85,10 +82,10 @@ class Reporter(object): try: report_fn(cu, self.coverage._analyze(cu)) except NoSource: - if not self.ignore_errors: + if not self.config.ignore_errors: raise except NotPython: # Only report errors for .py files, and only if we didn't # explicitly suppress those errors. - if cu.should_be_python(".py") and not self.ignore_errors: + if cu.should_be_python(".py") and not self.config.ignore_errors: raise -- cgit v1.2.1