[Checkins] SVN: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/ fixing up issues when all test run

david whitfield Morriss whit at longnow.org
Thu Aug 24 00:31:52 EDT 2006


Log message for revision 69756:
  fixing up issues when all test run
  
  - new layer for testing webserver
  
  todo: fix sessions in sanboxs
        rename Zope2Layer
  

Changed:
  U   Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/layer.py
  U   Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/sandbox.py
  U   Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/testShoppingCart.py
  U   Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/testWebserver.py
  U   Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/testZODBCompat.py
  U   Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/utils.py

-=-
Modified: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/layer.py
===================================================================
--- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/layer.py	2006-08-24 04:19:45 UTC (rev 69755)
+++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/layer.py	2006-08-24 04:31:52 UTC (rev 69756)
@@ -43,6 +43,8 @@
          for name, quiet in _products]
 
         [func(*args, **kw) for func, args, kw in _z2_callables]
+        import transaction as txn
+        txn.commit()
 
     @classmethod
     def tearDown(cls):

Modified: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/sandbox.py
===================================================================
--- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/sandbox.py	2006-08-24 04:19:45 UTC (rev 69755)
+++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/sandbox.py	2006-08-24 04:31:52 UTC (rev 69756)
@@ -19,6 +19,7 @@
 import utils
 import connections
 
+
 class Sandboxed:
     '''Derive from this class and an xTestCase to make each test
        run in its own ZODB sandbox::

Modified: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/testShoppingCart.py
===================================================================
--- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/testShoppingCart.py	2006-08-24 04:19:45 UTC (rev 69755)
+++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/testShoppingCart.py	2006-08-24 04:31:52 UTC (rev 69756)
@@ -34,20 +34,22 @@
 examples_path = os.path.join(SOFTWARE_HOME, '..', '..', 'skel', 'import', 'Examples.zexp')
 examples_path = os.path.abspath(examples_path)
 
-
-# Open ZODB connection
-app = ZopeTestCase.app()
-
 # Set up sessioning objects
-ZopeTestCase.utils.setupCoreSessions(app)
+ZopeTestCase.utils.setupCoreSessions()
 
-# Set up example applications
-if not hasattr(app, 'Examples'):
-    ZopeTestCase.utils.importObjectFromFile(app, examples_path)
+from layer import Zope2Layer
 
-# Close ZODB connection
-ZopeTestCase.close(app)
+class ShoppingCartLayer(Zope2Layer):
+    @classmethod
+    def setUp(cls):
+        app = ZopeTestCase.app()
+        if not hasattr(app, 'Examples'):
+            ZopeTestCase.utils.importObjectFromFile(app, examples_path)
+        ZopeTestCase.close(app)
 
+    @classmethod
+    def tearDown(cls):
+        raise NotImplementedError
 
 class DummyOrder:
     '''Construct an order we can add to the cart'''
@@ -61,6 +63,8 @@
 class TestShoppingCart(ZopeTestCase.ZopeTestCase):
     '''Test the ShoppingCart example application'''
 
+    layer = ShoppingCartLayer
+
     _setup_fixture = 0  # No default fixture
 
     def afterSetUp(self):
@@ -116,11 +120,10 @@
         # Additional test to trigger connection pool depletion bug
         pass
 
-
 class TestSandboxedShoppingCart(ZopeTestCase.Sandboxed, TestShoppingCart):
     '''Demonstrate that sessions work in sandboxes''' 
+    
 
-
 def test_suite():
     from unittest import TestSuite, makeSuite
     suite = TestSuite()

Modified: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/testWebserver.py
===================================================================
--- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/testWebserver.py	2006-08-24 04:19:45 UTC (rev 69755)
+++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/testWebserver.py	2006-08-24 04:31:52 UTC (rev 69756)
@@ -39,15 +39,14 @@
 from Testing import ZopeTestCase
 
 from Testing.ZopeTestCase import transaction
+from Testing.ZopeTestCase.layer import Zope2Layer
+
 from AccessControl import Unauthorized
 import urllib
 
 # Create the error_log object
 ZopeTestCase.utils.setupSiteErrorLog()
 
-
-
-
 class ManagementOpener(urllib.FancyURLopener):
     '''Logs on as manager when prompted'''
     def prompt_user_passwd(self, host, realm):
@@ -58,8 +57,6 @@
     def prompt_user_passwd(self, host, realm):
         raise Unauthorized, 'The URLopener was asked for authentication'
 
-from layer import Zope2Layer
-
 folder_url, host, port = None, None, None
 
 class WebserverLayer(Zope2Layer):

Modified: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/testZODBCompat.py
===================================================================
--- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/testZODBCompat.py	2006-08-24 04:19:45 UTC (rev 69755)
+++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/testZODBCompat.py	2006-08-24 04:31:52 UTC (rev 69756)
@@ -168,13 +168,22 @@
     _v_foo = None
     _p_foo = None
 
-app = ZopeTestCase.app()
-app._setObject('dummy1', DummyObject())
-app._setObject('dummy2', DummyObject())
-transaction.commit()
-ZopeTestCase.close(app)
+from layer import Zope2Layer
 
+class ZODBCompatLayer(Zope2Layer):
+    @classmethod
+    def setUp(cls):
+        app = ZopeTestCase.app()
+        app._setObject('dummy1', DummyObject())
+        app._setObject('dummy2', DummyObject())
+        transaction.commit()
+        ZopeTestCase.close(app)
 
+    @classmethod
+    def tearDown(cls):
+        raise NotImplementedError
+
+
 class TestAttributesOfCleanObjects(ZopeTestCase.ZopeTestCase):
     '''This testcase shows that _v_ and _p_ attributes are NOT bothered
        by transaction boundaries, if the respective object is otherwise
@@ -195,6 +204,8 @@
        This testcase exploits the fact that test methods are sorted by name.
     '''
     
+    layer = ZODBCompatLayer
+    
     def afterSetUp(self):
         self.dummy = self.app.dummy1 # See above
 
@@ -256,6 +267,8 @@
        This testcase exploits the fact that test methods are sorted by name.
     '''
 
+    layer = ZODBCompatLayer
+    
     def afterSetUp(self):
         self.dummy = self.app.dummy2 # See above
         self.dummy.touchme = 1 # Tag, you're dirty
@@ -305,6 +318,8 @@
 
 class TestTransactionAbort(ZopeTestCase.ZopeTestCase):
 
+    layer = ZODBCompatLayer
+    
     def testTransactionAbort(self):
         self.folder.foo = 1
         self.failUnless(hasattr(self.folder, 'foo'))

Modified: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/utils.py
===================================================================
--- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/utils.py	2006-08-24 04:19:45 UTC (rev 69755)
+++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/utils.py	2006-08-24 04:31:52 UTC (rev 69756)
@@ -1,4 +1,4 @@
-##############################################################################
+#############################################################################
 #
 # Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
 #
@@ -34,7 +34,6 @@
     finally:
         transaction.abort()
         close(app)
-        
 
 def deferToZ2Layer(function):
     '''
@@ -52,12 +51,11 @@
             return function(*args, **kwargs)
         else:
             import layer
-            def curryAppCall(*args, **kwargs):
+            def caller(*args, **kwargs):
                 return appcall(function, *args, **kwargs)
-            return layer._z2_callables.append((curryAppCall, args, kwargs))
+            return layer._z2_callables.append((caller, args, kwargs))
     return wrapped
 
-
 @deferToZ2Layer
 def setupCoreSessions(app=None):
     '''Sets up the session_data_manager e.a.'''
@@ -121,10 +119,9 @@
             app._setObject('error_log', SiteErrorLog())
             transaction.commit()
 
-
 def importObjectFromFile(container, filename, quiet=0):
     '''Imports an object from a (.zexp) file into the given container.'''
-    from ZopeLite import _print, _patched
+    from ZopeLite import _patched
     quiet = quiet or not _patched
     start = time.time()
     if not quiet: _print("Importing %s ... " % os.path.basename(filename))
@@ -132,7 +129,6 @@
     transaction.commit()
     if not quiet: _print('done (%.3fs)\n' % (time.time() - start))
 
-
 _Z2HOST = None
 _Z2PORT = None
 



More information about the Checkins mailing list