[Zope3-checkins] CVS: Zope3/lib/python/Zope/Event/tests - PlacelessSetup.py:1.2

Jim Fulton jim@zope.com
Fri, 4 Oct 2002 16:07:10 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Event/tests
In directory cvs.zope.org:/tmp/cvs-serv8384/lib/python/Zope/Event/tests

Added Files:
	PlacelessSetup.py 
Log Message:
Many components now need to generate events. This means that an event
service needs to be in place when testing. For this reason, I've
refactored PlacelessSetup to include events.

- I added a PlacelessSetup in Zope.Event.tests.

  This module also registers a subscriber that collects all events in
  a list and a function for getting all of the events that match an
  optional event type or filter. This is useful so that component
  tests can include tests to make sure that the proper events are
  being fired.

- I added a PlacelessSetup in Zope.App.tests that combines the
  PlacelessSetup from Zope.App.ComponentArchitecture and Zope.Event.

- I changed all the modules that imported
  Zope.ComponentArchitecture.tests.PlacelessSetup to import
  Zope.App.tests.PlacelessSetup.



=== Zope3/lib/python/Zope/Event/tests/PlacelessSetup.py 1.1 => 1.2 ===
--- /dev/null	Fri Oct  4 16:07:10 2002
+++ Zope3/lib/python/Zope/Event/tests/PlacelessSetup.py	Fri Oct  4 16:07:09 2002
@@ -0,0 +1,57 @@
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+# 
+##############################################################################
+"""Unit test logic for setting up and tearing down basic infrastructure
+
+
+$Id$
+"""
+
+from Zope.ComponentArchitecture import getServiceManager
+from Zope.Event.IEventService import IEventService
+from Zope.Event.GlobalEventService import eventService
+from Interface import Interface
+
+events = []
+
+class EventRecorderClass:
+    notify = events.append
+
+EventRecorder = EventRecorderClass()
+
+def getEvents(event_type = None, filter = None):
+    r = []
+    for event in events:
+        if event_type is not None and not event_type.isImplementedBy(event):
+            continue
+        if filter is not None and not filter(event):
+            continue
+        r.append(event)
+
+    return r
+            
+    
+
+class PlacelessSetup:
+
+    def setUp(self):
+
+        sm=getServiceManager(None)
+        defineService=sm.defineService
+        provideService=sm.provideService
+
+        defineService("Events", IEventService)
+        provideService("Events", eventService)
+        
+        del events[:]
+        eventService.subscribe(EventRecorder)