[Zope3-checkins] SVN: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/ Moved the listing into its own feature and made it a report.

Christian Theune ct at gocept.com
Sun May 4 12:23:35 EDT 2008


Log message for revision 86399:
  Moved the listing into its own feature and made it a report.
  

Changed:
  U   zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/filter.py
  A   zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/listing.py
  U   zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py

-=-
Modified: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/filter.py
===================================================================
--- zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/filter.py	2008-05-04 16:17:25 UTC (rev 86398)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/filter.py	2008-05-04 16:23:35 UTC (rev 86399)
@@ -21,7 +21,7 @@
 
 
 class Filter(zope.testing.testrunner.feature.Feature):
-    """Filters all tests registered until now."""
+    """Filters and orders all tests registered until now."""
 
     active = True
 

Added: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/listing.py
===================================================================
--- zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/listing.py	                        (rev 0)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/listing.py	2008-05-04 16:23:35 UTC (rev 86399)
@@ -0,0 +1,39 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Filter which tests to run.
+
+$Id: __init__.py 86218 2008-05-03 14:17:26Z ctheune $
+"""
+
+import time
+import zope.testing.testrunner.feature
+
+
+class Listing(zope.testing.testrunner.feature.Feature):
+    """Lists all tests in the report instead of running the tests."""
+
+    def __init__(self, runner):
+        super(Listing, self).__init__(runner)
+        self.active = bool(runner.options.list_tests)
+
+    def global_setup(self):
+        self.runner.do_run_tests = False
+        self.runner.failed = False
+
+    def report(self):
+        layers = self.runner.tests_by_layer_name
+        if 'unit' in layers:
+            self.runner.options.output.list_of_tests(layers['unit'], 'unit')
+        for layer_name, layer, tests in self.runner.ordered_layers():
+            self.runner.options.output.list_of_tests(tests, layer_name)


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

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 16:17:25 UTC (rev 86398)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py	2008-05-04 16:23:35 UTC (rev 86399)
@@ -43,6 +43,7 @@
 import zope.testing.testrunner.timing
 import zope.testing.testrunner.filter
 import zope.testing.testrunner.garbagecollection
+import zope.testing.testrunner.listing
 
 
 PYREFCOUNT_PATTERN = re.compile('\[[0-9]+ refs\]')
@@ -95,11 +96,20 @@
         self.nlayers = 0
 
         self.show_report = True
+        self.do_run_tests = True
 
         self.features = []
 
         self.tests_by_layer_name = {}
 
+    def ordered_layers(self):
+        layer_names = dict([(layer_from_name(layer_name), layer_name)
+                            for layer_name in self.tests_by_layer_name
+                            if layer_name != 'unit'])
+        for layer in order_by_bases(layer_names):
+            layer_name = layer_names[layer]
+            yield layer_name, layer, self.tests_by_layer_name[layer_name]
+
     def register_tests(self, tests):
         """Registers tests."""
         # XXX To support multiple features that find tests this shouldn't be
@@ -139,7 +149,8 @@
             feature.late_setup()
 
         try:
-            self.run_tests()
+            if self.do_run_tests:
+                self.run_tests()
         finally:
             # Early teardown
             for feature in reversed(self.features):
@@ -149,7 +160,8 @@
                 feature.global_teardown()
 
         if self.show_report:
-            self.report()
+            if self.do_run_tests:
+                self.report()
             for feature in self.features:
                 feature.report()
 
@@ -193,6 +205,7 @@
         self.features.append(zope.testing.testrunner.garbagecollection.Debug(self))
         self.features.append(zope.testing.testrunner.find.Find(self))
         self.features.append(zope.testing.testrunner.filter.Filter(self))
+        self.features.append(zope.testing.testrunner.listing.Listing(self))
 
         # Remove all features that aren't activated
         self.features = [f for f in self.features if f.active]
@@ -205,21 +218,19 @@
         """
         if 'unit' in self.tests_by_layer_name:
             tests = self.tests_by_layer_name.pop('unit')
-            if self.options.list_tests:
-                self.options.output.list_of_tests(tests, 'unit')
-            else:
-                self.options.output.info("Running unit tests:")
-                self.nlayers += 1
-                try:
-                    self.ran += run_tests(self.options, tests, 'unit',
-                                          self.failures, self.errors)
-                except EndRun:
-                    self.failed = True
-                    return
+            self.options.output.info("Running unit tests:")
+            self.nlayers += 1
+            try:
+                self.ran += run_tests(self.options, tests, 'unit',
+                                      self.failures, self.errors)
+            except EndRun:
+                self.failed = True
+                return
 
         setup_layers = {}
 
-        layers_to_run = list(ordered_layers(self.tests_by_layer_name))
+        layers_to_run = list(self.ordered_layers())
+
         if self.options.resume_layer is not None:
             layers_to_run = [
                 (layer_name, layer, tests)
@@ -233,13 +244,6 @@
                 if filter(None, [pat(layer_name) for pat in self.options.layer])
             ]
 
-        if self.options.list_tests:
-            for layer_name, layer, tests in layers_to_run:
-                self.options.output.list_of_tests(tests, layer_name)
-            self.failed = False
-            self.show_report = False
-            return
-
         for layer_name, layer, tests in layers_to_run:
             self.nlayers += 1
             try:
@@ -629,12 +633,6 @@
             self.options.output.test_threads(test, new_threads)
 
 
-def ordered_layers(tests_by_layer_name):
-    layer_names = dict([(layer_from_name(layer_name), layer_name)
-                        for layer_name in tests_by_layer_name])
-    for layer in order_by_bases(layer_names):
-        layer_name = layer_names[layer]
-        yield layer_name, layer, tests_by_layer_name[layer_name]
 
 
 def layer_from_name(layer_name):



More information about the Zope3-Checkins mailing list