SVN: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/ Move coverage analysis out as its own feature.

Christian Theune <[email protected]>
Newsgroups gmane.comp.web.zope.zope3.cvs
Message-ID <[email protected]>
Log message for revision 86335:
  Move coverage analysis out as its own feature.
  

Changed:
  U   zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/__init__.py
  U   zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/coverage.py
  A   zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/feature.py
  U   zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/interfaces.py
  U   zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py
  U   zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/testrunner-layers-api.txt

-=-
Modified: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/__init__.py
===================================================================
--- zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/__init__.py	2008-05-04 11:02:32 UTC (rev 86334)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/__init__.py	2008-05-04 11:02:53 UTC (rev 86335)
@@ -20,12 +20,15 @@
 import unittest
 
 
-from zope.testing.testrunner.runner import Runner
+import zope.testing.testrunner.interfaces
 
 
+
 def run(defaults=None, args=None):
     # This function is here to make the whole test runner compatible before
     # the large refactoring.
+    # XXX Bah. Lazy import to avoid circular/early import problems
+    from zope.testing.testrunner.runner import Runner
     runner = Runner(defaults, args)
     runner.run()
     if runner.failed and runner.options.exitwithstatus:

Modified: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/coverage.py
===================================================================
--- zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/coverage.py	2008-05-04 11:02:32 UTC (rev 86334)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/coverage.py	2008-05-04 11:02:53 UTC (rev 86335)
@@ -21,7 +21,9 @@
 import os.path
 import threading
 
+import zope.testing.testrunner.feature
 
+
 # For some reason, the doctest module resets the trace callable randomly, thus
 # disabling the coverage. Simply disallow the code from doing this. A real
 # trace can be set, so that debugging still works.
@@ -118,3 +120,34 @@
     class TestIgnore(OldTestIgnore):
         def _filenameFormat(self, filename):
             return os.path.normcase(os.path.abspath(filename))
+
+
+class Coverage(zope.testing.testrunner.feature.Feature):
+
+    tracer = None
+    directory = None
+
+    def __init__(self, runner):
+        super(Coverage, self).__init__(runner)
+        self.active = bool(runner.options.coverage)
+
+    def global_setup(self):
+        """Executed once when the test runner is being set up."""
+        self.directory = os.path.join(os.getcwd(), self.runner.options.coverage)
+        self.tracer = TestTrace(self.runner.test_directories,
+                                trace=False, count=True)
+
+    def late_setup(self):
+        """Executed once right before the actual tests get executed and after
+        all global setups have happened."""
+        self.tracer.start()
+
+    def early_teardown(self):
+        """Executed once directly after all tests."""
+        self.tracer.stop()
+
+    def report(self):
+        """Executed once after all tests have been run and all setup was
+        torn down."""
+        r = self.tracer.results()
+        r.write_results(summary=True, coverdir=self.directory)

Added: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/feature.py
===================================================================
--- zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/feature.py	                        (rev 0)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/feature.py	2008-05-04 11:02:53 UTC (rev 86335)
@@ -0,0 +1,63 @@
+##############################################################################
+#
+# Copyright (c) 2004-2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Generic features for the test runner.
+
+$Id: __init__.py 86232 2008-05-03 15:09:33Z ctheune $
+"""
+
+import zope.interface
+import zope.testing.testrunner.interfaces
+
+
+class Feature(object):
+    """A base class implementing no-op methods for the IFeature interface."""
+
+    zope.interface.implements(zope.testing.testrunner.interfaces.IFeature)
+
+    active = False
+
+    def __init__(self, runner):
+        self.runner = runner
+
+    def global_setup(self):
+        """Executed once when the test runner is being set up."""
+        pass
+
+    def late_setup(self):
+        """Executed once right before the actual tests get executed and after
+        all global setups have happened.
+        """
+        pass
+
+    def test_setup(self):
+        """Executed once before each test."""
+        pass
+
+    def test_teardown(self):
+        """Executed once after each test."""
+        pass
+
+    def early_teardown(self):
+        """Executed once directly after all tests."""
+        pass
+
+    def global_teardown(self):
+        """Executed once after all tests where run and early teardowns have
+        happened."""
+        pass
+
+    def report(self):
+        """Executed once after all tests have been run and all setup was
+        torn down."""
+        pass


Property changes on: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/feature.py
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/interfaces.py
===================================================================
--- zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/interfaces.py	2008-05-04 11:02:32 UTC (rev 86334)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/interfaces.py	2008-05-04 11:02:53 UTC (rev 86335)
@@ -28,6 +28,10 @@
     order.
     """
 
+    active = zope.interface.Attribute(
+      "Flag whether this feature is activated. If it is not activated than "
+      "its methods won't be called by the runner.")
+
     def global_setup():
         """Executed once when the test runner is being set up."""
 
@@ -67,7 +71,7 @@
 
     def report():
         """Executed once after all tests have been run and all setup was
-        teared down.
+        torn down.
 
         This is the only method that should produce output.
 

Modified: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py
===================================================================
--- zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py	2008-05-04 11:02:32 UTC (rev 86334)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py	2008-05-04 11:02:53 UTC (rev 86335)
@@ -35,7 +35,7 @@
 from zope.testing.testrunner.find import find_tests, test_dirs
 from zope.testing.testrunner.find import StartUpFailure, import_name
 from zope.testing.testrunner.find import name_from_layer, _layer_name_cache
-from zope.testing.testrunner.coverage import TestTrace
+from zope.testing.testrunner import coverage
 from zope.testing.testrunner.refcount import TrackRefs
 from zope.testing.testrunner.options import get_options
 
@@ -164,6 +164,14 @@
 
         self.options = options
 
+        # XXX I moved this here mechanically.
+        self.test_directories = test_dirs(self.options, {})
+
+        self.features.append(coverage.Coverage(self))
+
+        # Remove all features that aren't activated
+        self.features = [f for f in self.features if f.active]
+
     def setup_features(self):
         # Make sure we start with real pdb.set_trace.  This is needed
         # to make tests of the test runner work properly. :)
@@ -177,13 +185,6 @@
         # Control reporting flags during run
         self.old_reporting_flags = doctest.set_unittest_reportflags(0)
 
-        # Set up code coverage analysis
-        if self.options.coverage:
-            self.tracer = TestTrace(test_dirs(self.options, {}), trace=False, count=True)
-            self.tracer.start()
-        else:
-            self.tracer = None
-
         # Setup profiling
         if (self.options.profile
             and sys.version_info[:3] <= (2,4,1)
@@ -390,9 +391,6 @@
                 self.profiler_stats = self.profiler.loadStats(self.prof_glob)
                 self.profiler_stats.sort_stats('cumulative', 'calls')
 
-        if self.tracer:
-            self.tracer.stop()
-
         doctest.set_unittest_reportflags(self.old_reporting_flags)
 
     def report(self):
@@ -420,12 +418,7 @@
         if self.options.profile and not self.options.resume_layer:
             self.options.output.profiler_stats(self.profiler_stats)
 
-        if self.tracer:
-            coverdir = os.path.join(os.getcwd(), self.options.coverage)
-            r = self.tracer.results()
-            r.write_results(summary=True, coverdir=coverdir)
 
-
 def run_tests(options, tests, name, failures, errors):
     repeat = options.repeat or 1
     repeat_range = iter(range(repeat))

Modified: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/testrunner-layers-api.txt
===================================================================
--- zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/testrunner-layers-api.txt	2008-05-04 11:02:32 UTC (rev 86334)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/testrunner-layers-api.txt	2008-05-04 11:02:53 UTC (rev 86335)
@@ -111,7 +111,7 @@
 the TestSpecifyingNoLayer was run and setup/torn down around the
 TestSpecifyingBaseLayer tests.
 
->>> from zope.testing.testrunner import Runner
+>>> from zope.testing.testrunner.runner import Runner
 >>> runner = Runner(options=fresh_options(), args=[], found_suites=[umbrella_suite])
 >>> succeeded = runner.run()
 Running unit tests:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.