Index: /main/waeup.sirp/trunk/src/waeup/sirp/testing.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/testing.py	(revision 5779)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/testing.py	(revision 5780)
@@ -1,5 +1,10 @@
+"""Testing support for :mod:`waeup.sirp`.
+"""
 import os.path
+import grok
+import zope.component
 import waeup.sirp
 from zope.app.testing.functional import ZCMLLayer
+from zope.component import getGlobalSiteManager
 
 ftesting_zcml = os.path.join(
@@ -19,2 +24,90 @@
     def tearDown(self):
         pass
+
+
+def setUpZope(test=None):
+    """Initialize a Zope-compatible environment.
+
+    Currently, we only initialize the event machinery.
+    """
+    zope.component.eventtesting.setUp(test)
+
+def cleanUpZope(test=None):
+    """Clean up Zope-related registrations.
+
+    Cleans up all registrations and the like.
+    """
+    cleanUp()
+
+def maybe_grok():
+    """Try to grok the :mod:`waeup.sirp` package.
+
+    For many tests, even simple ones, we want the components defined
+    somewhere in the :mod:`waeup.sirp` package being registered. While
+    grokking the complete package can become expensive when done many
+    times, we only want to grok if it did not happen
+    before. Furthermore regrokking the whole package makes no sense if
+    done already.
+
+    :func:`maybe_grok` checks whether any eventhandlers are already
+    registered and does nothing in that case.
+
+    The grokking of :mod:`waeup.sirp` is done with warnings disabled.
+
+    Returns ``True`` if grokking was done, ``False`` else.
+
+    Sample
+    ******
+    
+    Together with the :func:`setUpZope` and :func:`cleanUpZope`
+    functions we then can do unittests with all components registered
+    like this::
+
+      import unittest2 as unittest # Want Python 2.7 features
+      from waeup.sirp.testing import (
+        maybe_grok, setUpZope, cleanUpZope,
+        )
+      from waeup.sirp.app import University
+
+      class MyTestCase(unittest.TestCase):
+
+          @classmethod
+          def setUpClass(cls):
+              grokked = maybe_grok()
+              if grokked:
+                  setUpZope(None)
+              return
+
+          @classmethod
+          def tearDownClass(cls):
+              cleanUpZope(None)
+
+          def setUp(self):
+              pass
+        
+          def tearDown(self):
+              pass
+
+          def test_jambdata_in_site(self):
+              u = University()
+              self.assertTrue('jambdata' in u.keys())
+              return
+
+    Here the component registration is done only once for the whole
+    :class:`unittest.TestCase` and no ZODB is needed. That means
+    inside the tests you can expect to have all :mod:`waeup.sirp`
+    components (utilities, adapter, events) registered but as objects
+    have here still have no place inside a ZODB things like 'browsing'
+    won't work out of the box. The benefit is the faster test
+    setup/teardown.
+    """
+    gsm =  getGlobalSiteManager()
+    # If there are any event handlers registered already, we assume
+    # that waeup.sirp was grokked already. There might be a batter
+    # check, though.
+    if len(list(gsm.registeredHandlers())) > 0:
+        return False
+    warnings.simplefilter('ignore') # disable (erraneous) warnings
+    grok.testing.grok('waeup.sirp')
+    warnings.simplefilter('default') # reenable warnings
+    return True
