DebugClients/Python/coverage/report.py

branch
Py2 comp.
changeset 3495
fac17a82b431
parent 790
2c0ea0163ef4
child 3499
f2d4b02c7e88
--- a/DebugClients/Python/coverage/report.py	Fri Apr 04 22:57:07 2014 +0200
+++ b/DebugClients/Python/coverage/report.py	Thu Apr 10 23:02:20 2014 +0200
@@ -1,21 +1,22 @@
 """Reporter foundation for Coverage."""
 
-import os
+import fnmatch, os
 from .codeunit import code_unit_factory
-from .misc import CoverageException, NoSource
+from .files import prep_patterns
+from .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,26 +25,52 @@
         # classes.
         self.directory = None
 
-    def find_code_units(self, morfs, omit_prefixes):
+    def find_code_units(self, morfs):
         """Find the code units we'll report on.
 
-        `morfs` is a list of modules or filenames. `omit_prefixes` is a list
-        of prefixes to leave out of the list.
+        `morfs` is a list of modules or filenames.
 
         """
-        morfs = morfs or self.coverage.data.executed_files()
-        self.code_units = code_unit_factory(
-                            morfs, self.coverage.file_locator, omit_prefixes)
+        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,
-                        omit_prefixes=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`.
+        `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, omit_prefixes)
+        self.find_code_units(morfs)
 
         if not self.code_units:
             raise CoverageException("No data to report.")
@@ -56,8 +83,10 @@
             try:
                 report_fn(cu, self.coverage._analyze(cu))
             except NoSource:
-                if not self.ignore_errors:
+                if not self.config.ignore_errors:
                     raise
-
-#
-# eflag: FileType = Python2
+            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

eric ide

mercurial