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
1b50c3ea
Commit
1b50c3ea
authored
Dec 10, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid 'has_key' usage; test it only under Python2.
parent
b126c076
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
12 deletions
+27
-12
BTrees/_compat.py
BTrees/_compat.py
+6
-0
BTrees/tests/common.py
BTrees/tests/common.py
+19
-10
BTrees/tests/testBTreesUnicode.py
BTrees/tests/testBTreesUnicode.py
+1
-1
BTrees/tests/testConflict.py
BTrees/tests/testConflict.py
+1
-1
No files found.
BTrees/_compat.py
View file @
1b50c3ea
...
...
@@ -15,6 +15,9 @@ import sys
if
sys
.
version_info
[
0
]
<
3
:
#pragma NO COVER Python2
PY2
=
True
PY3
=
False
from
StringIO
import
StringIO
BytesIO
=
StringIO
...
...
@@ -29,6 +32,9 @@ if sys.version_info[0] < 3: #pragma NO COVER Python2
else
:
#pragma NO COVER Python3
PY2
=
False
PY3
=
True
from
io
import
StringIO
from
io
import
BytesIO
...
...
BTrees/tests/common.py
View file @
1b50c3ea
...
...
@@ -251,9 +251,11 @@ class MappingBase(Base):
self
.
assertEqual
(
len
(
t
)
,
len
(
addl
),
len
(
t
))
def
testHasKeyWorks
(
self
):
from
.._compat
import
PY2
t
=
self
.
_makeOne
()
t
[
1
]
=
1
self
.
assert_
(
t
.
has_key
(
1
))
if
PY2
:
self
.
assert_
(
t
.
has_key
(
1
))
self
.
assert_
(
1
in
t
)
self
.
assert_
(
0
not
in
t
)
self
.
assert_
(
2
not
in
t
)
...
...
@@ -830,7 +832,7 @@ class BTreeTests(MappingBase):
r
=
range
(
100
)
for
x
in
r
:
k
=
random
.
choice
(
r
)
if
not
added
.
has_key
(
k
)
:
if
k
not
in
added
:
t
[
k
]
=
x
added
[
k
]
=
1
addl
=
sorted
(
added
.
keys
())
...
...
@@ -864,15 +866,15 @@ class BTreeTests(MappingBase):
deleted
=
[]
for
x
in
r
:
k
=
random
.
choice
(
r
)
if
t
.
has_key
(
k
)
:
if
k
in
t
:
self
.
assert_
(
k
in
t
)
del
t
[
k
]
deleted
.
append
(
k
)
if
t
.
has_key
(
k
)
:
if
k
in
t
:
self
.
fail
(
"had problems deleting %s"
%
k
)
badones
=
[]
for
x
in
deleted
:
if
t
.
has_key
(
x
)
:
if
x
in
t
:
badones
.
append
(
x
)
self
.
assertEqual
(
badones
,
[],
(
badones
,
added
,
deleted
))
self
.
_checkIt
(
t
)
...
...
@@ -959,9 +961,10 @@ class BTreeTests(MappingBase):
for
x
in
add_order
:
t
[
x
]
=
1
for
x
in
delete_order
:
try
:
del
t
[
x
]
try
:
del
t
[
x
]
except
KeyError
:
if
t
.
has_key
(
x
)
:
if
x
in
t
:
self
.
assertEqual
(
1
,
2
,
"failed to delete %s"
%
x
)
self
.
_checkIt
(
t
)
...
...
@@ -1073,19 +1076,23 @@ class NormalSetTests(Base):
self
.
assertEqual
(
t
.
add
(
5
)
,
0
)
def
testInsert
(
self
):
from
.._compat
import
PY2
t
=
self
.
_makeOne
()
t
.
insert
(
1
)
self
.
assert_
(
t
.
has_key
(
1
))
if
PY2
:
self
.
assert_
(
t
.
has_key
(
1
))
self
.
assert_
(
1
in
t
)
self
.
assert_
(
2
not
in
t
)
def
testBigInsert
(
self
):
from
.._compat
import
PY2
t
=
self
.
_makeOne
()
r
=
xrange
(
10000
)
for
x
in
r
:
t
.
insert
(
x
)
for
x
in
r
:
self
.
assert_
(
t
.
has_key
(
x
))
if
PY2
:
self
.
assert_
(
t
.
has_key
(
x
))
self
.
assert_
(
x
in
t
)
def
testRemoveSucceeds
(
self
):
...
...
@@ -1101,8 +1108,10 @@ class NormalSetTests(Base):
self
.
_makeOne
().
remove
(
1
)
def
testHasKeyFails
(
self
):
from
.._compat
import
PY2
t
=
self
.
_makeOne
()
self
.
assert_
(
not
t
.
has_key
(
1
))
if
PY2
:
self
.
assert_
(
not
t
.
has_key
(
1
))
self
.
assert_
(
1
not
in
t
)
def
testKeys
(
self
):
...
...
BTrees/tests/testBTreesUnicode.py
View file @
1b50c3ea
...
...
@@ -52,7 +52,7 @@ class TestBTreesUnicode(unittest.TestCase):
for
k
,
v
in
self
.
data
:
if
isinstance
(
k
,
str
):
k
=
unicode
(
k
,
encoding
)
self
.
assert
_
(
self
.
tree
.
has_key
(
k
)
)
self
.
assert
True
(
k
in
self
.
tree
)
self
.
assertEqual
(
self
.
tree
[
k
],
v
)
@
_skip_under_Py3k
...
...
BTrees/tests/testConflict.py
View file @
1b50c3ea
...
...
@@ -136,7 +136,7 @@ class NastyConfictFunctionalTests(ConflictTestBase, unittest.TestCase):
numtoadd
=
16
candidate
=
60
while
numtoadd
:
if
not
b
.
has_key
(
candidate
)
:
if
candidate
not
in
b
:
b
[
candidate
]
=
candidate
numtoadd
-=
1
candidate
+=
1
...
...
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