[Zope3-checkins] CVS: Zope3/src/zope/app/observable/tests -
__init__.py:1.1.2.1 test_adapter.py:1.1.2.1
Nathan Yergler
nathan at yergler.net
Tue Mar 23 15:48:19 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/observable/tests
In directory cvs.zope.org:/tmp/cvs-serv4467/src/zope/app/observable/tests
Added Files:
Tag: observable-branch
__init__.py test_adapter.py
Log Message:
Implemented tests for Observable adapter.
=== Added File Zope3/src/zope/app/observable/tests/__init__.py ===
# this is a package.
=== Added File Zope3/src/zope/app/observable/tests/test_adapter.py ===
##############################################################################
#
# Copyright (c) 2004 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.
#
##############################################################################
"""Tests for the Observable Adapter.
$Id: test_adapter.py,v 1.1.2.1 2004/03/23 20:48:18 nathan Exp $
"""
import doctest
import unittest
from zope.interface import implements
from zope.app.observable.observable import ObservableAdapter, key
from zope.app.observable.interfaces import IObservable
from zope.app.event.interfaces import ISubscriber
from zope.app.annotation.interfaces import IAnnotations
from zope.app.container.interfaces import IObjectAddedEvent
class DummyAnnotationsClass(dict):
implements(IAnnotations)
class DummySubscriber:
implements(ISubscriber)
def __init__(self):
self.events = []
def notify(self, event):
self.events.append(event)
class DummyEvent:
implements(IObjectAddedEvent)
def test_subscribe():
"""
First create an annotatable object and an adapter
>>> obj = DummyAnnotationsClass()
>>> adapter = ObservableAdapter(obj)
Make a subscriber and make a faux subscription
>>> subscriber = DummySubscriber(None)
>>> adapter.subscribe([], IAnnotations, subscriber)
Make sure an ObjectAdapterRegistry was created
>>> obj[key] is not None
True
"""
def test_notify():
"""
First create an annotatable object and an adapter
>>> obj = DummyAnnotationsClass()
>>> adapter = ObservableAdapter(obj)
Make a subscriber and make a faux subscription
>>> subscriber = DummySubscriber()
>>> adapter.subscribe([IObjectAddedEvent], ISubscriber, subscriber)
Make sure an ObjectAdapterRegistry was created
>>> obj[key] is not None
True
Call notify
>>> event = DummyEvent()
>>> adapter.notify(event, ISubscriber)
>>> subscriber.events
>>> subscriber.events == [event]
True
"""
def test_suite():
import sys
return unittest.TestSuite((
doctest.DocTestSuite(sys.modules[__name__]),
))
if __name__ == '__main__':
test_suite()
More information about the Zope3-Checkins
mailing list