[Zope3-checkins] CVS: Zope3/src/zope/app/annotation/tests - __init__.py:1.1 annotations.py:1.1 test_attributeannotations.py:1.1

Stephan Richter srichter at cosmos.phy.tufts.edu
Sat Mar 13 18:00:40 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/annotation/tests
In directory cvs.zope.org:/tmp/cvs-serv24548/src/zope/app/annotation/tests

Added Files:
	__init__.py annotations.py test_attributeannotations.py 
Log Message:


Created annotation package in zope.app.



Moved annotation interfaces to zope.app.annotation.interfaces.



Moved attributeannotations to zope.app.annotation.attribute.


=== Added File Zope3/src/zope/app/annotation/tests/__init__.py ===
# Import this.


=== Added File Zope3/src/zope/app/annotation/tests/annotations.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.
#
##############################################################################
"""General Annotations Tests

All objects implementing 'IAnnotations' should pass these tests. They might be
used as base tests for real implementations.

$Id: annotations.py,v 1.1 2004/03/13 23:00:39 srichter Exp $
"""
import unittest
from zope.interface.verify import verifyObject
from zope.app.annotation.interfaces import IAnnotations

class IAnnotationsTest(unittest.TestCase):
    """Test the IAnnotations interface.

    The test case class expects the 'IAnnotations' to be in
    'self.annotations'.
    """

    def setUp(self):
        self.obj = {1:2, 3:4}

    def testInterfaceVerifies(self):
        verifyObject(IAnnotations, self.annotations)

    def testStorage(self):
        # test __getitem__
        self.annotations['unittest'] = self.obj
        res = self.annotations['unittest']
        self.failUnlessEqual(self.obj, res)

    def testGetitemException(self):
        # test __getitem__ raises exception on unknown key
        self.assertRaises(KeyError, self.annotations.__getitem__,'randomkey')

    def testGet(self):
        # test get
        self.annotations['unittest'] = obj
        res = self.annotations.get('unittest')
        self.failUnlessEqual(obj, res)

    def testGet(self):
        # test get with no set
        res = self.annotations.get('randomkey')
        self.failUnlessEqual(None, res)

    def testGetDefault(self):
        # test get returns default
        res = self.annotations.get('randomkey', 'default')
        self.failUnlessEqual('default', res)

    def testDel(self):
        self.annotations['unittest'] = self.obj
        del self.annotations['unittest']
        self.failUnlessEqual(None, self.annotations.get('unittest'))

    def testDelRaisesKeyError(self):
        self.assertRaises(KeyError, self.annotations.__delitem__, 'unittest')


=== Added File Zope3/src/zope/app/annotation/tests/test_attributeannotations.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.
#
##############################################################################
"""Tests the 'AttributeAnnotations' adapter.

$Id: test_attributeannotations.py,v 1.1 2004/03/13 23:00:39 srichter Exp $
"""
from unittest import main, makeSuite
from zope.testing.cleanup import CleanUp # Base class w registry cleanup
from zope.app.annotation.tests.annotations import IAnnotationsTest
from zope.app.annotation.attribute import AttributeAnnotations
from zope.app.annotation.interfaces import IAttributeAnnotatable
from zope.interface import implements

class Dummy:
    implements(IAttributeAnnotatable)

class AttributeAnnotationsTest(IAnnotationsTest, CleanUp):

    def setUp(self):
        self.annotations = AttributeAnnotations(Dummy())
        super(AttributeAnnotationsTest, self).setUp()


def test_suite():
    return makeSuite(AttributeAnnotationsTest)

if __name__=='__main__':
    main(defaultTest='test_suite')




More information about the Zope3-Checkins mailing list