[Zope3-checkins]
SVN: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/
Moved configuration of garbage collection threshold to its
own feature.
Christian Theune
ct at gocept.com
Sun May 4 08:53:09 EDT 2008
Log message for revision 86356:
Moved configuration of garbage collection threshold to its own feature.
Changed:
A zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/garbagecollection.py
U zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py
-=-
Added: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/garbagecollection.py
===================================================================
--- zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/garbagecollection.py (rev 0)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/garbagecollection.py 2008-05-04 12:53:09 UTC (rev 86356)
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Garbage collection support.
+
+$Id: __init__.py 86218 2008-05-03 14:17:26Z ctheune $
+"""
+
+import gc
+import time
+import zope.testing.testrunner.feature
+
+
+class Threshold(zope.testing.testrunner.feature.Feature):
+
+ def __init__(self, runner):
+ super(Threshold, self).__init__(runner)
+ self.threshold = self.runner.options.gc
+ self.active = bool(self.threshold)
+
+ if not self.active:
+ return
+
+ if len(self.threshold) > 3:
+ output.error("Too many --gc options")
+ sys.exit(1)
+
+ def global_setup(self):
+ self.old_threshold = gc.get_threshold()
+
+ if self.threshold[0]:
+ self.runner.options.output.info(
+ "Cyclic garbage collection threshold set to: %s" %
+ repr(tuple(self.threshold)))
+ else:
+ self.runner.options.output.info(
+ "Cyclic garbage collection is disabled.")
+
+ gc.set_threshold(*self.threshold)
+
+ def global_teardown(self):
+ gc.set_threshold(*self.old_threshold)
Property changes on: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/garbagecollection.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 12:45:10 UTC (rev 86355)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py 2008-05-04 12:53:09 UTC (rev 86356)
@@ -41,6 +41,7 @@
import zope.testing.testrunner.selftest
import zope.testing.testrunner.profiling
import zope.testing.testrunner.timing
+import zope.testing.testrunner.garbagecollection
PYREFCOUNT_PATTERN = re.compile('\[[0-9]+ refs\]')
@@ -102,12 +103,12 @@
return True
self.setup_features()
- self.find_tests()
-
# Global setup
for feature in self.features:
feature.global_setup()
+ self.find_tests()
+
# Late setup
#
# Some system tools like profilers are really bad with stack frames.
@@ -168,27 +169,12 @@
self.features.append(zope.testing.testrunner.doctest.DocTest(self))
self.features.append(zope.testing.testrunner.profiling.Profiling(self))
self.features.append(zope.testing.testrunner.timing.Timing(self))
+ self.features.append(zope.testing.testrunner.garbagecollection.Threshold(self))
# Remove all features that aren't activated
self.features = [f for f in self.features if f.active]
def setup_features(self):
- # Setup garbage collection threshold
- self.old_threshold = gc.get_threshold()
- if self.options.gc:
- if len(self.options.gc) > 3:
- output.error("Too many --gc options")
- sys.exit(1)
- if self.options.gc[0]:
- self.options.output.info(
- "Cyclic garbage collection threshold set to: %s" %
- repr(tuple(self.options.gc)))
- else:
- self.options.output.info(
- "Cyclic garbage collection is disabled.")
-
- gc.set_threshold(*self.options.gc)
-
# Set garbage collection debug flags
self.old_flags = gc.get_debug()
if self.options.gc_option:
@@ -307,9 +293,6 @@
if self.options.gc_option:
gc.set_debug(self.old_flags)
- if self.options.gc:
- gc.set_threshold(*self.old_threshold)
-
def report(self):
if self.options.resume_layer:
sys.stdout.close()
More information about the Zope3-Checkins
mailing list