[z3-checkins] r18281 - in z3/sqlos/trunk: testing transaction

jinty at codespeak.net jinty at codespeak.net
Sat Oct 8 03:06:50 CEST 2005


Author: jinty
Date: Sat Oct  8 03:06:47 2005
New Revision: 18281

Modified:
   z3/sqlos/trunk/testing/__init__.py
   z3/sqlos/trunk/testing/testdb.py
   z3/sqlos/trunk/transaction/__init__.py
Log:
Move more unit test set up into sqlos.testing making tests less verbose and even easier to write.

Modified: z3/sqlos/trunk/testing/__init__.py
==============================================================================
--- z3/sqlos/trunk/testing/__init__.py	(original)
+++ z3/sqlos/trunk/testing/__init__.py	Sat Oct  8 03:06:47 2005
@@ -9,3 +9,17 @@
 
 # Change this to change the database used in all unit testing
 from testdb import SQLiteTestDB as TestDB
+
+from zope.app.tests import ztapi
+from zope.app.event.interfaces import IObjectModifiedEvent
+from zope.app.event.interfaces import IObjectCreatedEvent
+from sqlos.event.interfaces import IObjectExpiredEvent
+from sqlos.event.subscriber import sqlobjectModifiedSubscriber
+from sqlos.event.subscriber import sqlobjectCreatedSubscriber
+from sqlos.event.subscriber import sqlobjectExpiredSubscriber
+
+def setUpSubscribers():
+    """Helper function to set up the sqlos event subscribers in unit tests."""
+    ztapi.handle([IObjectExpiredEvent], sqlobjectExpiredSubscriber)
+    ztapi.handle([IObjectCreatedEvent], sqlobjectCreatedSubscriber)
+    ztapi.handle([IObjectModifiedEvent], sqlobjectModifiedSubscriber)

Modified: z3/sqlos/trunk/testing/testdb.py
==============================================================================
--- z3/sqlos/trunk/testing/testdb.py	(original)
+++ z3/sqlos/trunk/testing/testdb.py	Sat Oct  8 03:06:47 2005
@@ -42,5 +42,8 @@
     def connectionAdapterFactory(self):
         return SQLiteAdapter(self.zda())
 
+    def getConnection(self):
+        return self.connectionAdapterFactory().transaction()
+
     def tearDown(self):
         pass

Modified: z3/sqlos/trunk/transaction/__init__.py
==============================================================================
--- z3/sqlos/trunk/transaction/__init__.py	(original)
+++ z3/sqlos/trunk/transaction/__init__.py	Sat Oct  8 03:06:47 2005
@@ -39,38 +39,18 @@
     >>> from zope.app.tests.placelesssetup import setUp, tearDown
     >>> setUp()
 
-    First, register the subscribers:
+    First, register the subscribers and make a test data base:
 
-    >>> from zope.app.tests import ztapi
-    >>> from zope.app.event.interfaces import IObjectModifiedEvent
-    >>> from zope.app.event.interfaces import IObjectCreatedEvent
-    >>> from sqlos.event.interfaces import IObjectExpiredEvent
-    >>> from sqlos.event.subscriber import sqlobjectModifiedSubscriber
-    >>> from sqlos.event.subscriber import sqlobjectCreatedSubscriber
-    >>> from sqlos.event.subscriber import sqlobjectExpiredSubscriber
+    >>> from sqlos import testing
+    >>> testing.setUpSubscribers()
+    >>> testdb = testing.TestDB()
 
-    >>> ztapi.handle([IObjectExpiredEvent], sqlobjectExpiredSubscriber)
-    >>> ztapi.handle([IObjectCreatedEvent], sqlobjectCreatedSubscriber)
-    >>> ztapi.handle([IObjectModifiedEvent], sqlobjectModifiedSubscriber)
-
-    Make a testing db:
-
-    >>> from sqlos.testing import TestDB
-    >>> testdb = TestDB()
-
-    Then, create a connection:
-
-    >>> adapter = testdb.connectionAdapterFactory()
-
-    Stuff the connection into the test class and initialize the table
+    Stuff a connection into the test class and initialize the table
     if it doesn't exists yet:
 
     >>> from sqlos.testing.sampleperson import SamplePerson
     >>> oldconn = SamplePerson._connection
-    >>> if adapter.supportTransactions == True:
-    ...     SamplePerson._connection = adapter.transaction()
-    ... else:
-    ...     SamplePerson._connection = adapter
+    >>> SamplePerson._connection = testdb.getConnection()
     >>> SamplePerson.createTable()
 
     Now create a SamplePerson for testing:


More information about the z3-checkins mailing list