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
05c4be46
Commit
05c4be46
authored
Nov 12, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moar _p_resolveConflict coverage.
parent
d38b1e56
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
6 deletions
+60
-6
BTrees/_base.py
BTrees/_base.py
+1
-1
BTrees/tests/test__base.py
BTrees/tests/test__base.py
+59
-5
No files found.
BTrees/_base.py
View file @
05c4be46
...
@@ -145,7 +145,7 @@ class _BucketBase(_Base):
...
@@ -145,7 +145,7 @@ class _BucketBase(_Base):
has_key
=
__contains__
has_key
=
__contains__
def
_p_resolveConflict
(
self
,
*
states
):
def
_p_resolveConflict
(
self
,
*
states
):
is_set
=
getattr
(
self
,
'_values'
,
None
)
is
None
is_set
=
getattr
(
self
,
'_values'
,
self
)
is
self
buckets
=
[]
buckets
=
[]
for
state
in
states
:
for
state
in
states
:
...
...
BTrees/tests/test__base.py
View file @
05c4be46
...
@@ -362,15 +362,29 @@ class Test_BucketBase(unittest.TestCase):
...
@@ -362,15 +362,29 @@ class Test_BucketBase(unittest.TestCase):
for
key
in
KEYS
:
for
key
in
KEYS
:
self
.
assertTrue
(
key
in
bucket
)
self
.
assertTrue
(
key
in
bucket
)
def
_with_setstate
(
self
):
def
_with_setstate
_set
(
self
):
class
_WithSetState
(
self
.
_getTargetClass
()):
class
_WithSetState
(
self
.
_getTargetClass
()):
def
__setstate__
(
self
,
state
):
def
__setstate__
(
self
,
state
):
self
.
_keys
,
self
.
_next
=
state
self
.
_keys
,
self
.
_next
=
state
return
_WithSetState
()
return
_WithSetState
()
def
_with_setstate_bucket
(
self
):
class
_WithSetState
(
self
.
_getTargetClass
()):
_values
=
None
def
__setstate__
(
self
,
state
):
state
,
self
.
_next
=
state
self
.
_keys
=
[]
self
.
_values
=
[]
for
i
in
range
(
len
(
state
)
//
2
):
self
.
_keys
.
append
(
state
[
i
])
self
.
_values
.
append
(
state
[
i
+
1
])
def
iteritems
(
self
):
return
iter
(
zip
(
self
.
_keys
,
self
.
_values
))
return
_WithSetState
()
def
test__p_resolveConflict_new_next
(
self
):
def
test__p_resolveConflict_new_next
(
self
):
from
..Interfaces
import
BTreesConflictError
from
..Interfaces
import
BTreesConflictError
bucket
=
self
.
_with_setstate
()
bucket
=
self
.
_with_setstate
_set
()
N_NEW
=
object
()
N_NEW
=
object
()
s_old
=
([],
None
)
s_old
=
([],
None
)
s_com
=
([],
N_NEW
)
s_com
=
([],
N_NEW
)
...
@@ -381,7 +395,7 @@ class Test_BucketBase(unittest.TestCase):
...
@@ -381,7 +395,7 @@ class Test_BucketBase(unittest.TestCase):
def
test__p_resolveConflict_committed_next
(
self
):
def
test__p_resolveConflict_committed_next
(
self
):
from
..Interfaces
import
BTreesConflictError
from
..Interfaces
import
BTreesConflictError
bucket
=
self
.
_with_setstate
()
bucket
=
self
.
_with_setstate
_set
()
N_NEW
=
object
()
N_NEW
=
object
()
s_old
=
([],
None
)
s_old
=
([],
None
)
s_com
=
([],
None
)
s_com
=
([],
None
)
...
@@ -392,7 +406,7 @@ class Test_BucketBase(unittest.TestCase):
...
@@ -392,7 +406,7 @@ class Test_BucketBase(unittest.TestCase):
def
test__p_resolveConflict_empty_committed
(
self
):
def
test__p_resolveConflict_empty_committed
(
self
):
from
..Interfaces
import
BTreesConflictError
from
..Interfaces
import
BTreesConflictError
bucket
=
self
.
_with_setstate
()
bucket
=
self
.
_with_setstate
_set
()
s_old
=
([],
None
)
s_old
=
([],
None
)
s_com
=
([],
None
)
s_com
=
([],
None
)
s_new
=
([
'a'
],
None
)
s_new
=
([
'a'
],
None
)
...
@@ -402,7 +416,7 @@ class Test_BucketBase(unittest.TestCase):
...
@@ -402,7 +416,7 @@ class Test_BucketBase(unittest.TestCase):
def
test__p_resolveConflict_empty_new
(
self
):
def
test__p_resolveConflict_empty_new
(
self
):
from
..Interfaces
import
BTreesConflictError
from
..Interfaces
import
BTreesConflictError
bucket
=
self
.
_with_setstate
()
bucket
=
self
.
_with_setstate
_set
()
s_old
=
([],
None
)
s_old
=
([],
None
)
s_com
=
([
'a'
],
None
)
s_com
=
([
'a'
],
None
)
s_new
=
([],
None
)
s_new
=
([],
None
)
...
@@ -410,6 +424,46 @@ class Test_BucketBase(unittest.TestCase):
...
@@ -410,6 +424,46 @@ class Test_BucketBase(unittest.TestCase):
bucket
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
bucket
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
self
.
assertEqual
(
e
.
reason
,
12
)
self
.
assertEqual
(
e
.
reason
,
12
)
def
test__p_resolveConflict_delete_first_new_set
(
self
):
from
..Interfaces
import
BTreesConflictError
bucket
=
self
.
_with_setstate_set
()
s_old
=
([
'a'
,
'b'
],
None
)
s_com
=
([
'a'
,
'b'
,
'c'
],
None
)
s_new
=
([
'b'
],
None
)
e
=
self
.
assertRaises
(
BTreesConflictError
,
bucket
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
self
.
assertEqual
(
e
.
reason
,
13
)
def
test__p_resolveConflict_delete_first_new_bucket
(
self
):
from
..Interfaces
import
BTreesConflictError
bucket
=
self
.
_with_setstate_bucket
()
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
)
self
.
assertEqual
(
e
.
reason
,
2
)
def
test__p_resolveConflict_delete_first_committed_set
(
self
):
from
..Interfaces
import
BTreesConflictError
bucket
=
self
.
_with_setstate_set
()
s_old
=
([
'a'
,
'b'
],
None
)
s_com
=
([
'b'
],
None
)
s_new
=
([
'a'
,
'b'
,
'c'
],
None
)
e
=
self
.
assertRaises
(
BTreesConflictError
,
bucket
.
_p_resolveConflict
,
s_old
,
s_com
,
s_new
)
self
.
assertEqual
(
e
.
reason
,
13
)
def
test__p_resolveConflict_delete_first_committed_bucket
(
self
):
from
..Interfaces
import
BTreesConflictError
bucket
=
self
.
_with_setstate_bucket
()
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
)
self
.
assertEqual
(
e
.
reason
,
3
)
def
test_suite
():
def
test_suite
():
return
unittest
.
TestSuite
((
return
unittest
.
TestSuite
((
...
...
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