[Zope3-checkins] CVS: Zope3/src/zope/event/tests - __init__.py:1.2 subscriber.py:1.2 test_eventchannel.py:1.2
Jim Fulton
jim@zope.com
Wed, 25 Dec 2002 09:14:09 -0500
Update of /cvs-repository/Zope3/src/zope/event/tests
In directory cvs.zope.org:/tmp/cvs-serv15352/src/zope/event/tests
Added Files:
__init__.py subscriber.py test_eventchannel.py
Log Message:
Grand renaming:
- Renamed most files (especially python modules) to lower case.
- Moved views and interfaces into separate hierarchies within each
project, where each top-level directory under the zope package
is a separate project.
- Moved everything to src from lib/python.
lib/python will eventually go away. I need access to the cvs
repository to make this happen, however.
There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.
=== Zope3/src/zope/event/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:14:08 2002
+++ Zope3/src/zope/event/tests/__init__.py Wed Dec 25 09:13:38 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.
=== Zope3/src/zope/event/tests/subscriber.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:14:08 2002
+++ Zope3/src/zope/event/tests/subscriber.py Wed Dec 25 09:13:38 2002
@@ -0,0 +1,41 @@
+##############################################################################
+#
+# Copyright (c) 2001, 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.
+#
+##############################################################################
+"""
+This contains some dummy stuff to do with subscribing to event channels
+that's useful in several test modules.
+
+Revision information:
+$Id$
+"""
+
+
+class DummySubscriber:
+
+ def __init__(self):
+ self.notified = 0
+
+ def notify(self, event):
+ self.notified += 1
+
+subscriber = DummySubscriber()
+
+class DummyFilter:
+
+ def __init__(self,value=1):
+ self.value = value
+
+ def __call__(self, event):
+ return self.value
+
+filter = DummyFilter
=== Zope3/src/zope/event/tests/test_eventchannel.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:14:08 2002
+++ Zope3/src/zope/event/tests/test_eventchannel.py Wed Dec 25 09:13:38 2002
@@ -0,0 +1,98 @@
+##############################################################################
+#
+# Copyright (c) 2001, 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.
+#
+##############################################################################
+"""A functional EventChanel test.
+
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.interfaces.event import IEvent
+
+class ISomeEvent(IEvent):
+ pass
+
+class ISomeSubEvent(ISomeEvent):
+ pass
+
+class ISomeOtherEvent(IEvent):
+ pass
+
+class SomeEvent:
+ __implements__ = ISomeEvent
+
+class SomeSubEvent:
+ __implements__ = ISomeSubEvent
+
+class SomeOtherEvent:
+ __implements__ = ISomeOtherEvent
+
+class SubscriberStub:
+ received = None
+ def notify(self, event):
+ self.received = event
+
+class Test(TestCase):
+
+ def test_notify(self):
+ from zope.event.eventchannel import EventChannel
+
+ subscriber = SubscriberStub()
+ ec = EventChannel()
+ ec.subscribe(subscriber, ISomeEvent)
+
+ ev = SomeEvent()
+ ec.notify(ev)
+ self.assertEquals(subscriber.received, ev,
+ "Did not get event registered for")
+
+ ev = SomeSubEvent()
+ ec.notify(ev)
+ self.assertEquals(subscriber.received, ev, "Did not get subclassed event")
+
+ ev = SomeOtherEvent()
+ ec.notify(ev)
+ self.assertNotEquals(subscriber.received, ev, "Got unrelated event")
+
+ def test_notify_filter(self):
+ from zope.event.eventchannel import EventChannel
+
+ true = lambda x: True
+ false = lambda x: False
+
+ subscriber = SubscriberStub()
+ ec = EventChannel()
+ ec.subscribe(subscriber, ISomeEvent, true)
+
+ ev = SomeEvent()
+ ec.notify(ev)
+ self.assertEquals(subscriber.received, ev,
+ "Did not get event registered for")
+
+ subscriber = SubscriberStub()
+ ec = EventChannel()
+ ec.subscribe(subscriber, ISomeEvent, false)
+
+ ev = SomeEvent()
+ ec.notify(ev)
+ self.assertEquals(subscriber.received, None,
+ "Event was not filtered")
+
+
+def test_suite():
+ return TestSuite((
+ makeSuite(Test),
+ ))
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')