Commit 2bcabfa8 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 7f4ea073
......@@ -27,7 +27,10 @@ from BTrees.IIBTree import IITreeSet, IISet
from BTrees.tests import testBTrees
from BTrees import check as zbcheck
from BTrees.check import BTREE_EMPTY, BTREE_ONE, BTREE_NORMAL
from ZODB.MappingStorage import MappingStorage
from ZODB import DB
from persistent import Persistent
import transaction
inf = float('inf')
......@@ -451,17 +454,29 @@ def test_walkBFS():
def test_zwalkBFS():
zt = buildDegenerateZTree()
# T return kind + keys of a ztree node
def T(ztree):
assert isinstance(ztree, IITreeSet)
kind, keys, kids = zbcheck.crack_btree(ztree, False)
return (kind, keys)
# B returns keys from zbucket node
def B(zbucket):
assert isinstance(zbucket, IISet)
keys, _ = zbcheck.crack_bucket(zbucket, False)
return keys
# assign oid to created objects
zstor = MappingStorage()
db= DB(zstor)
zconn = db.open()
zroot = zconn.root()
zroot['x'] = zt
transaction.commit()
# assertT asserts that znode is tree + has specified keys and children
def assertT(znode, keyv, *children):
assert isinstance(znode, IITreeSet)
kind, keys, kids = zbcheck.crack_btree(znode, False)
assert kind == BTREE_NORMAL
assert keys == keyv
assert len(kids) == len(children)
for (child, childOK) in zip(kids, children):
assert child is childOK
# assertB asserts that znode is bucket + has specified keys
def assertB(znode, *keyv):
assert isinstance(znode, IISet)
keys, _ = zbcheck.crack_bucket(znode, False)
assert keys == keyv
R = xbtree._Range
......@@ -473,6 +488,22 @@ def test_zwalkBFS():
# [4,6)T, [6,10)B7, [10,∞)B11
# [4,6)B5
_ = zwalkv[5] # [4,6)B5
assert len(_) == 1
assert _[0].range == R(4,6)
assertB(_[0].node, 5)
b5 = _[0]
_ = zwalkv[4] # [4,6)T, [6,10)B7, [10,∞)B11
assert len(_) == 3
assert _[0].range == R(4,6)
assert _[1].range == R(6,10)
assert _[2].range == R(10,inf)
assertT(_[0].node, [], b5)
assertB(_[1].node, 7)
assertB(_[2].node, 11)
_ = zwalkv[0] # [-∞,∞)T4,
assert len(_) == 1
assert _[0].range == R(-inf, inf)
......@@ -507,19 +538,6 @@ def test_zwalkBFS():
assert T(_[3].node) == (BTREE_ONE, B7)
assert T(_[4].node) == (BTREE_ONE, B11)
_ = zwalkv[4] # [4,6)T, [6,10)B7, [10,∞)B11
assert len(_) == 3
assert _[0].range == R(4,6)
assert _[1].range == R(6,10)
assert _[2].range == R(10,inf)
assert T(_[0].node) == (BTREE_ONE, B5)
assert B(_[1].node) == [7]
assert B(_[2].node) == [11]
_ = zwalkv[5] # [4,6)B5
assert len(_) == 1
assert _[0].range == R(4,6)
assert B(_[0].node) == [5]
def test_keyvSliceBy():
......
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