Log message for revision 69708:
  fixing missing part of patch
  

Changed:
  U   Zope/branches/2.9-layer-support/lib/python/Testing/ZopeTestCase/utils.py

-=-
Modified: 
Zope/branches/2.9-layer-support/lib/python/Testing/ZopeTestCase/utils.py
===================================================================
--- Zope/branches/2.9-layer-support/lib/python/Testing/ZopeTestCase/utils.py    
2006-08-20 20:13:01 UTC (rev 69707)
+++ Zope/branches/2.9-layer-support/lib/python/Testing/ZopeTestCase/utils.py    
2006-08-20 20:20:04 UTC (rev 69708)
@@ -24,15 +24,46 @@
 import random
 import transaction
 
+def appcall(function, *args, **kw):
+    '''Calls a function passing 'app' as first argument.'''
+    from base import app, close
+    app = app()
+    args = (app,) + args
+    try:
+        return function(*args, **kw)
+    finally:
+        transaction.abort()
+        close(app)
+        
 
+def deferToZ2Layer(function):
+    '''
+    decorator assumes following:
+
+    * function only takes one argument: app
+    
+    * if app is not passed in, function should be deferred 
+
+    deferral queues execution of the function to the setup call of
+    Testing.ZopeTestCase.layer.Zope2Layer
+    '''
+    def wrapped(*args, **kwargs):
+        if args or kwargs.get('app', None):
+            return function(*args, **kwargs)
+        else:
+            import layer
+            def curryAppCall(*args, **kwargs):
+                return appcall(function, *args, **kwargs)
+            return layer._z2_callables.append((curryAppCall, args, kwargs))
+    return wrapped
+
+
[EMAIL PROTECTED]
 def setupCoreSessions(app=None):
     '''Sets up the session_data_manager e.a.'''
     from Acquisition import aq_base
     commit = 0
 
-    if app is None: 
-        return appcall(setupCoreSessions)
-
     if not hasattr(app, 'temp_folder'):
         from Products.TemporaryFolder.TemporaryFolder import 
MountedTemporaryFolder
         tf = MountedTemporaryFolder('temp_folder', 'Temporary Folder')
@@ -67,11 +98,9 @@
     if commit:
         transaction.commit()
 
-
[EMAIL PROTECTED]
 def setupZGlobals(app=None):
     '''Sets up the ZGlobals BTree required by ZClasses.'''
-    if app is None: 
-        return appcall(setupZGlobals)
 
     root = app._p_jar.root()
     if not root.has_key('ZGlobals'):
@@ -79,11 +108,9 @@
         root['ZGlobals'] = OOBTree()
         transaction.commit()
 
-
[EMAIL PROTECTED]
 def setupSiteErrorLog(app=None):
     '''Sets up the error_log object required by ZPublisher.'''
-    if app is None: 
-        return appcall(setupSiteErrorLog)
 
     if not hasattr(app, 'error_log'):
         try:
@@ -147,18 +174,6 @@
     return app.__of__(RequestContainer(REQUEST=request))
 
 
-def appcall(function, *args, **kw):
-    '''Calls a function passing 'app' as first argument.'''
-    from base import app, close
-    app = app()
-    args = (app,) + args
-    try:
-        return function(*args, **kw)
-    finally:
-        transaction.abort()
-        close(app)
-
-
 def makelist(arg):
     '''Turns arg into a list. Where arg may be
        list, tuple, or string.
@@ -171,7 +186,33 @@
        return filter(None, [arg])
     raise ValueError('Argument must be list, tuple, or string')
 
+def hasProduct(name):
+    '''Checks if a product can be found along Products.__path__'''
+    from OFS.Application import get_products
+    return name in [n[1] for n in get_products()]
 
+def _print(msg):
+    '''Writes 'msg' to stderr and flushes the stream.'''
+    sys.stderr.write(msg)
+    sys.stderr.flush()
+
+def setDebugMode(mode):
+    '''
+    Allows manual setting of Five's inspection of debug mode to allow for
+    zcml to fail meaningfully
+    '''
+    import Products.Five.fiveconfigure as fc
+    fc.debug_mode=mode
+
+def setAllLayers(suite, newlayer):
+    '''
+    helper function that iterates through all the subsuites in a
+    suite, resetting their layer to @param layer: the desired layer
+    class
+    '''
+    [setattr(subsuite, 'layer', newlayer) for subsuite in suite]
+    return suite
+
 __all__ = [
     'setupCoreSessions',
     'setupSiteErrorLog',
@@ -181,5 +222,9 @@
     'appcall',
     'makerequest',
     'makelist',
+    'hasProduct',
+    'setDebugMode',
+    '_print',
+    'setAllLayers'
 ]
 

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to