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
78a1b0d1
Commit
78a1b0d1
authored
Nov 11, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid module-scope imports, test case attrs.
parent
f5db3d59
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
35 deletions
+42
-35
BTrees/tests/test_check.py
BTrees/tests/test_check.py
+42
-35
No files found.
BTrees/tests/test_check.py
View file @
78a1b0d1
...
...
@@ -15,61 +15,68 @@
import
unittest
from
BTrees.OOBTree
import
OOBTree
from
BTrees.check
import
check
class
CheckTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
t
=
t
=
OOBTree
()
def
_makeOne
(
self
):
from
BTrees.OOBTree
import
OOBTree
tree
=
OOBTree
()
for
i
in
range
(
31
):
t
[
i
]
=
2
*
i
self
.
state
=
t
.
__getstate__
()
t
ree
[
i
]
=
2
*
i
return
tree
def
testNormal
(
self
):
s
=
self
.
state
# Looks like (state, first_bucket)
# where state looks like (bucket0, 15, bucket1).
self
.
assertEqual
(
len
(
s
),
2
)
self
.
assertEqual
(
len
(
s
[
0
]),
3
)
self
.
assertEqual
(
s
[
0
][
1
],
15
)
self
.
t
.
_check
()
# shouldn't blow up
check
(
self
.
t
)
# shouldn't blow up
from
BTrees.check
import
check
tree
=
self
.
_makeOne
()
state
=
tree
.
__getstate__
()
self
.
assertEqual
(
len
(
state
),
2
)
self
.
assertEqual
(
len
(
state
[
0
]),
3
)
self
.
assertEqual
(
state
[
0
][
1
],
15
)
tree
.
_check
()
# shouldn't blow up
check
(
tree
)
# shouldn't blow up
def
testKeyTooLarge
(
self
):
# Damage an invariant by dropping the BTree key to 14.
s
=
self
.
state
news
=
(
s
[
0
][
0
],
14
,
s
[
0
][
2
]),
s
[
1
]
self
.
t
.
__setstate__
(
news
)
self
.
t
.
_check
()
# not caught
from
BTrees.check
import
check
tree
=
self
.
_makeOne
()
state
=
tree
.
__getstate__
()
news
=
(
state
[
0
][
0
],
14
,
state
[
0
][
2
]),
state
[
1
]
tree
.
__setstate__
(
news
)
tree
.
_check
()
# not caught
try
:
# Expecting "... key %r >= upper bound %r at index %d"
check
(
self
.
t
)
except
AssertionError
,
detail
:
self
.
failUnless
(
str
(
detail
).
find
(
">= upper bound"
)
>
0
)
check
(
tree
)
except
AssertionError
as
detail
:
self
.
assertTrue
(
">= upper bound"
in
str
(
detail
)
)
else
:
self
.
fail
(
"expected
self.t_check(
) to catch the problem"
)
self
.
fail
(
"expected
check(tree
) to catch the problem"
)
def
testKeyTooSmall
(
self
):
# Damage an invariant by bumping the BTree key to 16.
s
=
self
.
state
news
=
(
s
[
0
][
0
],
16
,
s
[
0
][
2
]),
s
[
1
]
self
.
t
.
__setstate__
(
news
)
self
.
t
.
_check
()
# not caught
from
BTrees.check
import
check
tree
=
self
.
_makeOne
()
state
=
tree
.
__getstate__
()
news
=
(
state
[
0
][
0
],
16
,
state
[
0
][
2
]),
state
[
1
]
tree
.
__setstate__
(
news
)
tree
.
_check
()
# not caught
try
:
# Expecting "... key %r < lower bound %r at index %d"
check
(
self
.
t
)
except
AssertionError
,
detail
:
self
.
failUnless
(
str
(
detail
).
find
(
"< lower bound"
)
>
0
)
check
(
tree
)
except
AssertionError
as
detail
:
self
.
assertTrue
(
"< lower bound"
in
str
(
detail
)
)
else
:
self
.
fail
(
"expected
self.t_check(
) to catch the problem"
)
self
.
fail
(
"expected
check(tree
) to catch the problem"
)
def
testKeysSwapped
(
self
):
# Damage an invariant by swapping two key/value pairs.
s
=
self
.
state
from
BTrees.check
import
check
tree
=
self
.
_makeOne
()
state
=
tree
.
__getstate__
()
# Looks like (state, first_bucket)
# where state looks like (bucket0, 15, bucket1).
(
b0
,
num
,
b1
),
firstbucket
=
s
(
b0
,
num
,
b1
),
firstbucket
=
s
tate
self
.
assertEqual
(
b0
[
4
],
8
)
self
.
assertEqual
(
b0
[
5
],
10
)
b0state
=
b0
.
__getstate__
()
...
...
@@ -83,14 +90,14 @@ class CheckTest(unittest.TestCase):
self
.
assertEqual
(
pairs
[
11
],
10
)
newpairs
=
pairs
[:
8
]
+
(
5
,
10
,
4
,
8
)
+
pairs
[
12
:]
b0
.
__setstate__
((
newpairs
,
nextbucket
))
self
.
t
.
_check
()
# not caught
tree
.
_check
()
# not caught
try
:
check
(
self
.
t
)
check
(
tree
)
except
AssertionError
,
detail
:
self
.
failUnless
(
str
(
detail
).
find
(
"key 5 at index 4 >= key 4 at index 5"
)
>
0
)
self
.
assertTrue
(
"key 5 at index 4 >= key 4 at index 5"
in
str
(
detail
)
)
else
:
self
.
fail
(
"expected
self.t_check(
) to catch the problem"
)
self
.
fail
(
"expected
check(tree
) to catch the problem"
)
def
test_suite
():
return
unittest
.
makeSuite
(
CheckTest
)
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