Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Unified Diff: third_party/pycoverage/coverage/report.py

Issue 727003004: Add python coverage module to third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/pycoverage/coverage/phystokens.py ('k') | third_party/pycoverage/coverage/results.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/pycoverage/coverage/report.py
diff --git a/third_party/pycoverage/coverage/report.py b/third_party/pycoverage/coverage/report.py
new file mode 100644
index 0000000000000000000000000000000000000000..34f44422298ec7519d221d85cb48ff8b2e52ba27
--- /dev/null
+++ b/third_party/pycoverage/coverage/report.py
@@ -0,0 +1,92 @@
+"""Reporter foundation for Coverage."""
+
+import fnmatch, os
+from coverage.codeunit import code_unit_factory
+from coverage.files import prep_patterns
+from coverage.misc import CoverageException, NoSource, NotPython
+
+class Reporter(object):
+ """A base class for all reporters."""
+
+ def __init__(self, coverage, config):
+ """Create a reporter.
+
+ `coverage` is the coverage instance. `config` is an instance of
+ CoverageConfig, for controlling all sorts of behavior.
+
+ """
+ self.coverage = coverage
+ self.config = config
+
+ # The code units to report on. Set by find_code_units.
+ self.code_units = []
+
+ # The directory into which to place the report, used by some derived
+ # classes.
+ self.directory = None
+
+ def find_code_units(self, morfs):
+ """Find the code units we'll report on.
+
+ `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 self.config.include:
+ patterns = prep_patterns(self.config.include)
+ filtered = []
+ for cu in self.code_units:
+ for pattern in patterns:
+ if fnmatch.fnmatch(cu.filename, pattern):
+ filtered.append(cu)
+ break
+ self.code_units = filtered
+
+ if self.config.omit:
+ patterns = prep_patterns(self.config.omit)
+ filtered = []
+ for cu in self.code_units:
+ for pattern in patterns:
+ if fnmatch.fnmatch(cu.filename, pattern):
+ break
+ else:
+ filtered.append(cu)
+ self.code_units = filtered
+
+ self.code_units.sort()
+
+ 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
+ as::
+
+ report_fn(code_unit, analysis)
+
+ where `code_unit` is the `CodeUnit` for the morf, and `analysis` is
+ the `Analysis` for the morf.
+
+ """
+ self.find_code_units(morfs)
+
+ if not self.code_units:
+ raise CoverageException("No data to report.")
+
+ self.directory = directory
+ if self.directory and not os.path.exists(self.directory):
+ os.makedirs(self.directory)
+
+ for cu in self.code_units:
+ try:
+ report_fn(cu, self.coverage._analyze(cu))
+ except NoSource:
+ 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() and not self.config.ignore_errors:
+ raise
« no previous file with comments | « third_party/pycoverage/coverage/phystokens.py ('k') | third_party/pycoverage/coverage/results.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698