Commit 0d40356d authored by Fred Drake's avatar Fred Drake

add new 64-bit btree types (patch from Jim), merged from trunk

parent 6ab8173f
What's new in ZODB3 3.7.0? What's new in ZODB3 3.7.0?
========================== ==========================
Release date: ??? Release date: ???
...@@ -5,6 +6,11 @@ Release date: ??? ...@@ -5,6 +6,11 @@ Release date: ???
BTrees BTrees
------ ------
- Added support for 64-bit integer BTrees as separate types.
(For now, we're retaining compile-time support for making the
regular integer BTrees 64-bit.)
- Support for 64-bit integer keys and values has been provided as a - Support for 64-bit integer keys and values has been provided as a
compile-time option. compile-time option.
......
...@@ -69,7 +69,7 @@ base_btrees_depends = [ ...@@ -69,7 +69,7 @@ base_btrees_depends = [
"src/persistent/cPersistence.h", "src/persistent/cPersistence.h",
] ]
_flavors = {"O": "object", "I": "int", "F": "float"} _flavors = {"O": "object", "I": "int", "F": "float", 'L': 'int'}
KEY_H = "src/BTrees/%skeymacros.h" KEY_H = "src/BTrees/%skeymacros.h"
VALUE_H = "src/BTrees/%svaluemacros.h" VALUE_H = "src/BTrees/%svaluemacros.h"
...@@ -88,7 +88,9 @@ def BTreeExtension(flavor): ...@@ -88,7 +88,9 @@ def BTreeExtension(flavor):
return Extension(name, sources, **kwargs) return Extension(name, sources, **kwargs)
exts = [BTreeExtension(flavor) exts = [BTreeExtension(flavor)
for flavor in ("OO", "IO", "OI", "II", "IF", "fs")] for flavor in ("OO", "IO", "OI", "II", "IF",
"fs", "LO", "OL", "LL", "LF",
)]
cPersistence = Extension(name = 'persistent.cPersistence', cPersistence = Extension(name = 'persistent.cPersistence',
include_dirs = include, include_dirs = include,
......
##############################################################################
#
# 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.1 (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
#
##############################################################################
# hack to overcome dynamic-linking headache.
from _LFBTree import *
##############################################################################
#
# 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.1 (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
#
##############################################################################
# hack to overcome dynamic-linking headache.
from _LLBTree import *
##############################################################################
#
# 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.1 (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
#
##############################################################################
# hack to overcome dynamic-linking headache.
from _LOBTree import *
##############################################################################
#
# 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.1 (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
#
##############################################################################
# hack to overcome dynamic-linking headache.
from _OLBTree import *
...@@ -118,3 +118,83 @@ ...@@ -118,3 +118,83 @@
depends-on TreeSetTemplate.c depends-on TreeSetTemplate.c
depends-on sorters.c depends-on sorters.c
</extension> </extension>
<extension _LFBTree>
source _LFBTree.c
# Specialization:
depends-on objectkeymacros.h
depends-on objectvaluemacros.h
# Common btree includes:
depends-on BTreeItemsTemplate.c
depends-on BTreeModuleTemplate.c
depends-on BTreeTemplate.c
depends-on BucketTemplate.c
depends-on MergeTemplate.c
depends-on SetOpTemplate.c
depends-on SetTemplate.c
depends-on TreeSetTemplate.c
depends-on sorters.c
</extension>
<extension _LLBTree>
source _LLBTree.c
# Specialization:
depends-on objectkeymacros.h
depends-on objectvaluemacros.h
# Common btree includes:
depends-on BTreeItemsTemplate.c
depends-on BTreeModuleTemplate.c
depends-on BTreeTemplate.c
depends-on BucketTemplate.c
depends-on MergeTemplate.c
depends-on SetOpTemplate.c
depends-on SetTemplate.c
depends-on TreeSetTemplate.c
depends-on sorters.c
</extension>
<extension _LOBTree>
source _LOBTree.c
# Specialization:
depends-on objectkeymacros.h
depends-on objectvaluemacros.h
# Common btree includes:
depends-on BTreeItemsTemplate.c
depends-on BTreeModuleTemplate.c
depends-on BTreeTemplate.c
depends-on BucketTemplate.c
depends-on MergeTemplate.c
depends-on SetOpTemplate.c
depends-on SetTemplate.c
depends-on TreeSetTemplate.c
depends-on sorters.c
</extension>
<extension _OLBTree>
source _OLBTree.c
# Specialization:
depends-on objectkeymacros.h
depends-on objectvaluemacros.h
# Common btree includes:
depends-on BTreeItemsTemplate.c
depends-on BTreeModuleTemplate.c
depends-on BTreeTemplate.c
depends-on BucketTemplate.c
depends-on MergeTemplate.c
depends-on SetOpTemplate.c
depends-on SetTemplate.c
depends-on TreeSetTemplate.c
depends-on sorters.c
</extension>
/*############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
############################################################################*/
#define MASTER_ID "$Id: _IFBTree.c 67074 2006-04-17 19:13:39Z fdrake $\n"
/* IFBTree - int key, float value BTree
Implements a collection using int type keys
and float type values
*/
/* Setup template macros */
#define PERSISTENT
#define MOD_NAME_PREFIX "LF"
#define INITMODULE init_LFBTree
#define DEFAULT_MAX_BUCKET_SIZE 120
#define DEFAULT_MAX_BTREE_SIZE 500
#define ZODB_64BIT_INTS
#include "intkeymacros.h"
#include "floatvaluemacros.h"
#include "BTreeModuleTemplate.c"
/*############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
############################################################################*/
#define MASTER_ID "$Id: _IIBTree.c 25186 2004-06-02 15:07:33Z jim $\n"
/* IIBTree - int key, int value BTree
Implements a collection using int type keys
and int type values
*/
/* Setup template macros */
#define PERSISTENT
#define MOD_NAME_PREFIX "LL"
#define INITMODULE init_LLBTree
#define DEFAULT_MAX_BUCKET_SIZE 120
#define DEFAULT_MAX_BTREE_SIZE 500
#define ZODB_64BIT_INTS
#include "intkeymacros.h"
#include "intvaluemacros.h"
#include "BTreeModuleTemplate.c"
/*############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
############################################################################*/
#define MASTER_ID "$Id: _IOBTree.c 25186 2004-06-02 15:07:33Z jim $\n"
/* IOBTree - int key, object value BTree
Implements a collection using int type keys
and object type values
*/
#define PERSISTENT
#define MOD_NAME_PREFIX "LO"
#define DEFAULT_MAX_BUCKET_SIZE 60
#define DEFAULT_MAX_BTREE_SIZE 500
#define INITMODULE init_LOBTree
#define ZODB_64BIT_INTS
#include "intkeymacros.h"
#include "objectvaluemacros.h"
#include "BTreeModuleTemplate.c"
/*############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
############################################################################*/
#define MASTER_ID "$Id: _OIBTree.c 25186 2004-06-02 15:07:33Z jim $\n"
/* OIBTree - object key, int value BTree
Implements a collection using object type keys
and int type values
*/
#define PERSISTENT
#define MOD_NAME_PREFIX "OL"
#define INITMODULE init_OLBTree
#define DEFAULT_MAX_BUCKET_SIZE 60
#define DEFAULT_MAX_BTREE_SIZE 250
#define ZODB_64BIT_INTS
#include "objectkeymacros.h"
#include "intvaluemacros.h"
#include "BTreeModuleTemplate.c"
...@@ -39,35 +39,27 @@ from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet ...@@ -39,35 +39,27 @@ from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet
from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet
from BTrees.IIBTree import IIBTree, IIBucket, IISet, IITreeSet from BTrees.IIBTree import IIBTree, IIBucket, IISet, IITreeSet
from BTrees.IFBTree import IFBTree, IFBucket, IFSet, IFTreeSet from BTrees.IFBTree import IFBTree, IFBucket, IFSet, IFTreeSet
from BTrees.OLBTree import OLBTree, OLBucket, OLSet, OLTreeSet
from BTrees.LOBTree import LOBTree, LOBucket, LOSet, LOTreeSet
from BTrees.LLBTree import LLBTree, LLBucket, LLSet, LLTreeSet
from BTrees.LFBTree import LFBTree, LFBucket, LFSet, LFTreeSet
from ZODB.utils import positive_id, oid_repr from ZODB.utils import positive_id, oid_repr
TYPE_UNKNOWN, TYPE_BTREE, TYPE_BUCKET = range(3) TYPE_UNKNOWN, TYPE_BTREE, TYPE_BUCKET = range(3)
_type2kind = {IOBTree: (TYPE_BTREE, True), _type2kind = {}
IIBTree: (TYPE_BTREE, True), for kv in ('OO',
IFBTree: (TYPE_BTREE, True), 'II', 'IO', 'OI', 'IF',
OIBTree: (TYPE_BTREE, True), 'LL', 'LO', 'OL', 'LF',
OOBTree: (TYPE_BTREE, True), ):
for name, kind in (
IOBucket: (TYPE_BUCKET, True), ('BTree', (TYPE_BTREE, True)),
IIBucket: (TYPE_BUCKET, True), ('Bucket', (TYPE_BUCKET, True)),
IFBucket: (TYPE_BUCKET, True), ('TreeSet', (TYPE_BTREE, False)),
OIBucket: (TYPE_BUCKET, True), ('Set', (TYPE_BUCKET, False)),
OOBucket: (TYPE_BUCKET, True), ):
_type2kind[globals()[kv+name]] = kind
IOTreeSet: (TYPE_BTREE, False),
IITreeSet: (TYPE_BTREE, False),
IFTreeSet: (TYPE_BTREE, False),
OITreeSet: (TYPE_BTREE, False),
OOTreeSet: (TYPE_BTREE, False),
IOSet: (TYPE_BUCKET, False),
IISet: (TYPE_BUCKET, False),
IFSet: (TYPE_BUCKET, False),
OISet: (TYPE_BUCKET, False),
OOSet: (TYPE_BUCKET, False),
}
# Return pair # Return pair
# #
...@@ -117,20 +109,13 @@ BTREE_EMPTY, BTREE_ONE, BTREE_NORMAL = range(3) ...@@ -117,20 +109,13 @@ BTREE_EMPTY, BTREE_ONE, BTREE_NORMAL = range(3)
# self->firstbucket # self->firstbucket
# ) # )
_btree2bucket = {IOBTree: IOBucket, _btree2bucket = {}
IOTreeSet: IOSet, for kv in ('OO',
'II', 'IO', 'OI', 'IF',
IIBTree: IIBucket, 'LL', 'LO', 'OL', 'LF',
IITreeSet: IISet, ):
_btree2bucket[globals()[kv+'BTree']] = globals()[kv+'Bucket']
IFBTree: IFBucket, _btree2bucket[globals()[kv+'TreeSet']] = globals()[kv+'Set']
IFTreeSet: IFSet,
OIBTree: OIBucket,
OITreeSet: OISet,
OOBTree: OOBucket,
OOTreeSet: OOSet}
def crack_btree(t, is_mapping): def crack_btree(t, is_mapping):
state = t.__getstate__() state = t.__getstate__()
......
...@@ -13,12 +13,17 @@ ...@@ -13,12 +13,17 @@
############################################################################## ##############################################################################
import random import random
from unittest import TestCase, TestSuite, TextTestRunner, makeSuite from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
from types import ClassType
from BTrees.OOBTree import OOBTree, OOBucket, OOSet, OOTreeSet from BTrees.OOBTree import OOBTree, OOBucket, OOSet, OOTreeSet
from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet
from BTrees.IIBTree import IIBTree, IIBucket, IISet, IITreeSet from BTrees.IIBTree import IIBTree, IIBucket, IISet, IITreeSet
from BTrees.IFBTree import IFBTree, IFBucket, IFSet, IFTreeSet from BTrees.IFBTree import IFBTree, IFBucket, IFSet, IFTreeSet
from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet
from BTrees.LOBTree import LOBTree, LOBucket, LOSet, LOTreeSet
from BTrees.LLBTree import LLBTree, LLBucket, LLSet, LLTreeSet
from BTrees.LFBTree import LFBTree, LFBucket, LFSet, LFTreeSet
from BTrees.OLBTree import OLBTree, OLBucket, OLSet, OLTreeSet
from BTrees.IIBTree import using64bits from BTrees.IIBTree import using64bits
from BTrees.check import check from BTrees.check import check
...@@ -32,6 +37,9 @@ class Base(TestCase): ...@@ -32,6 +37,9 @@ class Base(TestCase):
db = None db = None
def setUp(self):
self.t = self.t_class()
def tearDown(self): def tearDown(self):
if self.db is not None: if self.db is not None:
self.db.close() self.db.close()
...@@ -1549,86 +1557,79 @@ class DegenerateBTree(TestCase): ...@@ -1549,86 +1557,79 @@ class DegenerateBTree(TestCase):
# at some unrelated line. # at some unrelated line.
del t # trigger destructor del t # trigger destructor
class IIBucketTest(MappingBase):
def setUp(self):
self.t = IIBucket()
class IFBucketTest(MappingBase):
def setUp(self):
self.t = IFBucket()
class IOBucketTest(MappingBase):
def setUp(self):
self.t = IOBucket()
class OIBucketTest(MappingBase):
def setUp(self):
self.t = OIBucket()
class OOBucketTest(MappingBase):
def setUp(self):
self.t = OOBucket()
class IITreeSetTest(NormalSetTests): class BugFixes(TestCase):
def setUp(self):
self.t = IITreeSet()
class IFTreeSetTest(NormalSetTests):
def setUp(self):
self.t = IFTreeSet()
class IOTreeSetTest(NormalSetTests):
def setUp(self):
self.t = IOTreeSet()
class OITreeSetTest(NormalSetTests):
def setUp(self):
self.t = OITreeSet()
class OOTreeSetTest(NormalSetTests):
def setUp(self):
self.t = OOTreeSet()
class IISetTest(ExtendedSetTests):
def setUp(self):
self.t = IISet()
# Collector 1843. Error returns were effectively ignored in # Collector 1843. Error returns were effectively ignored in
# Bucket_rangeSearch(), leading to "delayed" errors, or worse. # Bucket_rangeSearch(), leading to "delayed" errors, or worse.
def testNonIntKeyRaises(self): def testFixed1843(self):
self.t.insert(1) t = IISet()
t.insert(1)
# This one used to fail to raise the TypeError when it occurred. # This one used to fail to raise the TypeError when it occurred.
self.assertRaises(TypeError, self.t.keys, "") self.assertRaises(TypeError, t.keys, "")
# This one used to segfault. # This one used to segfault.
self.assertRaises(TypeError, self.t.keys, 0, "") self.assertRaises(TypeError, t.keys, 0, "")
class IFSetTest(ExtendedSetTests):
class IIBTreeTest(BTreeTests):
def setUp(self): def setUp(self):
self.t = IFSet() self.t = IIBTree()
class IOSetTest(ExtendedSetTests): class IFBTreeTest(BTreeTests):
def setUp(self): def setUp(self):
self.t = IOSet() self.t = IFBTree()
class OISetTest(ExtendedSetTests): class IOBTreeTest(BTreeTests):
def setUp(self): def setUp(self):
self.t = OISet() self.t = IOBTree()
class OOSetTest(ExtendedSetTests): class OIBTreeTest(BTreeTests):
def setUp(self):
self.t = OIBTree()
class OOBTreeTest(BTreeTests):
def setUp(self): def setUp(self):
self.t = OOSet() self.t = OOBTree()
class IIBTreeTest(BTreeTests, TestLongIntKeys, TestLongIntValues): if using64bits:
class IIBTreeTest(BTreeTests, TestLongIntKeys, TestLongIntValues):
def setUp(self):
self.t = IIBTree()
def getTwoValues(self):
return 1, 2
class IFBTreeTest(BTreeTests, TestLongIntKeys):
def setUp(self):
self.t = IFBTree()
def getTwoValues(self):
return 0.5, 1.5
class IOBTreeTest(BTreeTests, TestLongIntKeys):
def setUp(self):
self.t = IOBTree()
class OIBTreeTest(BTreeTests, TestLongIntValues):
def setUp(self):
self.t = OIBTree()
def getTwoKeys(self):
return object(), object()
class LLBTreeTest(BTreeTests, TestLongIntKeys, TestLongIntValues):
def setUp(self): def setUp(self):
self.t = IIBTree() self.t = LLBTree()
def getTwoValues(self): def getTwoValues(self):
return 1, 2 return 1, 2
class IFBTreeTest(BTreeTests, TestLongIntKeys): class LFBTreeTest(BTreeTests, TestLongIntKeys):
def setUp(self): def setUp(self):
self.t = IFBTree() self.t = LFBTree()
def getTwoValues(self): def getTwoValues(self):
return 0.5, 1.5 return 0.5, 1.5
class IOBTreeTest(BTreeTests, TestLongIntKeys): class LOBTreeTest(BTreeTests, TestLongIntKeys):
def setUp(self): def setUp(self):
self.t = IOBTree() self.t = LOBTree()
class OIBTreeTest(BTreeTests, TestLongIntValues): class OLBTreeTest(BTreeTests, TestLongIntValues):
def setUp(self): def setUp(self):
self.t = OIBTree() self.t = OLBTree()
def getTwoKeys(self): def getTwoKeys(self):
return object(), object() return object(), object()
class OOBTreeTest(BTreeTests): class OOBTreeTest(BTreeTests):
def setUp(self): def setUp(self):
self.t = OOBTree() self.t = OOBTree()
# cmp error propagation tests # cmp error propagation tests
class DoesntLikeBeingCompared: class DoesntLikeBeingCompared:
...@@ -1650,12 +1651,22 @@ class TestCmpError(TestCase): ...@@ -1650,12 +1651,22 @@ class TestCmpError(TestCase):
def test_suite(): def test_suite():
s = TestSuite() s = TestSuite()
for kv in ('OO',
'II', 'IO', 'OI', 'IF',
'LL', 'LO', 'OL', 'LF',
):
for name, bases in (('Bucket', (MappingBase,)),
('TreeSet', (NormalSetTests,)),
('Set', (ExtendedSetTests,)),
):
klass = ClassType(kv + name + 'Test', bases,
dict(t_class=globals()[kv+name]))
s.addTest(makeSuite(klass))
for klass in ( for klass in (
IIBucketTest, IIBTreeTest, IISetTest, IITreeSetTest, IIBTreeTest, IFBTreeTest, IOBTreeTest, OIBTreeTest,
IFBucketTest, IFBTreeTest, IFSetTest, IFTreeSetTest, LLBTreeTest, LFBTreeTest, LOBTreeTest, OLBTreeTest,
IOBucketTest, IOBTreeTest, IOSetTest, IOTreeSetTest, OOBTreeTest,
OOBucketTest, OOBTreeTest, OOSetTest, OOTreeSetTest,
OIBucketTest, OIBTreeTest, OISetTest, OITreeSetTest,
# Note: there is no TestOOBTrees. The next three are # Note: there is no TestOOBTrees. The next three are
# checking for assorted TypeErrors, and when both keys # checking for assorted TypeErrors, and when both keys
...@@ -1663,7 +1674,9 @@ def test_suite(): ...@@ -1663,7 +1674,9 @@ def test_suite():
TestIIBTrees, TestIFBTrees, TestIOBTrees, TestOIBTrees, TestIIBTrees, TestIFBTrees, TestIOBTrees, TestOIBTrees,
TestIOSets, TestIOSets,
DegenerateBTree, DegenerateBTree,
TestCmpError): TestCmpError,
BugFixes,
):
s.addTest(makeSuite(klass)) s.addTest(makeSuite(klass))
return s return s
......
...@@ -13,12 +13,17 @@ ...@@ -13,12 +13,17 @@
############################################################################## ##############################################################################
import os import os
from unittest import TestCase, TestSuite, makeSuite from unittest import TestCase, TestSuite, makeSuite
from types import ClassType
from BTrees.OOBTree import OOBTree, OOBucket, OOSet, OOTreeSet from BTrees.OOBTree import OOBTree, OOBucket, OOSet, OOTreeSet
from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet
from BTrees.IIBTree import IIBTree, IIBucket, IISet, IITreeSet from BTrees.IIBTree import IIBTree, IIBucket, IISet, IITreeSet
from BTrees.IFBTree import IFBTree, IFBucket, IFSet, IFTreeSet from BTrees.IFBTree import IFBTree, IFBucket, IFSet, IFTreeSet
from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet
from BTrees.LOBTree import LOBTree, LOBucket, LOSet, LOTreeSet
from BTrees.LLBTree import LLBTree, LLBucket, LLSet, LLTreeSet
from BTrees.LFBTree import LFBTree, LFBucket, LFSet, LFTreeSet
from BTrees.OLBTree import OLBTree, OLBucket, OLSet, OLTreeSet
import transaction import transaction
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
...@@ -28,6 +33,9 @@ class Base: ...@@ -28,6 +33,9 @@ class Base:
storage = None storage = None
def setUp(self):
self.t = self.t_type()
def tearDown(self): def tearDown(self):
transaction.abort() transaction.abort()
del self.t del self.t
...@@ -322,98 +330,6 @@ def test_merge(o1, o2, o3, expect, message='failed to merge', should_fail=0): ...@@ -322,98 +330,6 @@ def test_merge(o1, o2, o3, expect, message='failed to merge', should_fail=0):
merged = o1._p_resolveConflict(s1, s2, s3) merged = o1._p_resolveConflict(s1, s2, s3)
assert merged == expected, message assert merged == expected, message
class BucketTests(MappingBase):
""" Tests common to all buckets """
class BTreeTests(MappingBase):
""" Tests common to all BTrees """
## BTree tests
class TestIOBTrees(BTreeTests, TestCase):
def setUp(self):
self.t = IOBTree()
class TestOOBTrees(BTreeTests, TestCase):
def setUp(self):
self.t = OOBTree()
class TestOIBTrees(BTreeTests, TestCase):
def setUp(self):
self.t = OIBTree()
class TestIIBTrees(BTreeTests, TestCase):
def setUp(self):
self.t = IIBTree()
class TestIFBTrees(BTreeTests, TestCase):
def setUp(self):
self.t = IFBTree()
## Set tests
class TestIOSets(SetTests, TestCase):
def setUp(self):
self.t = IOSet()
class TestOOSets(SetTests, TestCase):
def setUp(self):
self.t = OOSet()
class TestIISets(SetTests, TestCase):
def setUp(self):
self.t = IISet()
class TestIFSets(SetTests, TestCase):
def setUp(self):
self.t = IFSet()
class TestOISets(SetTests, TestCase):
def setUp(self):
self.t = OISet()
class TestIOTreeSets(SetTests, TestCase):
def setUp(self):
self.t = IOTreeSet()
class TestOOTreeSets(SetTests, TestCase):
def setUp(self):
self.t = OOTreeSet()
class TestIITreeSets(SetTests, TestCase):
def setUp(self):
self.t = IITreeSet()
class TestIFTreeSets(SetTests, TestCase):
def setUp(self):
self.t = IFTreeSet()
class TestOITreeSets(SetTests, TestCase):
def setUp(self):
self.t = OITreeSet()
## Bucket tests
class TestIOBuckets(BucketTests, TestCase):
def setUp(self):
self.t = IOBucket()
class TestOOBuckets(BucketTests, TestCase):
def setUp(self):
self.t = OOBucket()
class TestIIBuckets(BucketTests, TestCase):
def setUp(self):
self.t = IIBucket()
class TestIFBuckets(BucketTests, TestCase):
def setUp(self):
self.t = IFBucket()
class TestOIBuckets(BucketTests, TestCase):
def setUp(self):
self.t = OIBucket()
class NastyConfict(Base, TestCase): class NastyConfict(Base, TestCase):
def setUp(self): def setUp(self):
self.t = OOBTree() self.t = OOBTree()
...@@ -846,12 +762,19 @@ class NastyConfict(Base, TestCase): ...@@ -846,12 +762,19 @@ class NastyConfict(Base, TestCase):
def test_suite(): def test_suite():
suite = TestSuite() suite = TestSuite()
for k in (
TestIIBTrees, TestIISets, TestIITreeSets, TestIIBuckets, for kv in ('OO',
TestIFBTrees, TestIFSets, TestIFTreeSets, TestIFBuckets, 'II', 'IO', 'OI', 'IF',
TestIOBTrees, TestIOSets, TestIOTreeSets, TestIOBuckets, 'LL', 'LO', 'OL', 'LF',
TestOOBTrees, TestOOSets, TestOOTreeSets, TestOOBuckets, ):
TestOIBTrees, TestOISets, TestOITreeSets, TestOIBuckets, for name, bases in (('BTree', (MappingBase, TestCase)),
NastyConfict): ('Bucket', (MappingBase, TestCase)),
suite.addTest(makeSuite(k)) ('TreeSet', (SetTests, TestCase)),
('Set', (SetTests, TestCase)),
):
klass = ClassType(kv + name + 'Test', bases,
dict(t_type=globals()[kv+name]))
suite.addTest(makeSuite(klass))
suite.addTest(makeSuite(NastyConfict))
return suite return suite
...@@ -15,8 +15,13 @@ from unittest import TestCase, TestSuite, TextTestRunner, makeSuite ...@@ -15,8 +15,13 @@ from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
from BTrees.OOBTree import OOBTree, OOBucket, OOSet, OOTreeSet from BTrees.OOBTree import OOBTree, OOBucket, OOSet, OOTreeSet
from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet
from BTrees.IFBTree import IFBTree, IFBucket, IFSet, IFTreeSet
from BTrees.IIBTree import IIBTree, IIBucket, IISet, IITreeSet from BTrees.IIBTree import IIBTree, IIBucket, IISet, IITreeSet
from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet
from BTrees.LOBTree import LOBTree, LOBucket, LOSet, LOTreeSet
from BTrees.LFBTree import LFBTree, LFBucket, LFSet, LFTreeSet
from BTrees.LLBTree import LLBTree, LLBucket, LLSet, LLTreeSet
from BTrees.OLBTree import OLBTree, OLBucket, OLSet, OLTreeSet
# Subclasses have to set up: # Subclasses have to set up:
# builders - functions to build inputs, taking an optional keys arg # builders - functions to build inputs, taking an optional keys arg
...@@ -169,6 +174,10 @@ def makeBuilder(mapbuilder): ...@@ -169,6 +174,10 @@ def makeBuilder(mapbuilder):
return mapbuilder(zip(keys, keys)) return mapbuilder(zip(keys, keys))
return result return result
class PureOO(SetResult):
from BTrees.OOBTree import union, intersection, difference
builders = OOSet, OOTreeSet, makeBuilder(OOBTree), makeBuilder(OOBucket)
class PureII(SetResult): class PureII(SetResult):
from BTrees.IIBTree import union, intersection, difference from BTrees.IIBTree import union, intersection, difference
builders = IISet, IITreeSet, makeBuilder(IIBTree), makeBuilder(IIBucket) builders = IISet, IITreeSet, makeBuilder(IIBTree), makeBuilder(IIBucket)
...@@ -177,14 +186,30 @@ class PureIO(SetResult): ...@@ -177,14 +186,30 @@ class PureIO(SetResult):
from BTrees.IOBTree import union, intersection, difference from BTrees.IOBTree import union, intersection, difference
builders = IOSet, IOTreeSet, makeBuilder(IOBTree), makeBuilder(IOBucket) builders = IOSet, IOTreeSet, makeBuilder(IOBTree), makeBuilder(IOBucket)
class PureOO(SetResult): class PureIF(SetResult):
from BTrees.OOBTree import union, intersection, difference from BTrees.IFBTree import union, intersection, difference
builders = OOSet, OOTreeSet, makeBuilder(OOBTree), makeBuilder(OOBucket) builders = IFSet, IFTreeSet, makeBuilder(IFBTree), makeBuilder(IFBucket)
class PureOI(SetResult): class PureOI(SetResult):
from BTrees.OIBTree import union, intersection, difference from BTrees.OIBTree import union, intersection, difference
builders = OISet, OITreeSet, makeBuilder(OIBTree), makeBuilder(OIBucket) builders = OISet, OITreeSet, makeBuilder(OIBTree), makeBuilder(OIBucket)
class PureLL(SetResult):
from BTrees.LLBTree import union, intersection, difference
builders = LLSet, LLTreeSet, makeBuilder(LLBTree), makeBuilder(LLBucket)
class PureLO(SetResult):
from BTrees.LOBTree import union, intersection, difference
builders = LOSet, LOTreeSet, makeBuilder(LOBTree), makeBuilder(LOBucket)
class PureLF(SetResult):
from BTrees.LFBTree import union, intersection, difference
builders = LFSet, LFTreeSet, makeBuilder(LFBTree), makeBuilder(LFBucket)
class PureOL(SetResult):
from BTrees.OLBTree import union, intersection, difference
builders = OLSet, OLTreeSet, makeBuilder(OLBTree), makeBuilder(OLBucket)
# Subclasses must set up (as class variables): # Subclasses must set up (as class variables):
# multiunion, union # multiunion, union
# mkset, mktreeset # mkset, mktreeset
...@@ -261,6 +286,26 @@ class TestIOMultiUnion(MultiUnion): ...@@ -261,6 +286,26 @@ class TestIOMultiUnion(MultiUnion):
from BTrees.IOBTree import IOSet as mkset, IOTreeSet as mktreeset from BTrees.IOBTree import IOSet as mkset, IOTreeSet as mktreeset
from BTrees.IOBTree import IOBucket as mkbucket, IOBTree as mkbtree from BTrees.IOBTree import IOBucket as mkbucket, IOBTree as mkbtree
class TestIFMultiUnion(MultiUnion):
from BTrees.IFBTree import multiunion, union
from BTrees.IFBTree import IFSet as mkset, IFTreeSet as mktreeset
from BTrees.IFBTree import IFBucket as mkbucket, IFBTree as mkbtree
class TestLLMultiUnion(MultiUnion):
from BTrees.LLBTree import multiunion, union
from BTrees.LLBTree import LLSet as mkset, LLTreeSet as mktreeset
from BTrees.LLBTree import LLBucket as mkbucket, LLBTree as mkbtree
class TestLOMultiUnion(MultiUnion):
from BTrees.LOBTree import multiunion, union
from BTrees.LOBTree import LOSet as mkset, LOTreeSet as mktreeset
from BTrees.LOBTree import LOBucket as mkbucket, LOBTree as mkbtree
class TestLFMultiUnion(MultiUnion):
from BTrees.LFBTree import multiunion, union
from BTrees.LFBTree import LFSet as mkset, LFTreeSet as mktreeset
from BTrees.LFBTree import LFBucket as mkbucket, LFBTree as mkbtree
# Check that various special module functions are and aren't imported from # Check that various special module functions are and aren't imported from
# the expected BTree modules. # the expected BTree modules.
class TestImports(TestCase): class TestImports(TestCase):
...@@ -275,6 +320,16 @@ class TestImports(TestCase): ...@@ -275,6 +320,16 @@ class TestImports(TestCase):
else: else:
self.fail("IOBTree shouldn't have weightedUnion") self.fail("IOBTree shouldn't have weightedUnion")
from BTrees.LLBTree import weightedUnion
from BTrees.OLBTree import weightedUnion
try:
from BTrees.LOBTree import weightedUnion
except ImportError:
pass
else:
self.fail("LOBTree shouldn't have weightedUnion")
try: try:
from BTrees.OOBTree import weightedUnion from BTrees.OOBTree import weightedUnion
except ImportError: except ImportError:
...@@ -293,6 +348,16 @@ class TestImports(TestCase): ...@@ -293,6 +348,16 @@ class TestImports(TestCase):
else: else:
self.fail("IOBTree shouldn't have weightedIntersection") self.fail("IOBTree shouldn't have weightedIntersection")
from BTrees.LLBTree import weightedIntersection
from BTrees.OLBTree import weightedIntersection
try:
from BTrees.LOBTree import weightedIntersection
except ImportError:
pass
else:
self.fail("LOBTree shouldn't have weightedIntersection")
try: try:
from BTrees.OOBTree import weightedIntersection from BTrees.OOBTree import weightedIntersection
except ImportError: except ImportError:
...@@ -311,6 +376,16 @@ class TestImports(TestCase): ...@@ -311,6 +376,16 @@ class TestImports(TestCase):
else: else:
self.fail("OIBTree shouldn't have multiunion") self.fail("OIBTree shouldn't have multiunion")
from BTrees.LLBTree import multiunion
from BTrees.LOBTree import multiunion
try:
from BTrees.OLBTree import multiunion
except ImportError:
pass
else:
self.fail("OLBTree shouldn't have multiunion")
try: try:
from BTrees.OOBTree import multiunion from BTrees.OOBTree import multiunion
except ImportError: except ImportError:
...@@ -462,6 +537,18 @@ class TestWeightedOI(Weighted): ...@@ -462,6 +537,18 @@ class TestWeightedOI(Weighted):
from BTrees.OIBTree import OIBucket as mkbucket from BTrees.OIBTree import OIBucket as mkbucket
builders = OIBucket, OIBTree, itemsToSet(OISet), itemsToSet(OITreeSet) builders = OIBucket, OIBTree, itemsToSet(OISet), itemsToSet(OITreeSet)
class TestWeightedLL(Weighted):
from BTrees.LLBTree import weightedUnion, weightedIntersection
from BTrees.LLBTree import union, intersection
from BTrees.LLBTree import LLBucket as mkbucket
builders = LLBucket, LLBTree, itemsToSet(LLSet), itemsToSet(LLTreeSet)
class TestWeightedOL(Weighted):
from BTrees.OLBTree import weightedUnion, weightedIntersection
from BTrees.OLBTree import union, intersection
from BTrees.OLBTree import OLBucket as mkbucket
builders = OLBucket, OLBTree, itemsToSet(OLSet), itemsToSet(OLTreeSet)
# 'thing' is a bucket, btree, set or treeset. Return true iff it's one of the # 'thing' is a bucket, btree, set or treeset. Return true iff it's one of the
# latter two. # latter two.
...@@ -471,10 +558,16 @@ def isaset(thing): ...@@ -471,10 +558,16 @@ def isaset(thing):
def test_suite(): def test_suite():
s = TestSuite() s = TestSuite()
for klass in (TestIIMultiUnion, TestIOMultiUnion, for klass in (
TestImports, TestIIMultiUnion, TestIOMultiUnion, TestIFMultiUnion,
PureII, PureIO, PureOI, PureOO, TestLLMultiUnion, TestLOMultiUnion, TestLFMultiUnion,
TestWeightedII, TestWeightedOI): TestImports,
PureOO,
PureII, PureIO, PureIF, PureOI,
PureLL, PureLO, PureLF, PureOL,
TestWeightedII, TestWeightedOI,
TestWeightedLL, TestWeightedOL,
):
s.addTest(makeSuite(klass)) s.addTest(makeSuite(klass))
return s return s
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment