[Zope3-checkins] CVS: Zope3/src/zope/event/tests - __init__.py:1.1.2.1 subscriber.py:1.1.2.1 test_eventchannel.py:1.1.2.1
Jim Fulton
jim@zope.com
Mon, 23 Dec 2002 14:32:50 -0500
Update of /cvs-repository/Zope3/src/zope/event/tests
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/event/tests
Added Files:
Tag: NameGeddon-branch
__init__.py subscriber.py test_eventchannel.py
Log Message:
Initial renaming before debugging
=== Added File Zope3/src/zope/event/tests/__init__.py ===
#
# This file is necessary to make this directory a package.
=== Added File Zope3/src/zope/event/tests/subscriber.py ===
##############################################################################
#
# 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: subscriber.py,v 1.1.2.1 2002/12/23 19:32:48 jim Exp $
"""
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
=== Added File Zope3/src/zope/event/tests/test_eventchannel.py ===
##############################################################################
#
# 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: test_eventchannel.py,v 1.1.2.1 2002/12/23 19:32:48 jim Exp $
"""
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')