[Checkins] SVN: zope.testing/branches/ctheune-entrypoints/s Snapshot: pull in features using entry points.

Christian Theune ct at gocept.com
Tue Apr 21 16:10:24 EDT 2009


Log message for revision 99353:
  Snapshot: pull in features using entry points. 
  
  I think I'll revamp that again as the entry points are too generic to be
  useful.
  

Changed:
  U   zope.testing/branches/ctheune-entrypoints/setup.py
  U   zope.testing/branches/ctheune-entrypoints/src/zope/testing/testrunner/runner.py

-=-
Modified: zope.testing/branches/ctheune-entrypoints/setup.py
===================================================================
--- zope.testing/branches/ctheune-entrypoints/setup.py	2009-04-21 16:20:36 UTC (rev 99352)
+++ zope.testing/branches/ctheune-entrypoints/setup.py	2009-04-21 20:10:24 UTC (rev 99353)
@@ -89,4 +89,21 @@
 
     packages=["zope", "zope.testing"],
     package_dir = {'': 'src'},
+
+    entry_points="""
+    [zope.testing.testrunner.features]
+    selftest = zope.testing.testrunner.selftest:SelfTest
+    logging = zope.testing.testrunner.logsupport:Logging
+    coverage = zope.testing.testrunner.coverage:Coverage
+    doctest = zope.testing.testrunner.doctest:DocTest
+    profiling = zope.testing.testrunner.profiling:Profiling
+    threshold = zope.testing.testrunner.garbagecollection:Threshold
+    debug = zope.testing.testrunner.garbagecollection:Debug
+    find = zope.testing.testrunner.find:Find
+    subprocess = zope.testing.testrunner.subprocess:SubProcess
+    filter = zope.testing.testrunner.filter:Filter
+    listing = zope.testing.testrunner.listing:Listing
+    statistics = zope.testing.testrunner.statistics:Statistics
+
+    """,
     **extra)

Modified: zope.testing/branches/ctheune-entrypoints/src/zope/testing/testrunner/runner.py
===================================================================
--- zope.testing/branches/ctheune-entrypoints/src/zope/testing/testrunner/runner.py	2009-04-21 16:20:36 UTC (rev 99352)
+++ zope.testing/branches/ctheune-entrypoints/src/zope/testing/testrunner/runner.py	2009-04-21 20:10:24 UTC (rev 99353)
@@ -33,6 +33,7 @@
 import time
 import traceback
 import unittest
+import pkg_resources
 
 from zope.testing import doctest
 from zope.testing.testrunner.find import find_tests, test_dirs
@@ -55,7 +56,6 @@
 
 PYREFCOUNT_PATTERN = re.compile('\[[0-9]+ refs\]')
 
-is_jython = sys.platform.startswith('java')
 
 class SubprocessError(Exception):
     """An error occurred when running a subprocess
@@ -69,6 +69,11 @@
         return '%s: %s' % (self.reason, self.stderr)
 
 
+FEATURE_ORDER = [
+    'selftest', 'logging', 'coverage', 'doctest', 'profiling', 'threshold',
+    'debug', 'find', 'subprocess', 'filter', 'listing', 'statistics']
+
+
 class CanNotTearDown(Exception):
     "Couldn't tear down a test"
 
@@ -97,7 +102,10 @@
         self.show_report = True
         self.do_run_tests = True
 
-        self.features = []
+        features = pkg_resources.iter_entry_points(
+            'zope.testing.testrunner.features')
+        self.features = list(features)
+        self.features.sort(key=lambda x:FEATURE_ORDER.index(x.name))
 
         self.tests_by_layer_name = {}
 
@@ -180,25 +188,8 @@
         # XXX I moved this here mechanically. Move to find feature?
         self.test_directories = test_dirs(self.options, {})
 
-        self.features.append(zope.testing.testrunner.selftest.SelfTest(self))
-        self.features.append(zope.testing.testrunner.logsupport.Logging(self))
-        self.features.append(zope.testing.testrunner.coverage.Coverage(self))
-        self.features.append(zope.testing.testrunner.doctest.DocTest(self))
-        self.features.append(zope.testing.testrunner.profiling.Profiling(self))
-        if is_jython:
-            # Jython GC support is not yet implemented
-            pass
-        else:
-            self.features.append(zope.testing.testrunner.garbagecollection.Threshold(self))
-            self.features.append(zope.testing.testrunner.garbagecollection.Debug(self))
-
-        self.features.append(zope.testing.testrunner.find.Find(self))
-        self.features.append(zope.testing.testrunner.subprocess.SubProcess(self))
-        self.features.append(zope.testing.testrunner.filter.Filter(self))
-        self.features.append(zope.testing.testrunner.listing.Listing(self))
-        self.features.append(zope.testing.testrunner.statistics.Statistics(self))
-
-        # Remove all features that aren't activated
+        # Activate features
+        self.features = [f.load()(self) for f in self.features]
         self.features = [f for f in self.features if f.active]
 
     def run_tests(self):
@@ -252,12 +243,8 @@
 
     output = options.output
 
-    if is_jython:
-        # Jython has no GC suppport - set count to 0
-        lgarbage = 0
-    else:
-        gc.collect()
-        lgarbage = len(gc.garbage)
+    gc.collect()
+    lgarbage = len(gc.garbage)
 
     sumrc = 0
     if options.report_refcounts:
@@ -317,13 +304,10 @@
         output.summary(result.testsRun, len(result.failures), len(result.errors), t)
         ran = result.testsRun
 
-        if is_jython:
-            lgarbage = 0
-        else:
-            gc.collect()
-            if len(gc.garbage) > lgarbage:
-                output.garbage(gc.garbage[lgarbage:])
-                lgarbage = len(gc.garbage)
+        gc.collect()
+        if len(gc.garbage) > lgarbage:
+            output.garbage(gc.garbage[lgarbage:])
+            lgarbage = len(gc.garbage)
 
         if options.report_refcounts:
 
@@ -618,13 +602,10 @@
         self.testTearDown()
         self.options.output.stop_test(test)
 
-        if is_jython:
-            pass
-        else:
-            if gc.garbage:
-                self.options.output.test_garbage(test, gc.garbage)
-                # TODO: Perhaps eat the garbage here, so that the garbage isn't
-                #       printed for every subsequent test.
+        if gc.garbage:
+            self.options.output.test_garbage(test, gc.garbage)
+            # TODO: Perhaps eat the garbage here, so that the garbage isn't
+            #       printed for every subsequent test.
 
         # Did the test leave any new threads behind?
         new_threads = [t for t in threading.enumerate()



More information about the Checkins mailing list