[Zope3-checkins] CVS: Zope3/src/zope/app/observable - tests.py:1.1.2.1

Nathan Yergler nathan at yergler.net
Tue Mar 23 16:23:53 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/observable
In directory cvs.zope.org:/tmp/cvs-serv12645

Added Files:
      Tag: observable-branch
	tests.py 
Log Message:
Moved tests from tests package into tests.py.


=== Added File Zope3/src/zope/app/observable/tests.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: tests.py,v 1.1.2.1 2004/03/23 21:23:52 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()
    >>> adapter.subscribe([IObjectAddedEvent], ISubscriber, 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 == [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