Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BTrees
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
BTrees
Commits
ef4eea82
Commit
ef4eea82
authored
Nov 14, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixin' to expand coverage for _p_resolveConflict.
parent
d66be83a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
79 deletions
+119
-79
BTrees/_base.py
BTrees/_base.py
+51
-50
BTrees/tests/test__base.py
BTrees/tests/test__base.py
+68
-29
No files found.
BTrees/_base.py
View file @
ef4eea82
...
...
@@ -200,6 +200,7 @@ class _SetBase(_Base):
add
(
i
)
def
_p_resolveConflict
(
self
,
s_old
,
s_com
,
s_new
):
b_old
=
self
.
__class__
()
if
s_old
is
not
None
:
b_old
.
__setstate__
(
s_old
)
...
...
@@ -209,11 +210,12 @@ class _SetBase(_Base):
b_new
=
self
.
__class__
()
if
s_new
is
not
None
:
b_new
.
__setstate__
(
s_new
)
if
(
b_com
.
_next
!=
b_old
.
_next
or
b_new
.
_next
!=
b_old
.
_next
):
b_new
.
_next
!=
b_old
.
_next
):
# conflict: com or new changed _next
raise
BTreesConflictError
(
-
1
,
-
1
,
-
1
,
0
)
if
not
b_com
or
not
b_new
:
if
not
b_com
or
not
b_new
:
# conflict: com or new empty
raise
BTreesConflictError
(
-
1
,
-
1
,
-
1
,
12
)
i_old
=
_SetIteration
(
b_old
,
True
)
...
...
@@ -231,15 +233,14 @@ class _SetBase(_Base):
it
.
advance
()
while
i_old
.
active
and
i_com
.
active
and
i_new
.
active
:
cmp12
=
cmp
(
i_old
.
key
,
i_com
.
key
)
cmp13
=
cmp
(
i_old
.
key
,
i_new
.
key
)
if
cmp12
==
0
:
if
cmp13
==
0
:
result
.
add
(
i_old
.
key
)
i_old
.
advance
()
cmpOC
=
cmp
(
i_old
.
key
,
i_com
.
key
)
cmpON
=
cmp
(
i_old
.
key
,
i_new
.
key
)
if
cmpOC
==
0
:
if
cmpON
==
0
:
# all match
merge_output
(
i_old
)
i_com
.
advance
()
i_new
.
advance
()
elif
cmp
13
>
0
:
# insert in new
elif
cmp
ON
>
0
:
# insert in new
merge_output
(
i_new
)
else
:
# deleted new
if
i_new
.
position
==
1
:
...
...
@@ -249,8 +250,8 @@ class _SetBase(_Base):
raise
merge_error
(
13
)
i_old
.
advance
()
i_com
.
advance
()
elif
cmp
13
==
0
:
if
cmp
12
>
0
:
# insert committed
elif
cmp
ON
==
0
:
if
cmp
OC
>
0
:
# insert committed
merge_output
(
i_com
)
else
:
# delete committed
if
i_com
.
position
==
1
:
...
...
@@ -260,34 +261,34 @@ class _SetBase(_Base):
raise
merge_error
(
13
)
i_old
.
advance
()
i_new
.
advance
()
else
:
# both keys changed
cmp
23
=
cmp
(
i_com
.
key
,
i_new
.
key
)
if
cmp
23
==
0
:
else
:
# both
com and new
keys changed
cmp
CN
=
cmp
(
i_com
.
key
,
i_new
.
key
)
if
cmp
CN
==
0
:
# both inserted same key
raise
merge_error
(
4
)
if
cmp
12
>
0
:
# insert committed
if
cmp
23
>
0
:
# insert i_new first
if
cmp
OC
>
0
:
# insert committed
if
cmp
CN
>
0
:
# insert i_new first
merge_output
(
i_new
)
else
:
merge_output
(
i_com
)
elif
cmp
13
>
0
:
# insert i_new
elif
cmp
ON
>
0
:
# insert i_new
merge_output
(
i_new
)
else
:
raise
merge_error
(
5
)
# both deleted same key
else
:
# both com and new deleted same key
raise
merge_error
(
5
)
while
i_com
.
active
and
i_new
.
active
:
# new inserts
cmp
23
=
cmp
(
i_com
.
key
,
i_new
.
key
)
if
cmp
23
==
0
:
raise
merge_error
(
6
)
# dueling insert
if
cmp
23
>
0
:
# insert new
cmp
CN
=
cmp
(
i_com
.
key
,
i_new
.
key
)
if
cmp
CN
==
0
:
# dueling insert
raise
merge_error
(
6
)
if
cmp
CN
>
0
:
# insert new
merge_output
(
i_new
)
else
:
# insert committed
merge_output
(
i_com
)
while
i_old
.
active
and
i_com
.
active
:
# new deletes rest of original
cmp
12
=
cmp
(
i_old
.
key
,
i_com
.
key
)
if
cmp
12
>
0
:
# insert committed
cmp
OC
=
cmp
(
i_old
.
key
,
i_com
.
key
)
if
cmp
OC
>
0
:
# insert committed
merge_output
(
i_com
)
elif
cmp
12
==
0
:
# del in new
elif
cmp
OC
==
0
:
# del in new
i_old
.
advance
()
i_com
.
advance
()
else
:
# dueling deletes or delete and change
...
...
@@ -295,10 +296,10 @@ class _SetBase(_Base):
while
i_old
.
active
and
i_new
.
active
:
# committed deletes rest of original
cmp
13
=
cmp
(
i_old
.
key
,
i_new
.
key
)
if
cmp
13
>
0
:
# insert new
cmp
ON
=
cmp
(
i_old
.
key
,
i_new
.
key
)
if
cmp
ON
>
0
:
# insert new
merge_output
(
i_new
)
elif
cmp
13
==
0
:
# deleted in committed
elif
cmp
ON
==
0
:
# deleted in committed
i_old
.
advance
()
i_new
.
advance
()
else
:
# dueling deletes or delete and change
...
...
@@ -388,10 +389,10 @@ class _MappingBase(_Base):
it
.
advance
()
while
i_old
.
active
and
i_com
.
active
and
i_new
.
active
:
cmp
12
=
cmp
(
i_old
.
key
,
i_com
.
key
)
cmp
13
=
cmp
(
i_old
.
key
,
i_new
.
key
)
if
cmp
12
==
0
:
if
cmp
13
==
0
:
cmp
OC
=
cmp
(
i_old
.
key
,
i_com
.
key
)
cmp
ON
=
cmp
(
i_old
.
key
,
i_new
.
key
)
if
cmp
OC
==
0
:
if
cmp
ON
==
0
:
if
i_com
.
value
==
i_old
.
value
:
result
[
i_old
.
key
]
=
i_new
.
value
elif
i_new
.
value
==
i_old
.
value
:
...
...
@@ -401,7 +402,7 @@ class _MappingBase(_Base):
i_old
.
advance
()
i_com
.
advance
()
i_new
.
advance
()
elif
(
cmp
13
>
0
):
# insert in new
elif
(
cmp
ON
>
0
):
# insert in new
merge_output
(
i_new
)
elif
i_old
.
value
==
i_com
.
value
:
# deleted new
if
i_new
.
position
==
1
:
...
...
@@ -413,8 +414,8 @@ class _MappingBase(_Base):
i_com
.
advance
()
else
:
raise
merge_error
(
2
)
elif
cmp
13
==
0
:
if
cmp
12
>
0
:
# insert committed
elif
cmp
ON
==
0
:
if
cmp
OC
>
0
:
# insert committed
merge_output
(
i_com
)
elif
i_old
.
value
==
i_new
.
value
:
# delete committed
if
i_com
.
position
==
1
:
...
...
@@ -427,33 +428,33 @@ class _MappingBase(_Base):
else
:
raise
merge_error
(
3
)
else
:
# both keys changed
cmp
23
=
cmp
(
i_com
.
key
,
i_new
.
key
)
if
cmp
23
==
0
:
cmp
CN
=
cmp
(
i_com
.
key
,
i_new
.
key
)
if
cmp
CN
==
0
:
raise
merge_error
(
4
)
if
cmp
12
>
0
:
# insert committed
if
cmp
23
>
0
:
# insert i_new first
if
cmp
OC
>
0
:
# insert committed
if
cmp
CN
>
0
:
# insert i_new first
merge_output
(
i_new
)
else
:
merge_output
(
i_com
)
elif
cmp
13
>
0
:
# insert i_new
elif
cmp
ON
>
0
:
# insert i_new
merge_output
(
i_new
)
else
:
raise
merge_error
(
5
)
# both deleted same key
while
i_com
.
active
and
i_new
.
active
:
# new inserts
cmp
23
=
cmp
(
i_com
.
key
,
i_new
.
key
)
if
cmp
23
==
0
:
cmp
CN
=
cmp
(
i_com
.
key
,
i_new
.
key
)
if
cmp
CN
==
0
:
raise
merge_error
(
6
)
# dueling insert
if
cmp
23
>
0
:
# insert new
if
cmp
CN
>
0
:
# insert new
merge_output
(
i_new
)
else
:
# insert committed
merge_output
(
i_com
)
while
i_old
.
active
and
i_com
.
active
:
# new deletes rest of original
cmp
12
=
cmp
(
i_old
.
key
,
i_com
.
key
)
if
cmp
12
>
0
:
# insert committed
cmp
OC
=
cmp
(
i_old
.
key
,
i_com
.
key
)
if
cmp
OC
>
0
:
# insert committed
merge_output
(
i_com
)
elif
cmp
12
==
0
and
(
i_old
.
value
==
i_com
.
value
):
# del in new
elif
cmp
OC
==
0
and
(
i_old
.
value
==
i_com
.
value
):
# del in new
i_old
.
advance
()
i_com
.
advance
()
else
:
# dueling deletes or delete and change
...
...
@@ -461,10 +462,10 @@ class _MappingBase(_Base):
while
i_old
.
active
and
i_new
.
active
:
# committed deletes rest of original
cmp
13
=
cmp
(
i_old
.
key
,
i_new
.
key
)
if
cmp
13
>
0
:
# insert new
cmp
ON
=
cmp
(
i_old
.
key
,
i_new
.
key
)
if
cmp
ON
>
0
:
# insert new
merge_output
(
i_new
)
elif
cmp
13
==
0
and
(
i_old
.
value
==
i_new
.
value
):
elif
cmp
ON
==
0
and
(
i_old
.
value
==
i_new
.
value
):
# deleted in committed
i_old
.
advance
()
i_new
.
advance
()
...
...
BTrees/tests/test__base.py
View file @
ef4eea82
...
...
@@ -371,6 +371,25 @@ class Test__SetIteration(unittest.TestCase):
from
.._base
import
_SetIteration
return
_SetIteration
def
_makeOne
(
self
,
to_iterate
,
useValues
=
False
,
default
=
None
):
return
self
.
_getTargetClass
()(
to_iterate
,
useValues
,
default
)
def
test_ctor_w_None
(
self
):
si
=
self
.
_makeOne
(
None
)
self
.
assertEqual
(
si
.
useValues
,
False
)
self
.
failIf
(
'key'
in
si
.
__dict__
)
self
.
assertEqual
(
si
.
value
,
None
)
self
.
assertEqual
(
si
.
active
,
False
)
self
.
assertEqual
(
si
.
position
,
-
1
)
def
test_ctor_w_non_empty_list
(
self
):
si
=
self
.
_makeOne
([
'a'
,
'b'
,
'c'
])
self
.
assertEqual
(
si
.
useValues
,
False
)
self
.
assertEqual
(
si
.
key
,
'a'
)
self
.
assertEqual
(
si
.
value
,
None
)
self
.
assertEqual
(
si
.
active
,
True
)
self
.
assertEqual
(
si
.
position
,
1
)
class
Test__SetBase
(
unittest
.
TestCase
):
...
...
@@ -392,68 +411,88 @@ class Test__SetBase(unittest.TestCase):
return
iter
(
self
.
_keys
)
return
_TestSet
()
def
test__p_resolveConflict_
new
_next
(
self
):
def
test__p_resolveConflict_
x_on_com
_next
(
self
):
from
..Interfaces
import
BTreesConflictError
buck
et
=
self
.
_makeOne
()
_s
et
=
self
.
_makeOne
()
N_NEW
=
object
()
s_old
=
([],
None
)
s_com
=
([],
N_NEW
)
s_new
=
([],
None
)
e
=
self
.
assertRaises
(
BTreesConflictError
,
buck
et
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
_s
et
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
self
.
assertEqual
(
e
.
reason
,
0
)
def
test__p_resolveConflict_
committed
_next
(
self
):
def
test__p_resolveConflict_
x_on_new
_next
(
self
):
from
..Interfaces
import
BTreesConflictError
buck
et
=
self
.
_makeOne
()
_s
et
=
self
.
_makeOne
()
N_NEW
=
object
()
s_old
=
([],
None
)
s_com
=
([],
None
)
s_new
=
([],
N_NEW
)
e
=
self
.
assertRaises
(
BTreesConflictError
,
buck
et
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
_s
et
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
self
.
assertEqual
(
e
.
reason
,
0
)
def
test__p_resolveConflict_
empty_committed
(
self
):
def
test__p_resolveConflict_
x_on_com_empty
(
self
):
from
..Interfaces
import
BTreesConflictError
buck
et
=
self
.
_makeOne
()
s_old
=
([],
None
)
_s
et
=
self
.
_makeOne
()
s_old
=
([
'a'
,
'b'
],
None
)
s_com
=
([],
None
)
s_new
=
([
'a'
],
None
)
e
=
self
.
assertRaises
(
BTreesConflictError
,
buck
et
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
_s
et
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
self
.
assertEqual
(
e
.
reason
,
12
)
def
test__p_resolveConflict_
empty_new
(
self
):
def
test__p_resolveConflict_
x_on_new_empty
(
self
):
from
..Interfaces
import
BTreesConflictError
buck
et
=
self
.
_makeOne
()
s_old
=
([],
None
)
_s
et
=
self
.
_makeOne
()
s_old
=
([
'a'
,
'b'
],
None
)
s_com
=
([
'a'
],
None
)
s_new
=
([],
None
)
e
=
self
.
assertRaises
(
BTreesConflictError
,
buck
et
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
_s
et
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
self
.
assertEqual
(
e
.
reason
,
12
)
def
test__p_resolveConflict_
delete_first_new
(
self
):
def
test__p_resolveConflict_
x_on_del_first_com
(
self
):
from
..Interfaces
import
BTreesConflictError
buck
et
=
self
.
_makeOne
()
_s
et
=
self
.
_makeOne
()
s_old
=
([
'a'
,
'b'
],
None
)
s_com
=
([
'
a'
,
'b'
,
'c
'
],
None
)
s_new
=
([
'
b
'
],
None
)
s_com
=
([
'
b
'
],
None
)
s_new
=
([
'
a'
,
'b'
,
'c
'
],
None
)
e
=
self
.
assertRaises
(
BTreesConflictError
,
buck
et
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
_s
et
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
self
.
assertEqual
(
e
.
reason
,
13
)
def
test__p_resolveConflict_
delete_first_committed
(
self
):
def
test__p_resolveConflict_
x_on_del_first_new
(
self
):
from
..Interfaces
import
BTreesConflictError
buck
et
=
self
.
_makeOne
()
s_old
=
([
'a'
,
'b'
],
None
)
s_com
=
([
'
b
'
],
None
)
s_new
=
([
'
a'
,
'b'
,
'c
'
],
None
)
_s
et
=
self
.
_makeOne
()
s_old
=
([
'a'
,
'b'
],
None
)
s_com
=
([
'
a'
,
'b'
,
'c
'
],
None
)
s_new
=
([
'
b
'
],
None
)
e
=
self
.
assertRaises
(
BTreesConflictError
,
buck
et
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
_s
et
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
self
.
assertEqual
(
e
.
reason
,
13
)
def
test__p_resolveConflict_x_on_ins_same_after_del
(
self
):
from
..Interfaces
import
BTreesConflictError
_set
=
self
.
_makeOne
()
s_old
=
([
'a'
,
'b'
],
None
)
s_com
=
([
'a'
,
'c'
],
None
)
s_new
=
([
'a'
,
'c'
,
'd'
],
None
)
e
=
self
.
assertRaises
(
BTreesConflictError
,
_set
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
self
.
assertEqual
(
e
.
reason
,
4
)
def
test__p_resolveConflict_x_on_del_same
(
self
):
from
..Interfaces
import
BTreesConflictError
_set
=
self
.
_makeOne
()
s_old
=
([
'a'
,
'b'
,
'c'
],
None
)
s_com
=
([
'a'
,
'c'
],
None
)
s_new
=
([
'a'
,
'd'
,
'e'
],
None
)
e
=
self
.
assertRaises
(
BTreesConflictError
,
_set
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
self
.
assertEqual
(
e
.
reason
,
5
)
class
Test__MappingBase
(
unittest
.
TestCase
):
...
...
@@ -481,22 +520,22 @@ class Test__MappingBase(unittest.TestCase):
def
test__p_resolveConflict_delete_first_new
(
self
):
from
..Interfaces
import
BTreesConflictError
bucket
=
self
.
_makeOne
()
_mapping
=
self
.
_makeOne
()
s_old
=
([
'a'
,
0
,
'b'
,
1
],
None
)
s_com
=
([
'a'
,
1
,
'b'
,
2
,
'c'
,
3
],
None
)
s_new
=
([
'b'
,
4
],
None
)
e
=
self
.
assertRaises
(
BTreesConflictError
,
bucket
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
_mapping
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
self
.
assertEqual
(
e
.
reason
,
2
)
def
test__p_resolveConflict_delete_first_committed
(
self
):
from
..Interfaces
import
BTreesConflictError
bucket
=
self
.
_makeOne
()
_mapping
=
self
.
_makeOne
()
s_old
=
([
'a'
,
0
,
'b'
,
1
],
None
)
s_com
=
([
'b'
,
4
],
None
)
s_new
=
([
'a'
,
1
,
'b'
,
2
,
'c'
,
3
],
None
)
e
=
self
.
assertRaises
(
BTreesConflictError
,
bucket
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
_mapping
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
self
.
assertEqual
(
e
.
reason
,
3
)
...
...
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