[Zope-Checkins] SVN: Zope/branches/five-integration/lib/python/Testing/ZopeTestCase/ ZopeLite now is careful not to apply monkey patches to an already running Zope.

Stefan H. Holek stefan at epy.co.at
Thu Mar 24 04:04:08 EST 2005


Log message for revision 29664:
  ZopeLite now is careful not to apply monkey patches to an already running Zope.
  

Changed:
  U   Zope/branches/five-integration/lib/python/Testing/ZopeTestCase/ZopeLite.py
  U   Zope/branches/five-integration/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt

-=-
Modified: Zope/branches/five-integration/lib/python/Testing/ZopeTestCase/ZopeLite.py
===================================================================
--- Zope/branches/five-integration/lib/python/Testing/ZopeTestCase/ZopeLite.py	2005-03-24 09:02:28 UTC (rev 29663)
+++ Zope/branches/five-integration/lib/python/Testing/ZopeTestCase/ZopeLite.py	2005-03-24 09:04:07 UTC (rev 29664)
@@ -45,19 +45,30 @@
 _write('Loading Zope, please stand by ')
 _start = time.time()
 
-# Configure logging
-if not sys.modules.has_key('logging'):
-    import logging
-    logging.basicConfig()
+def _configure_logging():
+    # Initialize the logging module
+    if not sys.modules.has_key('logging'):
+        import logging
+        logging.basicConfig()
 
-# Debug mode is dog slow ...
-import App.config
-config = App.config.getConfiguration()
-config.debug_mode = 0
-App.config.setConfiguration(config)
+def _configure_debug_mode():
+    # Switch off debug mode
+    import App.config
+    config = App.config.getConfiguration()
+    config.debug_mode = 0
+    App.config.setConfiguration(config)
 
-# Need to import Zope2 early on as the 
-# ZTUtils package relies on it
+def _configure_client_cache():
+    # Make sure we use a temporary client cache
+    import App.config
+    config = App.config.getConfiguration()
+    config.zeo_client_name = None
+    App.config.setConfiguration(config)
+
+_configure_logging()
+_configure_debug_mode()
+_configure_client_cache()
+
 _exec('import Zope2')
 import Zope2
 _exec('import ZODB')
@@ -75,26 +86,31 @@
 _exec('import OFS.Application')
 import OFS.Application
 import App.ProductContext
+_write('.')
 
-# Avoid expensive product import
-def _null_import_products(): pass
-OFS.Application.import_products = _null_import_products
+def _apply_patches():
+    # Avoid expensive product import
+    def null_import_products(): pass
+    OFS.Application.import_products = null_import_products
 
-# Avoid expensive product installation
-def _null_initialize(app): pass
-OFS.Application.initialize = _null_initialize
+    # Avoid expensive product installation
+    def null_initialize(app): pass
+    OFS.Application.initialize = null_initialize
 
-# Avoid expensive help registration
-def _null_register_topic(self,id,topic): pass
-App.ProductContext.ProductContext.registerHelpTopic = _null_register_topic
-def _null_register_title(self,title): pass
-App.ProductContext.ProductContext.registerHelpTitle = _null_register_title
-def _null_register_help(self,directory='',clear=1,title_re=None): pass
-App.ProductContext.ProductContext.registerHelp = _null_register_help
+    # Avoid expensive help registration
+    def null_register_topic(self,id,topic): pass
+    App.ProductContext.ProductContext.registerHelpTopic = null_register_topic
+    def null_register_title(self,title): pass
+    App.ProductContext.ProductContext.registerHelpTitle = null_register_title
+    def null_register_help(self,directory='',clear=1,title_re=None): pass
+    App.ProductContext.ProductContext.registerHelp = null_register_help
 
-# Make sure to use a temporary client cache
-if os.environ.get('ZEO_CLIENT'): del os.environ['ZEO_CLIENT']
+# Do not patch a running Zope
+if not Zope2._began_startup:
+    _apply_patches()
 
+# Allow test authors to install Zope products into the test environment. Note
+# that installProduct() must be called at module level - never from tests.
 from OFS.Application import get_folder_permissions, get_products, install_product
 from OFS.Folder import Folder
 import Products
@@ -103,13 +119,12 @@
 _installedProducts = {}
 
 def hasProduct(name):
-    '''Tests if a product can be found along Products.__path__'''
+    '''Checks if a product can be found along Products.__path__'''
     return name in [n[1] for n in get_products()]
 
 def installProduct(name, quiet=0):
     '''Installs a Zope product.'''
     start = time.time()
-    app = _theApp
     meta_types = []
     if not _installedProducts.has_key(name):
         for priority, product_name, index, product_dir in get_products():
@@ -117,7 +132,7 @@
                 if not quiet: _print('Installing %s ... ' % product_name)
                 # We want to fail immediately if a product throws an exception
                 # during install, so we set the raise_exc flag.
-                install_product(app, product_dir, product_name, meta_types,
+                install_product(_theApp, product_dir, product_name, meta_types,
                                 get_folder_permissions(), raise_exc=1)
                 _installedProducts[product_name] = 1
                 Products.meta_types = Products.meta_types + tuple(meta_types)
@@ -125,27 +140,31 @@
                 if not quiet: _print('done (%.3fs)\n' % (time.time() - start))
                 break
         else:
-            if name != 'SomeProduct':   # Ignore the skeleton tests :-P
+            if name != 'SomeProduct':   # Ignore skeleton tests :-P
                 if not quiet: _print('Installing %s ... NOT FOUND\n' % name)
 
-# Loading the Control_Panel of an existing ZODB may take 
-# a while; print another dot if it does.
-_s = time.time(); _max = (_s - _start) / 4
-_exec('_theApp.Control_Panel')
-_cp = _theApp.Control_Panel
-if hasattr(_cp, 'initialize_cache'):
-    _cp.initialize_cache()
-if (time.time() - _s) > _max: 
-    _write('.')
+def _load_control_panel():
+    # Loading the Control_Panel of an existing ZODB may take
+    # a while; print another dot if it does.
+    start = time.time()
+    max = (start - _start) / 4
+    _exec('_theApp.Control_Panel')
+    _theApp.Control_Panel
+    if (time.time() - start) > max:
+        _write('.')
 
-installProduct('PluginIndexes', 1)  # Must install first
-installProduct('OFSP', 1)
-#installProduct('ExternalMethod', 1)
-#installProduct('ZSQLMethods', 1)
-#installProduct('ZGadflyDA', 1)
-#installProduct('MIMETools', 1)
-#installProduct('MailHost', 1)
+def _install_products():
+    installProduct('PluginIndexes', 1)  # Must install first
+    installProduct('OFSP', 1)
+    #installProduct('ExternalMethod', 1)
+    #installProduct('ZSQLMethods', 1)
+    #installProduct('ZGadflyDA', 1)
+    #installProduct('MIMETools', 1)
+    #installProduct('MailHost', 1)
 
+_load_control_panel()
+_install_products()
+
 # So people can use ZopeLite.app()
 app = Zope2.app
 debug = Zope2.debug
@@ -153,9 +172,11 @@
 configure = Zope2.configure
 def startup(): pass
 
+# Provide a ZODB sandbox factory
 from ZODB.DemoStorage import DemoStorage
+
 def sandbox(base=None):
-    '''Returns what amounts to a sandbox copy of the base ZODB.'''
+    '''Returns a sandbox copy of the base ZODB.'''
     if base is None: base = Zope2.DB
     base_storage = base._storage
     quota = getattr(base_storage, '_quota', None)

Modified: Zope/branches/five-integration/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt
===================================================================
--- Zope/branches/five-integration/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt	2005-03-24 09:02:28 UTC (rev 29663)
+++ Zope/branches/five-integration/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt	2005-03-24 09:04:07 UTC (rev 29664)
@@ -6,6 +6,7 @@
 - Removed warnhook.py, we now use the one from ZODB.tests.
 - Removed doctest.py, we now use the one from zope.testing.
 - Removed dochttp.py + test, we now use the one from zope.app.tests.
+- ZopeLite now takes care not to monkey patch an already running Zope.
 
 0.9.6
 - Dropped support for Zope 2.5 as it lacks the setSecurityManager() API.



More information about the Zope-Checkins mailing list