[Zodb-checkins] SVN: ZODB/trunk/src/BTrees/ add integer family
conveniences
Gary Poster
gary at zope.com
Wed Apr 25 16:09:15 EDT 2007
Log message for revision 74761:
add integer family conveniences
Changed:
U ZODB/trunk/src/BTrees/Interfaces.py
U ZODB/trunk/src/BTrees/__init__.py
U ZODB/trunk/src/BTrees/tests/testBTrees.py
-=-
Modified: ZODB/trunk/src/BTrees/Interfaces.py
===================================================================
--- ZODB/trunk/src/BTrees/Interfaces.py 2007-04-25 18:10:55 UTC (rev 74760)
+++ ZODB/trunk/src/BTrees/Interfaces.py 2007-04-25 20:09:15 UTC (rev 74761)
@@ -440,11 +440,28 @@
linear-time pass.
"""
+class IIntegerFamily(Interface):
+ """the 64-bit or 32-bit family"""
+ IOModule = Attribute(
+ 'The IIntegerObjectBTreeModule for this family')
+ OIModule = Attribute(
+ 'The IObjectIntegerBTreeModule for this family')
+ IIModule = Attribute(
+ 'The IIntegerIntegerBTreeModule for this family')
+ IFModule = Attribute(
+ 'The IIntegerFloatBTreeModule for this family')
+ maxint = Attribute('The maximum integer storable in this family')
+ minint = Attribute('The minimum integer storable in this family')
+
+
class IIntegerObjectBTreeModule(IBTreeModule, IMerge):
"""keys, or set values, are integers; values are objects.
describes IOBTree and LOBTree"""
+
+ family = Attribute('The IIntegerFamily of this module')
+
class IObjectIntegerBTreeModule(IBTreeModule, IIMerge):
"""keys, or set values, are objects; values are integers.
@@ -452,12 +469,18 @@
object id)! Homogenous key types recommended.
describes OIBTree and LOBTree"""
+
+ family = Attribute('The IIntegerFamily of this module')
+
class IIntegerIntegerBTreeModule(IBTreeModule, IIMerge, IMergeIntegerKey):
"""keys, or set values, are integers; values are also integers.
describes IIBTree and LLBTree"""
+
+ family = Attribute('The IIntegerFamily of this module')
+
class IObjectObjectBTreeModule(IBTreeModule, IMerge):
"""keys, or set values, are objects; values are also objects.
@@ -466,11 +489,15 @@
describes OOBTree"""
+
class IIntegerFloatBTreeModule(IBTreeModule, IMerge):
"""keys, or set values, are integers; values are floats.
describes IFBTree and LFBTree"""
+
+ family = Attribute('The IIntegerFamily of this module')
+
###############################################################
# IMPORTANT NOTE
#
Modified: ZODB/trunk/src/BTrees/__init__.py
===================================================================
--- ZODB/trunk/src/BTrees/__init__.py 2007-04-25 18:10:55 UTC (rev 74760)
+++ ZODB/trunk/src/BTrees/__init__.py 2007-04-25 20:09:15 UTC (rev 74761)
@@ -1 +1,12 @@
-# This is a Python package.
+import BTrees.family64
+import BTrees.family32
+
+BTrees.family64.IOModule.family = BTrees.family64
+BTrees.family64.OIModule.family = BTrees.family64
+BTrees.family64.IFModule.family = BTrees.family64
+BTrees.family64.IIModule.family = BTrees.family64
+
+BTrees.family32.IOModule.family = BTrees.family32
+BTrees.family32.OIModule.family = BTrees.family32
+BTrees.family32.IFModule.family = BTrees.family32
+BTrees.family32.IIModule.family = BTrees.family32
Modified: ZODB/trunk/src/BTrees/tests/testBTrees.py
===================================================================
--- ZODB/trunk/src/BTrees/tests/testBTrees.py 2007-04-25 18:10:55 UTC (rev 74760)
+++ ZODB/trunk/src/BTrees/tests/testBTrees.py 2007-04-25 20:09:15 UTC (rev 74761)
@@ -26,6 +26,8 @@
from BTrees.LFBTree import LFBTree, LFBucket, LFSet, LFTreeSet
from BTrees.OLBTree import OLBTree, OLBucket, OLSet, OLTreeSet
+import BTrees.family32
+import BTrees.family64
import BTrees.OOBTree
import BTrees.IOBTree
import BTrees.IIBTree
@@ -1676,6 +1678,72 @@
self.assert_(
zope.interface.verify.verifyObject(self.iface, self.module))
+ def testFamily(self):
+ if self.prefix == 'OO':
+ self.assert_(
+ getattr(self.module, 'family', self) is self)
+ elif 'L' in self.prefix:
+ self.assert_(self.module.family is BTrees.family64)
+ elif 'I' in self.prefix:
+ self.assert_(self.module.family is BTrees.family32)
+
+class FamilyTest(TestCase):
+ def test32(self):
+ self.assert_(
+ zope.interface.verify.verifyObject(
+ BTrees.Interfaces.IIntegerFamily, BTrees.family32))
+ self.assertEquals(
+ BTrees.family32.IOModule, BTrees.IOBTree)
+ self.assertEquals(
+ BTrees.family32.OIModule, BTrees.OIBTree)
+ self.assertEquals(
+ BTrees.family32.IIModule, BTrees.IIBTree)
+ self.assertEquals(
+ BTrees.family32.IFModule, BTrees.IFBTree)
+ s = IOTreeSet()
+ s.insert(BTrees.family32.maxint)
+ self.assert_(BTrees.family32.maxint in s)
+ s = IOTreeSet()
+ s.insert(BTrees.family32.minint)
+ self.assert_(BTrees.family32.minint in s)
+ s = IOTreeSet()
+ # this next bit illustrates an, um, "interesting feature". If
+ # the characteristics change to match the 64 bit version, please
+ # feel free to change.
+ big = BTrees.family32.maxint + 1
+ if isinstance(big, long):
+ self.assertRaises(TypeError, s.insert, big)
+ self.assertRaises(TypeError, s.insert, BTrees.family32.minint - 1)
+ else: # 64 bit Python
+ s.insert(BTrees.family32.maxint + 1)
+ self.assert_(BTrees.family32.maxint + 1 not in s)
+ # yeah, it's len of 1 now...don't look...don't look...
+ s = IOTreeSet()
+ s.insert(BTrees.family32.minint - 1)
+ self.assert_(BTrees.family32.minint - 1 not in s)
+
+ def test64(self):
+ self.assert_(
+ zope.interface.verify.verifyObject(
+ BTrees.Interfaces.IIntegerFamily, BTrees.family64))
+ self.assertEquals(
+ BTrees.family64.IOModule, BTrees.LOBTree)
+ self.assertEquals(
+ BTrees.family64.OIModule, BTrees.OLBTree)
+ self.assertEquals(
+ BTrees.family64.IIModule, BTrees.LLBTree)
+ self.assertEquals(
+ BTrees.family64.IFModule, BTrees.LFBTree)
+ s = LOTreeSet()
+ s.insert(BTrees.family64.maxint)
+ self.assert_(BTrees.family64.maxint in s)
+ s = LOTreeSet()
+ s.insert(BTrees.family64.minint)
+ self.assert_(BTrees.family64.minint in s)
+ s = LOTreeSet()
+ self.assertRaises(ValueError, s.insert, BTrees.family64.maxint + 1)
+ self.assertRaises(ValueError, s.insert, BTrees.family64.minint - 1)
+
def test_suite():
s = TestSuite()
@@ -1723,6 +1791,7 @@
DegenerateBTree,
TestCmpError,
BugFixes,
+ FamilyTest,
):
s.addTest(makeSuite(klass))
More information about the Zodb-checkins
mailing list