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
7731e76a
Commit
7731e76a
authored
May 29, 2015
by
Tres Seaver
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14 from NextThought/bucket-repr
Human-readable __repr__ for pure-Python Bucket and Set objects.
parents
85cc5d79
f89a3552
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
1 deletion
+41
-1
BTrees/_base.py
BTrees/_base.py
+14
-0
BTrees/tests/common.py
BTrees/tests/common.py
+25
-0
CHANGES.rst
CHANGES.rst
+2
-1
No files found.
BTrees/_base.py
View file @
7731e76a
...
...
@@ -155,6 +155,12 @@ class _BucketBase(_Base):
has_key
=
__contains__
def
_repr_helper
(
self
,
items
):
type_self
=
type
(
self
)
mod
=
type_self
.
__module__
name
=
type_self
.
__name__
name
=
name
[:
-
2
]
if
name
.
endswith
(
"Py"
)
else
name
return
"%s.%s(%r)"
%
(
mod
,
name
,
items
)
class
_SetIteration
(
object
):
...
...
@@ -517,6 +523,8 @@ class Bucket(_BucketBase):
result
.
_next
=
b_old
.
_next
return
result
.
__getstate__
()
def
__repr__
(
self
):
return
self
.
_repr_helper
(
self
.
items
())
class
Set
(
_BucketBase
):
...
...
@@ -711,6 +719,8 @@ class Set(_BucketBase):
result
.
_next
=
b_old
.
_next
return
result
.
__getstate__
()
def
__repr__
(
self
):
return
self
.
_repr_helper
(
self
.
_keys
)
class
_TreeItem
(
object
):
...
...
@@ -1066,6 +1076,10 @@ class _Tree(_Base):
return
((
self
.
_bucket_type
().
_p_resolveConflict
(
s_old
,
s_com
,
s_new
),
),
)
def
__repr__
(
self
):
r
=
super
(
_Tree
,
self
).
__repr__
()
r
=
r
.
replace
(
'Py'
,
''
)
return
r
def
_get_simple_btree_bucket_state
(
state
):
if
state
is
None
:
...
...
BTrees/tests/common.py
View file @
7731e76a
...
...
@@ -228,6 +228,14 @@ class MappingBase(Base):
# Make sure the repr is **not* 10000 bytes long for a shrort bucket.
# (the buffer must be terminated when copied).
self
.
assertTrue
(
len
(
r
)
<
10000
)
# Make sure the repr is human readable if it's a bucket
if
'Bucket'
in
r
:
self
.
assertTrue
(
r
.
startswith
(
"BTrees"
))
self
.
assertTrue
(
r
.
endswith
(
repr
(
t
.
items
())
+
')'
),
r
)
else
:
self
.
assertEqual
(
r
[:
8
],
'<BTrees.'
)
# Make sure it's the same between Python and C
self
.
assertTrue
(
'Py'
not
in
r
)
def
testRepr
(
self
):
# test the repr because buckets have a complex repr implementation
...
...
@@ -1187,6 +1195,23 @@ class NormalSetTests(Base):
# Make some data
t
.
update
(
range
(
l
))
def
testShortRepr
(
self
):
t
=
self
.
_makeOne
()
for
i
in
range
(
5
):
t
.
add
(
i
)
r
=
repr
(
t
)
# Make sure the repr is **not* 10000 bytes long for a shrort bucket.
# (the buffer must be terminated when copied).
self
.
assertTrue
(
len
(
r
)
<
10000
)
# Make sure the repr is human readable, unless it's a tree
if
'TreeSet'
not
in
r
:
self
.
assertTrue
(
r
.
endswith
(
"Set(%r)"
%
t
.
keys
()))
else
:
self
.
assertEqual
(
r
[:
7
],
'<BTrees'
,
r
)
# Make sure it's the same between Python and C
self
.
assertTrue
(
'Py'
not
in
r
)
def
testInsertReturnsValue
(
self
):
t
=
self
.
_makeOne
()
self
.
assertEqual
(
t
.
insert
(
5
)
,
1
)
...
...
CHANGES.rst
View file @
7731e76a
...
...
@@ -4,7 +4,8 @@
4.1.4 (unreleased)
------------------
- TBD
- Ensure that pure-Python Bucket and Set objects have a human readable
``__repr__`` like the C versions.
4.1.3 (2015-05-19)
------------------
...
...
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