[Zope-CVS] CVS: Packages/pypes/pypes/tests - test_extent.py:1.1
runtests.py:1.4
Casey Duncan
casey at zope.com
Mon Feb 9 00:24:52 EST 2004
Update of /cvs-repository/Packages/pypes/pypes/tests
In directory cvs.zope.org:/tmp/cvs-serv21905/tests
Modified Files:
runtests.py
Added Files:
test_extent.py
Log Message:
Add basic extent service infrastructure and tests
Simplify IExtentMap interface
=== Added File Packages/pypes/pypes/tests/test_extent.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.
#
##############################################################################
"""Extent tests
$Id: test_extent.py,v 1.1 2004/02/09 05:24:51 caseman Exp $"""
import unittest
from zope.interface import Interface, implements
from zope.interface.verify import verifyObject
from pypes.interfaces import IExtentMap, IExtentService
from pypes.tests.common import TestConnection, sort
class FooClass:
pass
class BarClass(object):
pass
class BazClass(BarClass):
pass
class SplatClass(object):
pass
class IMoe(Interface):
pass
class ILarry(Interface):
pass
class ICurly(ILarry):
pass
class IJoe(Interface):
pass
class TestExtentMap:
"""Dummy extent map for testing"""
implements(IExtentMap)
def __init__(self, *keys):
self._keys = keys
def __getitem__(self, key):
if key in self._keys:
return key
for k in self._keys:
if isinstance(key, type(k)):
raise KeyError, key
raise TypeError, key
def __iter__(self):
return iter(self._keys)
def update(self):
pass
def makeClassMap(self, dbconn):
return TestExtentMap(FooClass, BarClass, BazClass)
def makeInterfaceMap(self, dbconn):
return TestExtentMap(IMoe, ILarry, ICurly)
class TestExtentService(unittest.TestCase):
def setUp(self):
self.extent = self.makeExtentService()
def makeExtentService(self, **kw):
from pypes.extent import ExtentService
orig_class_map = ExtentService._class_map_factory
orig_iface_map = ExtentService._interface_map_factory
ExtentService._class_map_factory = makeClassMap
ExtentService._interface_map_factory = makeInterfaceMap
extent = ExtentService(TestConnection(), **kw)
ExtentService._class_map_factory = orig_class_map
ExtentService._interface_map_factory = orig_iface_map
return extent
def testInterface(self):
from pypes.interfaces import IExtentService
self.failUnless(verifyObject(IExtentService, self.extent))
def testGetClass(self):
self.failUnless(self.extent[FooClass] is FooClass)
self.failUnless(self.extent[BarClass] is BarClass)
self.failUnless(self.extent[BazClass] is BazClass)
def testGetClassRaisesKeyError(self):
self.assertRaises(KeyError, lambda cls: self.extent[cls], SplatClass)
def testGetInterface(self):
self.failUnless(self.extent[IMoe] is IMoe)
self.failUnless(self.extent[ILarry] is ILarry)
self.failUnless(self.extent[ICurly] is ICurly)
def testGetInterfaceRaisesKeyError(self):
self.assertRaises(KeyError, lambda iface: self.extent[iface], IJoe)
def testGetRaisesTypeError(self):
self.assertRaises(TypeError, lambda x: self.extent[x], 'nigel')
def testContainsClass(self):
self.failUnless(FooClass in self.extent)
self.failUnless(BarClass in self.extent)
self.failUnless(BazClass in self.extent)
self.failIf(SplatClass in self.extent)
def testContainsInterface(self):
self.failUnless(IMoe in self.extent)
self.failUnless(ILarry in self.extent)
self.failUnless(ICurly in self.extent)
self.failIf(IJoe in self.extent)
def testContainsRaisesTypeError(self):
try:
'getty' in self.extent
except TypeError:
pass
else:
self.fail()
def testIter(self):
all = list(iter(self.extent))
expected = [FooClass, BarClass, BazClass, IMoe, ILarry, ICurly]
self.assertEqual(sort(all), sort(expected))
def testOnlyClasses(self):
self.extent = self.makeExtentService(interface_extents=False)
self.testGetClass()
self.testContainsClass()
self.assertRaises(TypeError, self.testGetInterface)
self.assertRaises(TypeError, self.testContainsInterface)
def testOnlyInterfaces(self):
self.extent = self.makeExtentService(class_extents=False)
self.testGetInterface()
self.testContainsInterface()
self.assertRaises(TypeError, self.testGetClass)
self.assertRaises(TypeError, self.testContainsClass)
def testMustEnableClassesOrInterfaces(self):
self.assertRaises(AssertionError, self.makeExtentService,
interface_extents=False, class_extents=False)
if __name__ == '__main__':
unittest.main()
=== Packages/pypes/pypes/tests/runtests.py 1.3 => 1.4 ===
--- Packages/pypes/pypes/tests/runtests.py:1.3 Sat Jan 31 00:23:31 2004
+++ Packages/pypes/pypes/tests/runtests.py Mon Feb 9 00:24:51 2004
@@ -10,6 +10,7 @@
from test_event import *
from test_graph import *
from test_expression import *
+from test_extent import *
if __name__ == '__main__':
unittest.main()
More information about the Zope-CVS
mailing list