Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
6787cb82
Commit
6787cb82
authored
May 18, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
8225ee67
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
9 deletions
+80
-9
wcfs/internal/xbtree_test.py
wcfs/internal/xbtree_test.py
+80
-9
No files found.
wcfs/internal/xbtree_test.py
View file @
6787cb82
...
@@ -392,6 +392,29 @@ def crack_bucket(zbucket):
...
@@ -392,6 +392,29 @@ def crack_bucket(zbucket):
assert
xbtree
.
_zclassify
(
zbucket
).
is_zbucket
,
zbucket
assert
xbtree
.
_zclassify
(
zbucket
).
is_zbucket
,
zbucket
return
zbcheck
.
crack_bucket
(
zbucket
,
is_mapping
=
True
)
return
zbcheck
.
crack_bucket
(
zbucket
,
is_mapping
=
True
)
# assertT asserts that znode is normal tree node of type typ + has specified keys and children.
#
# by default children are checked exactly via "is"
# if a child is represented as 'T' or 'B' - it is only verified to be of tree
# or bucket type correspondingly.
def
assertT
(
znode
,
keyv
,
*
children
):
# -> [] of children marked with 'T'/'B'
_
=
xbtree
.
_zclassify
(
znode
)
assert
_
.
is_ztree
kind
,
keys
,
kids
=
zbcheck
.
crack_btree
(
znode
,
_
.
is_map
)
assert
kind
==
BTREE_NORMAL
assert
keys
==
keyv
assert
len
(
kids
)
==
len
(
children
)
retv
=
[]
for
(
child
,
childOK
)
in
zip
(
kids
,
children
):
if
childOK
==
'T'
:
assert
type
(
child
)
is
type
(
znode
)
retv
.
append
(
child
)
elif
childOK
==
'B'
:
assert
type
(
child
)
is
znode
.
_bucket_type
retv
.
append
(
child
)
else
:
assert
child
is
childOK
return
retv
def
test_restructure
():
def
test_restructure
():
# do restructure tests under ZODB because without ZODB connection it is not
# do restructure tests under ZODB because without ZODB connection it is not
...
@@ -510,54 +533,79 @@ def test_restructure():
...
@@ -510,54 +533,79 @@ def test_restructure():
R
(
z
,
'T/B1'
)
R
(
z
,
'T/B1'
)
assert
crack_btree
(
z
)
==
(
BTREE_ONE
,
((
1
,
X
[
1
]),),
None
)
assert
crack_btree
(
z
)
==
(
BTREE_ONE
,
((
1
,
X
[
1
]),),
None
)
R
(
z
,
'T/T/B1'
)
R
(
z
,
'T/T/B1'
)
t
,
=
assertT
(
z
,
[],
'T'
)
"""
kind, keys, kids = crack_btree(z)
kind, keys, kids = crack_btree(z)
assert (kind, keys) == (BTREE_NORMAL, [])
assert (kind, keys) == (BTREE_NORMAL, [])
assert len(kids) == 1
assert len(kids) == 1
assert isinstance(kids[0], XLOTree)
assert isinstance(kids[0], XLOTree)
"""
b1
,
=
assertT
(
t
,
[],
'B'
)
"""
kind, keys, kids = crack_btree(kids[0])
kind, keys, kids = crack_btree(kids[0])
assert (kind, keys) == (BTREE_NORMAL, [])
assert (kind, keys) == (BTREE_NORMAL, [])
assert len(kids) == 1
assert len(kids) == 1
b1, = kids
b1, = kids
assert isinstance(b1, LOBucket)
assert isinstance(b1, LOBucket)
assert
crack_bucket
(
b1
)
==
([
1
],
[
X
[
1
]])
"""
assertB
(
b1
,
1
)
#assert crack_bucket(b1) == ([1], [X[1]])
assert
b1
.
_p_oid
is
not
None
assert
b1
.
_p_oid
is
not
None
R
(
z
,
'T/B1'
)
R
(
z
,
'T/B1'
)
assertT
(
z
,
[],
b1
)
"""
kind, keys, kids = crack_btree(z)
kind, keys, kids = crack_btree(z)
assert (kind, keys) == (BTREE_NORMAL, [])
assert (kind, keys) == (BTREE_NORMAL, [])
assert len(kids) == 1
assert len(kids) == 1
assert kids[0] is b1
assert kids[0] is b1
assert
crack_bucket
(
b1
)
==
([
1
],
[
X
[
1
]])
"""
assertB
(
b1
,
1
)
#assert crack_bucket(b1) == ([1], [X[1]])
# tree with 2 k->v (not-yet committed bucket)
# tree with 2 k->v (not-yet committed bucket)
z
=
Z
(
1
,
3
)
z
=
Z
(
1
,
3
)
assert
crack_btree
(
z
)
==
(
BTREE_ONE
,
((
1
,
X
[
1
],
3
,
X
[
3
]),),
None
)
assert
crack_btree
(
z
)
==
(
BTREE_ONE
,
((
1
,
X
[
1
],
3
,
X
[
3
]),),
None
)
R
(
z
,
'T2/B1-B3'
)
R
(
z
,
'T2/B1-B3'
)
b1
,
b3
=
assertT
(
z
,
[
2
],
'B'
,
'B'
)
"""
kind, keys, kids = crack_btree(z)
kind, keys, kids = crack_btree(z)
assert (kind, keys) == (BTREE_NORMAL, [2])
assert (kind, keys) == (BTREE_NORMAL, [2])
assert len(kids) == 2
assert len(kids) == 2
b1, b3 = kids
b1, b3 = kids
assert isinstance(b1, LOBucket)
assert isinstance(b1, LOBucket)
assert isinstance(b3, LOBucket)
assert isinstance(b3, LOBucket)
"""
assert
b1
.
_p_oid
is
None
assert
b1
.
_p_oid
is
None
assert
b3
.
_p_oid
is
None
assert
b3
.
_p_oid
is
None
assertB
(
b1
,
1
)
assertB
(
b3
,
3
)
"""
assert crack_bucket(b1) == ([1], [X[1]])
assert crack_bucket(b1) == ([1], [X[1]])
assert crack_bucket(b3) == ([3], [X[3]])
assert crack_bucket(b3) == ([3], [X[3]])
"""
R
(
z
,
'T/B1,3'
)
R
(
z
,
'T/B1,3'
)
# buckets were not yet assigned oid -> collapsed back into T
# buckets were not yet assigned oid -> collapsed back into T
assert
crack_btree
(
z
)
==
(
BTREE_ONE
,
((
1
,
X
[
1
],
3
,
X
[
3
]),),
None
)
assert
crack_btree
(
z
)
==
(
BTREE_ONE
,
((
1
,
X
[
1
],
3
,
X
[
3
]),),
None
)
R
(
z
,
'T3/B1-B3'
)
R
(
z
,
'T3/B1-B3'
)
b1
,
b3
=
assertT
(
z
,
[
3
],
'B'
,
'B'
)
"""
kind, keys, kids = crack_btree(z)
kind, keys, kids = crack_btree(z)
assert (kind, keys) == (BTREE_NORMAL, [3])
assert (kind, keys) == (BTREE_NORMAL, [3])
assert len(kids) == 2
assert len(kids) == 2
b1, b3 = kids
b1, b3 = kids
assert isinstance(b1, LOBucket)
assert isinstance(b1, LOBucket)
assert isinstance(b3, LOBucket)
assert isinstance(b3, LOBucket)
"""
assert
b1
.
_p_oid
is
None
assert
b1
.
_p_oid
is
None
assert
b3
.
_p_oid
is
None
assert
b3
.
_p_oid
is
None
assertB
(
b1
,
1
)
assertB
(
b3
,
3
)
"""
assert crack_bucket(b1) == ([1], [X[1]])
assert crack_bucket(b1) == ([1], [X[1]])
assert crack_bucket(b3) == ([3], [X[3]])
assert crack_bucket(b3) == ([3], [X[3]])
"""
transaction
.
commit
()
# force buckets to be assigned oid
transaction
.
commit
()
# force buckets to be assigned oid
assert
b1
.
_p_oid
is
not
None
assert
b1
.
_p_oid
is
not
None
...
@@ -565,26 +613,39 @@ def test_restructure():
...
@@ -565,26 +613,39 @@ def test_restructure():
# restructure back - buckets not collapsed back into T
# restructure back - buckets not collapsed back into T
R
(
z
,
'T/B1,3'
)
R
(
z
,
'T/B1,3'
)
b13
,
=
assertT
(
z
,
[],
'B'
)
"""
kind, keys, kids = crack_btree(z)
kind, keys, kids = crack_btree(z)
assert (kind, keys) == (BTREE_NORMAL, [])
assert (kind, keys) == (BTREE_NORMAL, [])
assert len(kids) == 1
assert len(kids) == 1
b13 = kids[0]
b13 = kids[0]
assert b13 is b1
assert b13 is b1
assert isinstance(b13, LOBucket)
assert isinstance(b13, LOBucket)
"""
assertB
(
b13
,
1
,
3
)
"""
assert crack_bucket(b13) == ([1,3], [X[1], X[3]])
assert crack_bucket(b13) == ([1,3], [X[1], X[3]])
"""
# add 1 key -> B splits -> B + B
# add 1 key -> B splits -> B + B
assert
S
(
z
)
==
'T/B1,3'
assert
S
(
z
)
==
'T/B1,3'
z
[
5
]
=
X
[
5
]
z
[
5
]
=
X
[
5
]
assert
S
(
z
)
==
'T3/B1-B3,5'
assert
S
(
z
)
==
'T3/B1-B3,5'
b1
,
b35
=
assertT
(
z
,
[
3
],
'B'
,
'B'
)
"""
kind, keys, kids = crack_btree(z)
kind, keys, kids = crack_btree(z)
assert (kind, keys) == (BTREE_NORMAL, [3])
assert (kind, keys) == (BTREE_NORMAL, [3])
b1, b35 = kids
b1, b35 = kids
assert isinstance(b1, LOBucket)
assert isinstance(b1, LOBucket)
assert isinstance(b35, LOBucket)
assert isinstance(b35, LOBucket)
"""
assertB
(
b1
,
1
)
assertB
(
b35
,
3
,
5
)
"""
assert crack_bucket(b1) == ([1], [X[1]])
assert crack_bucket(b1) == ([1], [X[1]])
assert crack_bucket(b35) == ([3,5], [X[3], X[5]])
assert crack_bucket(b35) == ([3,5], [X[3], X[5]])
"""
# -> T2/T-T/B1-B3,5 (add intermediate T-T level)
# -> T2/T-T/B1-B3,5 (add intermediate T-T level)
R
(
z
,
'T2/T-T/B1-B3,5'
)
R
(
z
,
'T2/T-T/B1-B3,5'
)
...
@@ -605,26 +666,42 @@ def test_restructure():
...
@@ -605,26 +666,42 @@ def test_restructure():
# -> T2/T-T/B1-T/B3,5 (add intermediate T level in right arm)
# -> T2/T-T/B1-T/B3,5 (add intermediate T level in right arm)
R
(
z
,
'T2/T-T/B1-T/B3,5'
)
R
(
z
,
'T2/T-T/B1-T/B3,5'
)
assertT
(
z
,
[
2
],
tl
,
tr
)
"""
kind, keys, kids = crack_btree(z)
kind, keys, kids = crack_btree(z)
assert (kind, keys) == (BTREE_NORMAL, [2])
assert (kind, keys) == (BTREE_NORMAL, [2])
assert len(kids) == 2
assert len(kids) == 2
assert kids[0] is tl
assert kids[0] is tl
assert kids[1] is tr
assert kids[1] is tr
"""
assertT
(
tl
,
[],
b1
)
"""
kind, keys, kids = crack_btree(tl) # XXX -> assertT ?
kind, keys, kids = crack_btree(tl) # XXX -> assertT ?
assert (kind, keys) == (BTREE_NORMAL, []) #
assert (kind, keys) == (BTREE_NORMAL, []) #
assert len(kids) == 1 #
assert len(kids) == 1 #
assert kids[0] is b1 #
assert kids[0] is b1 #
"""
trr
,
=
assertT
(
tr
,
[],
'T'
)
"""
kind, keys, kids = crack_btree(tr)
kind, keys, kids = crack_btree(tr)
assert (kind, keys) == (BTREE_NORMAL, [])
assert (kind, keys) == (BTREE_NORMAL, [])
assert len(kids) == 1
assert len(kids) == 1
trr = kids[0]
trr = kids[0]
"""
assert
isinstance
(
trr
,
XLOTree
)
assert
isinstance
(
trr
,
XLOTree
)
assertT
(
trr
,
[],
b35
)
"""
kind, keys, kids = crack_btree(trr)
kind, keys, kids = crack_btree(trr)
assert (kind, keys) == (BTREE_NORMAL, [])
assert (kind, keys) == (BTREE_NORMAL, [])
assert len(kids) == 1
assert len(kids) == 1
assert kids[0] is b35
assert kids[0] is b35
"""
assertB
(
b1
,
1
)
assertB
(
b35
,
3
,
5
)
"""
assert crack_bucket(b1) == ([1], [X[1]]) # XXX -> assertB ?
assert crack_bucket(b1) == ([1], [X[1]]) # XXX -> assertB ?
assert crack_bucket(b35) == ([3,5], [X[3], X[5]])
assert crack_bucket(b35) == ([3,5], [X[3], X[5]])
"""
...
@@ -689,15 +766,9 @@ def test_zwalkBFS():
...
@@ -689,15 +766,9 @@ def test_zwalkBFS():
zroot
[
'x'
]
=
zt
zroot
[
'x'
]
=
zt
transaction
.
commit
()
transaction
.
commit
()
# assertT asserts that znode is tree + has specified keys and children
def
assertT
(
znode
,
keyv
,
*
children
):
def
assertT
(
znode
,
keyv
,
*
children
):
assert
isinstance
(
znode
,
IITreeSet
)
assert
isinstance
(
znode
,
IITreeSet
)
kind
,
keys
,
kids
=
zbcheck
.
crack_btree
(
znode
,
False
)
return
globals
()[
'assertT'
](
znode
,
keyv
,
*
children
)
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
# assertB asserts that znode is bucket + has specified keys
def
assertB
(
znode
,
*
keyv
):
def
assertB
(
znode
,
*
keyv
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment