[Zope-Checkins] SVN: Zope/branches/2.10/lib/python/Testing/ZopeTestCase/ Use a decorator to save and restore thread-local state.
Log message for revision 73184: Use a decorator to save and restore thread-local state. Changed: U Zope/branches/2.10/lib/python/Testing/ZopeTestCase/functional.py U Zope/branches/2.10/lib/python/Testing/ZopeTestCase/zopedoctest/functional.py -=- Modified: Zope/branches/2.10/lib/python/Testing/ZopeTestCase/functional.py === --- Zope/branches/2.10/lib/python/Testing/ZopeTestCase/functional.py 2007-03-15 04:23:45 UTC (rev 73183) +++ Zope/branches/2.10/lib/python/Testing/ZopeTestCase/functional.py 2007-03-15 09:58:25 UTC (rev 73184) @@ -23,6 +23,25 @@ import interfaces +def savestate(func): +'''Decorator saving thread local state before executing func + and restoring it afterwards. +''' +from AccessControl.SecurityManagement import getSecurityManager +from AccessControl.SecurityManagement import setSecurityManager +from zope.app.component.hooks import getSite +from zope.app.component.hooks import setSite + +def wrapped_func(*args, **kw): +sm, site = getSecurityManager(), getSite() +try: +return func(*args, **kw) +finally: +setSecurityManager(sm) +setSite(site) +return wrapped_func + + class Functional(sandbox.Sandboxed): '''Derive from this class and an xTestCase to get functional testing support:: @@ -33,25 +52,15 @@ __implements__ = (interfaces.IFunctional,) +@savestate def publish(self, path, basic=None, env=None, extra=None, request_method='GET', stdin=None, handle_errors=True): '''Publishes the object at 'path' returning a response object.''' -from zope.app.component.hooks import setSite, getSite from StringIO import StringIO from ZPublisher.Response import Response from ZPublisher.Test import publish_module -from AccessControl.SecurityManagement import getSecurityManager -from AccessControl.SecurityManagement import setSecurityManager - -# Save current security manager -sm = getSecurityManager() - -# And we need to store the old site -old_site = getSite() -setSite(None) - # Commit the sandbox for good measure transaction.commit() @@ -91,12 +100,6 @@ debug=not handle_errors, ) -# Restore security manager -setSecurityManager(sm) - -# And we need to restore the site again -setSite(old_site) - return ResponseWrapper(response, outstream, path) Modified: Zope/branches/2.10/lib/python/Testing/ZopeTestCase/zopedoctest/functional.py === --- Zope/branches/2.10/lib/python/Testing/ZopeTestCase/zopedoctest/functional.py 2007-03-15 04:23:45 UTC (rev 73183) +++ Zope/branches/2.10/lib/python/Testing/ZopeTestCase/zopedoctest/functional.py 2007-03-15 09:58:25 UTC (rev 73184) @@ -31,6 +31,7 @@ from Testing.ZopeTestCase import standard_permissions from Testing.ZopeTestCase.sandbox import AppZapper from Testing.ZopeTestCase.functional import ResponseWrapper +from Testing.ZopeTestCase.functional import savestate class HTTPHeaderOutput: @@ -110,6 +111,7 @@ getRootFolder()._p_jar.sync() [EMAIL PROTECTED] def http(request_string, handle_errors=True): """Execute an HTTP request string via the publisher @@ -117,20 +119,10 @@ """ import urllib import rfc822 -from zope.app.component.hooks import setSite, getSite from cStringIO import StringIO from ZPublisher.Response import Response from ZPublisher.Test import publish_module -from AccessControl.SecurityManagement import getSecurityManager -from AccessControl.SecurityManagement import setSecurityManager -# Save current Security Manager -old_sm = getSecurityManager() - -# And we need to store the old site -old_site = getSite() -setSite(None) - # Commit work done by previous python code. transaction.commit() @@ -194,14 +186,6 @@ header_output.appendResponseHeaders(response._cookie_list()) header_output.appendResponseHeaders(response.accumulated_headers.splitlines()) -# Restore previous security manager, which may have been changed -# by calling the publish method above -setSecurityManager(old_sm) - -# And we need to restore the site again -setSite(old_site) -# Sync connection - sync() return DocResponseWrapper(response, outstream, path, header_output) ___ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins
[Zope-Checkins] SVN: Zope/trunk/lib/python/Testing/ZopeTestCase/ Merged r73183:73184 from 2.10 branch.
Log message for revision 73185: Merged r73183:73184 from 2.10 branch. Use a decorator to save and restore thread-local state. Changed: U Zope/trunk/lib/python/Testing/ZopeTestCase/functional.py U Zope/trunk/lib/python/Testing/ZopeTestCase/zopedoctest/functional.py -=- Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/functional.py === --- Zope/trunk/lib/python/Testing/ZopeTestCase/functional.py2007-03-15 09:58:25 UTC (rev 73184) +++ Zope/trunk/lib/python/Testing/ZopeTestCase/functional.py2007-03-15 10:04:04 UTC (rev 73185) @@ -25,6 +25,25 @@ from zope.interface import implements +def savestate(func): +'''Decorator saving thread local state before executing func + and restoring it afterwards. +''' +from AccessControl.SecurityManagement import getSecurityManager +from AccessControl.SecurityManagement import setSecurityManager +from zope.app.component.hooks import getSite +from zope.app.component.hooks import setSite + +def wrapped_func(*args, **kw): +sm, site = getSecurityManager(), getSite() +try: +return func(*args, **kw) +finally: +setSecurityManager(sm) +setSite(site) +return wrapped_func + + class Functional(sandbox.Sandboxed): '''Derive from this class and an xTestCase to get functional testing support:: @@ -35,25 +54,15 @@ implements(interfaces.IFunctional) +@savestate def publish(self, path, basic=None, env=None, extra=None, request_method='GET', stdin=None, handle_errors=True): '''Publishes the object at 'path' returning a response object.''' -from zope.app.component.hooks import setSite, getSite from StringIO import StringIO from ZPublisher.Response import Response from ZPublisher.Test import publish_module -from AccessControl.SecurityManagement import getSecurityManager -from AccessControl.SecurityManagement import setSecurityManager - -# Save current security manager -sm = getSecurityManager() - -# And we need to store the old site -old_site = getSite() -setSite(None) - # Commit the sandbox for good measure transaction.commit() @@ -93,12 +102,6 @@ debug=not handle_errors, ) -# Restore security manager -setSecurityManager(sm) - -# And we need to restore the site again -setSite(old_site) - return ResponseWrapper(response, outstream, path) Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/zopedoctest/functional.py === --- Zope/trunk/lib/python/Testing/ZopeTestCase/zopedoctest/functional.py 2007-03-15 09:58:25 UTC (rev 73184) +++ Zope/trunk/lib/python/Testing/ZopeTestCase/zopedoctest/functional.py 2007-03-15 10:04:04 UTC (rev 73185) @@ -31,6 +31,7 @@ from Testing.ZopeTestCase import standard_permissions from Testing.ZopeTestCase.sandbox import AppZapper from Testing.ZopeTestCase.functional import ResponseWrapper +from Testing.ZopeTestCase.functional import savestate class HTTPHeaderOutput: @@ -110,6 +111,7 @@ getRootFolder()._p_jar.sync() [EMAIL PROTECTED] def http(request_string, handle_errors=True): """Execute an HTTP request string via the publisher @@ -117,20 +119,10 @@ """ import urllib import rfc822 -from zope.app.component.hooks import setSite, getSite from cStringIO import StringIO from ZPublisher.Response import Response from ZPublisher.Test import publish_module -from AccessControl.SecurityManagement import getSecurityManager -from AccessControl.SecurityManagement import setSecurityManager -# Save current Security Manager -old_sm = getSecurityManager() - -# And we need to store the old site -old_site = getSite() -setSite(None) - # Commit work done by previous python code. transaction.commit() @@ -194,14 +186,6 @@ header_output.appendResponseHeaders(response._cookie_list()) header_output.appendResponseHeaders(response.accumulated_headers.splitlines()) -# Restore previous security manager, which may have been changed -# by calling the publish method above -setSecurityManager(old_sm) - -# And we need to restore the site again -setSite(old_site) -# Sync connection - sync() return DocResponseWrapper(response, outstream, path, header_output) ___ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins
[Zope-Checkins] SVN: Zope/trunk/lib/python/Testing/ZopeTestCase/ Removed broken profiler support.
Log message for revision 73189: Removed broken profiler support. Changed: U Zope/trunk/lib/python/Testing/ZopeTestCase/__init__.py U Zope/trunk/lib/python/Testing/ZopeTestCase/base.py U Zope/trunk/lib/python/Testing/ZopeTestCase/doc/API.stx U Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt D Zope/trunk/lib/python/Testing/ZopeTestCase/doc/PROFILER.stx U Zope/trunk/lib/python/Testing/ZopeTestCase/interfaces.py D Zope/trunk/lib/python/Testing/ZopeTestCase/profiler.py U Zope/trunk/lib/python/Testing/ZopeTestCase/testInterfaces.py U Zope/trunk/lib/python/Testing/ZopeTestCase/ztc_common.py -=- Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/__init__.py === --- Zope/trunk/lib/python/Testing/ZopeTestCase/__init__.py 2007-03-15 13:05:38 UTC (rev 73188) +++ Zope/trunk/lib/python/Testing/ZopeTestCase/__init__.py 2007-03-15 13:18:45 UTC (rev 73189) @@ -33,7 +33,6 @@ from PortalTestCase import portal_name from PortalTestCase import PortalTestCase -from profiler import Profiled from sandbox import Sandboxed from functional import Functional Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/base.py === --- Zope/trunk/lib/python/Testing/ZopeTestCase/base.py 2007-03-15 13:05:38 UTC (rev 73188) +++ Zope/trunk/lib/python/Testing/ZopeTestCase/base.py 2007-03-15 13:18:45 UTC (rev 73189) @@ -18,7 +18,6 @@ import ZopeLite as Zope2 import unittest import transaction -import profiler import utils import interfaces import connections @@ -41,7 +40,7 @@ -class TestCase(profiler.Profiled, unittest.TestCase, object): +class TestCase(unittest.TestCase, object): '''Base test case for Zope testing ''' Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/doc/API.stx === --- Zope/trunk/lib/python/Testing/ZopeTestCase/doc/API.stx 2007-03-15 13:05:38 UTC (rev 73188) +++ Zope/trunk/lib/python/Testing/ZopeTestCase/doc/API.stx 2007-03-15 13:18:45 UTC (rev 73189) @@ -57,8 +57,6 @@ PortalTestCase -Profiled - Sandboxed Functional @@ -243,38 +241,6 @@ -Module profiler - -Profiling support - -Functions - -runcall(func, *args, **kw) - -print_stats() - -dump_stats(filename) - -Classes - -Profiled - - - -Class Profiled - -Profiling support mix-in for xTestCases - -Interfaces - -implements(IProfiled) - -Methods - -runcall(func, *args, **kw) - - - Module sandbox ZODB sandbox support Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt === --- Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt 2007-03-15 13:05:38 UTC (rev 73188) +++ Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt 2007-03-15 13:18:45 UTC (rev 73189) @@ -1,5 +1,6 @@ 0.9.10 (Zope 2.11 edition) - Switched to Zope3 interfaces. +- Removed broken profiler support. 0.9.9 (Zope 2.11 edition) - transaction.commit(1) is deprecated in favor of transaction.savepoint(1). Deleted: Zope/trunk/lib/python/Testing/ZopeTestCase/doc/PROFILER.stx === --- Zope/trunk/lib/python/Testing/ZopeTestCase/doc/PROFILER.stx 2007-03-15 13:05:38 UTC (rev 73188) +++ Zope/trunk/lib/python/Testing/ZopeTestCase/doc/PROFILER.stx 2007-03-15 13:18:45 UTC (rev 73189) @@ -1,19 +0,0 @@ - - -Profiler Readme - -Since version 0.9.0 all xTestCases are profiler aware by default. - -You can run your tests under profiler control like this:: - -python testSomething.py profile - -If you want to profile fixture creation or destruction type one of:: - -python testSomething.py profile-setup -python testSomething.py profile-teardown - -Profiler statistics will be printed after the test results. - -See the API reference for more on the 'profiler' module. - Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/interfaces.py === --- Zope/trunk/lib/python/Testing/ZopeTestCase/interfaces.py2007-03-15 13:05:38 UTC (rev 73188) +++ Zope/trunk/lib/python/Testing/ZopeTestCase/interfaces.py2007-03-15 13:18:45 UTC (rev 73189) @@ -95,14 +95,6 @@ '''This is currently the same as IZopeSecurity''' -class IProfiled(Interface): - -def runcall(func, *args, **kw): -'''Allows to run a function under profiler control - adding to the accumulated profiler statistics. -''' - - class IFunctional(Interface): def publish(path, basic=None, env=None, extra=None, request_method='GET', stdin=None): Deleted: Zope/trunk/lib/python/Testing/ZopeTestCase/profiler.py ===
[Zope-Checkins] SVN: Zope/trunk/lib/python/Testing/ZopeTestCase/ Protect against setNumberOfThreads disappearing after first use...
Log message for revision 73190: Protect against setNumberOfThreads disappearing after first use... Changed: U Zope/trunk/lib/python/Testing/ZopeTestCase/threadutils.py U Zope/trunk/lib/python/Testing/ZopeTestCase/utils.py -=- Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/threadutils.py === --- Zope/trunk/lib/python/Testing/ZopeTestCase/threadutils.py 2007-03-15 13:18:45 UTC (rev 73189) +++ Zope/trunk/lib/python/Testing/ZopeTestCase/threadutils.py 2007-03-15 13:29:18 UTC (rev 73190) @@ -13,7 +13,7 @@ """Parts of ZServer support are in this module so they can be imported more selectively. -$Id: threadutils.py,v 1.6 2004/08/19 15:31:26 shh42 Exp $ +$Id$ """ from threading import Thread @@ -22,6 +22,15 @@ dummyLOG = StringIO() +def setNumberOfThreads(number_of_threads): +'''Sets number of ZServer threads.''' +try: +from ZServer.PubCore import setNumberOfThreads +setNumberOfThreads(number_of_threads) +except ImportError: +pass + + def zserverRunner(host, port, log=None): '''Runs an HTTP ZServer on host:port.''' from ZServer import logger, asyncore Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/utils.py === --- Zope/trunk/lib/python/Testing/ZopeTestCase/utils.py 2007-03-15 13:18:45 UTC (rev 73189) +++ Zope/trunk/lib/python/Testing/ZopeTestCase/utils.py 2007-03-15 13:29:18 UTC (rev 73190) @@ -115,7 +115,7 @@ if _Z2HOST is None: _Z2HOST = '127.0.0.1' _Z2PORT = random.choice(range(55000, 55500)) -from ZServer import setNumberOfThreads +from threadutils import setNumberOfThreads setNumberOfThreads(number_of_threads) from threadutils import QuietThread, zserverRunner t = QuietThread(target=zserverRunner, args=(_Z2HOST, _Z2PORT, log)) ___ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins
[Zope-Checkins] SVN: Zope/trunk/lib/python/Testing/ZopeTestCase/doc/ClassDiagram.pdf Updated class diagram.
Log message for revision 73191: Updated class diagram. Changed: U Zope/trunk/lib/python/Testing/ZopeTestCase/doc/ClassDiagram.pdf -=- Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/doc/ClassDiagram.pdf === (Binary files differ) ___ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins
[Zope-Checkins] SVN: Zope/branches/2.10/lib/python/Testing/ZopeTestCase/ Merged r73189:73190 from the trunk.
Log message for revision 73192: Merged r73189:73190 from the trunk. Protect against setNumberOfThreads disappearing after first use. Changed: U Zope/branches/2.10/lib/python/Testing/ZopeTestCase/threadutils.py U Zope/branches/2.10/lib/python/Testing/ZopeTestCase/utils.py -=- Modified: Zope/branches/2.10/lib/python/Testing/ZopeTestCase/threadutils.py === --- Zope/branches/2.10/lib/python/Testing/ZopeTestCase/threadutils.py 2007-03-15 13:44:26 UTC (rev 73191) +++ Zope/branches/2.10/lib/python/Testing/ZopeTestCase/threadutils.py 2007-03-15 14:20:14 UTC (rev 73192) @@ -13,7 +13,7 @@ """Parts of ZServer support are in this module so they can be imported more selectively. -$Id: threadutils.py,v 1.6 2004/08/19 15:31:26 shh42 Exp $ +$Id$ """ from threading import Thread @@ -22,6 +22,15 @@ dummyLOG = StringIO() +def setNumberOfThreads(number_of_threads): +'''Sets number of ZServer threads.''' +try: +from ZServer.PubCore import setNumberOfThreads +setNumberOfThreads(number_of_threads) +except ImportError: +pass + + def zserverRunner(host, port, log=None): '''Runs an HTTP ZServer on host:port.''' from ZServer import logger, asyncore Modified: Zope/branches/2.10/lib/python/Testing/ZopeTestCase/utils.py === --- Zope/branches/2.10/lib/python/Testing/ZopeTestCase/utils.py 2007-03-15 13:44:26 UTC (rev 73191) +++ Zope/branches/2.10/lib/python/Testing/ZopeTestCase/utils.py 2007-03-15 14:20:14 UTC (rev 73192) @@ -115,7 +115,7 @@ if _Z2HOST is None: _Z2HOST = '127.0.0.1' _Z2PORT = random.choice(range(55000, 55500)) -from ZServer import setNumberOfThreads +from threadutils import setNumberOfThreads setNumberOfThreads(number_of_threads) from threadutils import QuietThread, zserverRunner t = QuietThread(target=zserverRunner, args=(_Z2HOST, _Z2PORT, log)) ___ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins