Commits

Ned Batchelder  committed b7c2183 Merge

Automated merge with ssh://bitbucket.org/ned/coveragepy

  • Participants
  • Parent commits ebf015e, ebced10

Comments (0)

Files changed (3)

File coverage/control.py

         self.pylib_match = self.cover_match = None
         self.include_match = self.omit_match = None
 
-        # Only _harvest_data once per measurement cycle.
-        self._harvested = False
-
         # Set the reporting precision.
         Numbers.set_precision(self.config.precision)
 
         if self.omit:
             self.omit_match = FnmatchMatcher(self.omit)
 
-        self._harvested = False
         self.collector.start()
         self._started = True
 
                 for pattern in paths[1:]:
                     aliases.add(pattern, result)
         self.data.combine_parallel_data(aliases=aliases)
-        # Combining is a kind of harvesting.
-        self._harvested = True
 
     def _harvest_data(self):
         """Get the collected data and reset the collector.
         Also warn about various problems collecting data.
 
         """
-        if not self._harvested:
-            self.data.add_line_data(self.collector.get_line_data())
-            self.data.add_arc_data(self.collector.get_arc_data())
-            self.collector.reset()
+        self.data.add_line_data(self.collector.get_line_data())
+        self.data.add_arc_data(self.collector.get_arc_data())
+        self.collector.reset()
 
-            # If there are still entries in the source_pkgs list, then we never
-            # encountered those packages.
-            if self._warn_unimported_source:
-                for pkg in self.source_pkgs:
-                    self._warn("Module %s was never imported." % pkg)
+        # If there are still entries in the source_pkgs list, then we never
+        # encountered those packages.
+        if self._warn_unimported_source:
+            for pkg in self.source_pkgs:
+                self._warn("Module %s was never imported." % pkg)
 
-            # Find out if we got any data.
-            summary = self.data.summary()
-            if not summary and self._warn_no_data:
-                self._warn("No data was collected.")
+        # Find out if we got any data.
+        summary = self.data.summary()
+        if not summary and self._warn_no_data:
+            self._warn("No data was collected.")
 
-            # Find files that were never executed at all.
-            for src in self.source:
-                for py_file in find_python_files(src):
-                    py_file = self.file_locator.canonical_filename(py_file)
-                    self.data.touch_file(py_file)
-
-            self._harvested = True
+        # Find files that were never executed at all.
+        for src in self.source:
+            for py_file in find_python_files(src):
+                py_file = self.file_locator.canonical_filename(py_file)
+                self.data.touch_file(py_file)
 
     # Backward compatibility with version 1.
     def analysis(self, morf):
     """Install the egg1 egg for tests."""
     # I am pretty certain there are easier ways to install eggs...
     # pylint: disable=F0401,E0611,E1101
-    import distutils.core       
+    import distutils.core
     cur_dir = os.getcwd()
     os.chdir("test/eggsrc")
     distutils.core.run_setup("setup.py", ["--quiet", "bdist_egg"])
     check_files("test", ["*,cover"], trail_white=False)
     check_files("test/js", ["*.js", "*.html"])
     check_file("setup.py")
+    check_file("igor.py")
     check_files("doc", ["*.rst"])
     check_files(".", ["*.txt"])
 
 
 def main(args):
     """Main command-line execution for igor.
-    
+
     Verbs are taken from the command line, and extra words taken as directed
     by the arguments needed by the handler.
 

File test/test_api.py

         self.assertEqual(nums.n_branches, 2)
         self.assertEqual(nums.n_partial_branches, 0)
         self.assertEqual(nums.n_missing_branches, 2)
+
+
+class PluginTest(CoverageTest):
+    """Test that the API works properly the way the plugins call it.
+
+    We don't actually use the plugins, but these tests call the API the same
+    way they do.
+
+    """
+    def pretend_to_be_nose_with_cover(self, erase):
+        """This is what the nose --with-cover plugin does."""
+        cov = coverage.coverage()
+
+        self.make_file("no_biggie.py", """\
+            a = 1
+            b = 2
+            if b == 1:
+                c = 4
+            """)
+
+        if erase:
+            cov.combine()
+            cov.erase()
+        cov.load()
+        self.start_import_stop(cov, "no_biggie")
+        cov.combine()
+        cov.save()
+        cov.report(["no_biggie.py"])
+        self.assertEqual(self.stdout(), textwrap.dedent("""\
+            Name        Stmts   Miss  Cover   Missing
+            -----------------------------------------
+            no_biggie       4      1    75%   4
+            """))
+
+    def test_nose_plugin(self):
+        self.pretend_to_be_nose_with_cover(erase=False)
+
+    def test_nose_plugin_with_erase(self):
+        self.pretend_to_be_nose_with_cover(erase=True)