Commits

Ned Batchelder committed 978c427

Pass config objects around to limit the sprawl of argument lists.

  • Participants
  • Parent commits b0e9e39

Comments (0)

Files changed (6)

File coverage/annotate.py

     blank_re = re.compile(r"\s*(#|$)")
     else_re = re.compile(r"\s*else\s*:\s*(#|$)")
 
-    def report(self, morfs, directory=None, omit=None, include=None):
+    def report(self, morfs, config, directory=None):
         """Run the report.
 
         See `coverage.report()` for arguments.
 
         """
-        self.report_files(self.annotate_file, morfs, directory, omit, include)
+        self.report_files(self.annotate_file, morfs, config, directory)
 
     def annotate_file(self, cu, analysis):
         """Annotate a single file.

File coverage/control.py

         reporter = SummaryReporter(
             self, show_missing, self.config.ignore_errors
             )
-        reporter.report(
-            morfs, outfile=file, omit=self.config.omit,
-            include=self.config.include
-            )
+        reporter.report(morfs, outfile=file, config=self.config)
 
     def annotate(self, morfs=None, directory=None, ignore_errors=None,
                     omit=None, include=None):
             ignore_errors=ignore_errors, omit=omit, include=include
             )
         reporter = AnnotateReporter(self, self.config.ignore_errors)
-        reporter.report(
-            morfs, directory=directory,
-            omit=self.config.omit,
-            include=self.config.include
-            )
+        reporter.report(morfs, config=self.config, directory=directory)
 
     def html_report(self, morfs=None, directory=None, ignore_errors=None,
                     omit=None, include=None):
             html_dir=directory,
             )
         reporter = HtmlReporter(self, self.config.ignore_errors)
-        reporter.report(
-            morfs, directory=self.config.html_dir,
-            omit=self.config.omit,
-            include=self.config.include
-            )
+        reporter.report(morfs, config=self.config)
 
     def xml_report(self, morfs=None, outfile=None, ignore_errors=None,
                     omit=None, include=None):
                 file_to_close = outfile
         try:
             reporter = XmlReporter(self, self.config.ignore_errors)
-            reporter.report(
-                morfs, omit=self.config.omit, include=self.config.include,
-                outfile=outfile
-                )
+            reporter.report(morfs, outfile=outfile, config=self.config)
         finally:
             if file_to_close:
                 file_to_close.close()

File coverage/html.py

         self.files = []
         self.arcs = coverage.data.has_arcs()
 
-    def report(self, morfs, directory, omit=None, include=None):
+    def report(self, morfs, config=None):
         """Generate an HTML report for `morfs`.
 
-        `morfs` is a list of modules or filenames.  `directory` is where to put
-        the HTML files.
-
-        See `coverage.report()` for other arguments.
+        `morfs` is a list of modules or filenames.  `config` is a
+        CoverageConfig instance.
 
         """
-        assert directory, "must provide a directory for html reporting"
+        assert config.html_dir, "must provide a directory for html reporting"
 
         # Process all the files.
-        self.report_files(self.html_file, morfs, directory, omit, include)
+        self.report_files(self.html_file, morfs, config, config.html_dir)
 
         if not self.files:
             raise CoverageException("No data to report.")
             ]:
             shutil.copyfile(
                 data_filename("htmlfiles/" + static),
-                os.path.join(directory, static)
+                os.path.join(self.directory, static)
                 )
 
     def html_file(self, cu, analysis):

File coverage/report.py

         # classes.
         self.directory = None
 
-    def find_code_units(self, morfs, omit, include):
+    def find_code_units(self, morfs, config):
         """Find the code units we'll report on.
 
-        `morfs` is a list of modules or filenames.
-
-        See `coverage.report()` for other arguments.
+        `morfs` is a list of modules or filenames. `config` is a
+        CoverageConfig instance.
 
         """
         morfs = morfs or self.coverage.data.executed_files()
         file_locator = self.coverage.file_locator
         self.code_units = code_unit_factory(morfs, file_locator)
 
-        if include:
-            assert not isinstance(include, string_class) # common mistake
-            patterns = [file_locator.abs_file(p) for p in include]
+        if config.include:
+            patterns = [file_locator.abs_file(p) for p in config.include]
             filtered = []
             for cu in self.code_units:
                 for pattern in patterns:
                         break
             self.code_units = filtered
 
-        if omit:
-            assert not isinstance(omit, string_class) # common mistake
-            patterns = [file_locator.abs_file(p) for p in omit]
+        if config.omit:
+            patterns = [file_locator.abs_file(p) for p in config.omit]
             filtered = []
             for cu in self.code_units:
                 for pattern in patterns:
 
         self.code_units.sort()
 
-    def report_files(self, report_fn, morfs, directory=None,
-                        omit=None, include=None):
+    def report_files(self, report_fn, morfs, config, directory=None):
         """Run a reporting function on a number of morfs.
 
         `report_fn` is called for each relative morf in `morfs`.
 
-        `include` is a list of filename patterns. CodeUnits that match
-        those patterns will be included in the list. CodeUnits that match
-        `omit` will be omitted from the list.
+        `config` is a CoverageConfig instance.
 
         """
-        self.find_code_units(morfs, omit, include)
+        self.find_code_units(morfs, config)
 
         if not self.code_units:
             raise CoverageException("No data to report.")

File coverage/summary.py

         self.show_missing = show_missing
         self.branches = coverage.data.has_arcs()
 
-    def report(self, morfs, omit=None, outfile=None, include=None):
+    def report(self, morfs, outfile=None, config=None):
         """Writes a report summarizing coverage statistics per module.
 
-        See `coverage.report()` for other arguments.
+        `outfile` is a file object to write the summary to.  `config` is a
+        CoverageConfig instance.
 
         """
-        self.find_code_units(morfs, omit, include)
+        self.find_code_units(morfs, config)
 
         # Prepare the formatting strings
         max_name = max([len(cu.name) for cu in self.code_units] + [5])

File coverage/xmlreport.py

         self.xml_out = None
         self.arcs = coverage.data.has_arcs()
 
-    def report(self, morfs, omit=None, include=None, outfile=None):
+    def report(self, morfs, outfile=None, config=None):
         """Generate a Cobertura-compatible XML report for `morfs`.
 
         `morfs` is a list of modules or filenames.
 
-        See `coverage.report()` for other arguments.
+        `outfile` is a file object to write the XML to.  `config` is a
+        CoverageConfig instance.
 
         """
         # Initial setup.
 
         # Call xml_file for each file in the data.
         self.packages = {}
-        self.report_files(self.xml_file, morfs, omit=omit, include=include)
+        self.report_files(self.xml_file, morfs, config)
 
         lnum_tot, lhits_tot = 0, 0
         bnum_tot, bhits_tot = 0, 0