Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Commits
0baf4ba3
Commit
0baf4ba3
authored
8 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Add converters from string for BlockUID
parent
649f49c8
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
duniterpy/documents/__init__.py
+1
-1
1 addition, 1 deletion
duniterpy/documents/__init__.py
duniterpy/documents/block.py
+11
-0
11 additions, 0 deletions
duniterpy/documents/block.py
tests/documents/test_block.py
+14
-1
14 additions, 1 deletion
tests/documents/test_block.py
with
26 additions
and
2 deletions
duniterpy/documents/__init__.py
+
1
−
1
View file @
0baf4ba3
from
.block
import
Block
,
BlockUID
from
.block
import
Block
,
BlockUID
,
block_uid
from
.certification
import
SelfCertification
,
Certification
,
Revocation
from
.membership
import
Membership
from
.peer
import
Endpoint
,
BMAEndpoint
,
UnknownEndpoint
,
Peer
...
...
This diff is collapsed.
Click to expand it.
duniterpy/documents/block.py
+
11
−
0
View file @
0baf4ba3
...
...
@@ -7,6 +7,17 @@ from .constants import pubkey_regex, block_id_regex, block_hash_regex
import
re
def
block_uid
(
value
):
if
isinstance
(
value
,
BlockUID
):
return
value
elif
isinstance
(
value
,
str
):
return
BlockUID
.
from_str
(
value
)
elif
value
is
None
:
return
BlockUID
.
empty
()
else
:
raise
TypeError
(
"
Cannot convert {0} to BlockUID
"
.
format
(
type
(
value
)))
class
BlockUID
:
"""
A simple block id
...
...
This diff is collapsed.
Click to expand it.
tests/documents/test_block.py
+
14
−
1
View file @
0baf4ba3
...
...
@@ -4,7 +4,7 @@ Created on 12 déc. 2014
@author: inso
'''
import
unittest
from
duniterpy.documents.block
import
Block
,
BlockUID
from
duniterpy.documents.block
import
Block
,
BlockUID
,
block_uid
raw_block
=
"""
Version: 2
Type: Block
...
...
@@ -518,6 +518,19 @@ class Test_Block(unittest.TestCase):
from_rendered_raw
=
block
.
from_signed_raw
(
rendered_raw
)
self
.
assertEqual
(
from_rendered_raw
.
signed_raw
(),
negative_issuers_frame_var
)
def
test_block_uid_converter
(
self
):
buid
=
block_uid
(
"
1345-0000338C775613399FA508A8F8B22EB60F525884730639E2A707299E373F43C0
"
)
self
.
assertEqual
(
buid
.
number
,
1345
)
self
.
assertEqual
(
buid
.
sha_hash
,
"
0000338C775613399FA508A8F8B22EB60F525884730639E2A707299E373F43C0
"
)
def
test_block_uid_converter_error
(
self
):
with
self
.
assertRaises
(
TypeError
):
buid
=
block_uid
(
1235654
)
def
test_block_uid_no_convert
(
self
):
buid
=
block_uid
(
BlockUID
(
1345
,
"
0000338C775613399FA508A8F8B22EB60F525884730639E2A707299E373F43C0
"
))
self
.
assertEqual
(
buid
.
number
,
1345
)
self
.
assertEqual
(
buid
.
sha_hash
,
"
0000338C775613399FA508A8F8B22EB60F525884730639E2A707299E373F43C0
"
)
if
__name__
==
'
__main__
'
:
unittest
.
main
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment