Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
beem
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
hive
beem
Commits
29690131
Commit
29690131
authored
6 years ago
by
Holger
Browse files
Options
Downloads
Patches
Plain Diff
Fix unit tests
parent
ecfd2723
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.travis.yml
+10
-10
10 additions, 10 deletions
.travis.yml
beem/utils.py
+31
-28
31 additions, 28 deletions
beem/utils.py
tests/beem/test_cli.py
+2
-2
2 additions, 2 deletions
tests/beem/test_cli.py
tox.ini
+2
-2
2 additions, 2 deletions
tox.ini
with
45 additions
and
42 deletions
.travis.yml
+
10
−
10
View file @
29690131
...
...
@@ -9,10 +9,10 @@ matrix:
# python: 3.6
# env:
# - TOXENV=pylint
-
os
:
linux
python
:
3.6
env
:
-
TOXENV=flake8
#
- os: linux
#
python: 3.6
#
env:
#
- TOXENV=flake8
#- os: linux
# python: 3.6
# env:
...
...
@@ -38,12 +38,12 @@ matrix:
env
:
-
TOXENV=py36short
-
BUILD_LINUX=yes
-
os
:
osx
osx_image
:
xcode9.3
language
:
objective-c
env
:
-
TRAVIS_PYTHON_VERSION=3.6
-
TOXENV=short
#
- os: osx
#
osx_image: xcode9.3
#
language: objective-c
#
env:
#
- TRAVIS_PYTHON_VERSION=3.6
#
- TOXENV=short
cache
:
pip
...
...
This diff is collapsed.
Click to expand it.
beem/utils.py
+
31
−
28
View file @
29690131
...
...
@@ -12,12 +12,12 @@ import pytz
import
difflib
import
yaml
timeFormat
=
'
%Y-%m-%dT%H:%M:%S
'
timeFormat
=
"
%Y-%m-%dT%H:%M:%S
"
# https://github.com/matiasb/python-unidiff/blob/master/unidiff/constants.py#L37
# @@ (source offset, length) (target offset, length) @@ (section header)
RE_HUNK_HEADER
=
re
.
compile
(
r
"
^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))?\ @@[ ]?(.*)$
"
,
flags
=
re
.
MULTILINE
)
r
"
^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))?\ @@[ ]?(.*)$
"
,
flags
=
re
.
MULTILINE
)
def
formatTime
(
t
):
...
...
@@ -29,7 +29,7 @@ def formatTime(t):
return
t
.
strftime
(
"
%Y%m%dt%H%M%S%Z
"
)
def
addTzInfo
(
t
,
timezone
=
'
UTC
'
):
def
addTzInfo
(
t
,
timezone
=
"
UTC
"
):
"""
Returns a datetime object with tzinfo added
"""
if
t
and
isinstance
(
t
,
(
datetime
,
date
,
time
))
and
t
.
tzinfo
is
None
:
utc
=
pytz
.
timezone
(
timezone
)
...
...
@@ -68,8 +68,7 @@ def formatTimeFromNow(secs=0):
:rtype: str
"""
return
datetime
.
utcfromtimestamp
(
timenow
.
time
()
+
int
(
secs
)).
strftime
(
timeFormat
)
return
datetime
.
utcfromtimestamp
(
timenow
.
time
()
+
int
(
secs
)).
strftime
(
timeFormat
)
def
formatTimedelta
(
td
):
...
...
@@ -80,7 +79,7 @@ def formatTimedelta(td):
days
,
seconds
=
td
.
days
,
td
.
seconds
hours
=
days
*
24
+
seconds
//
3600
minutes
=
(
seconds
%
3600
)
//
60
seconds
=
(
seconds
%
60
)
seconds
=
seconds
%
60
return
"
%d:%s:%s
"
%
(
hours
,
str
(
minutes
).
zfill
(
2
),
str
(
seconds
).
zfill
(
2
))
...
...
@@ -88,7 +87,7 @@ def parse_time(block_time):
"""
Take a string representation of time from the blockchain, and parse it
into datetime object.
"""
utc
=
pytz
.
timezone
(
'
UTC
'
)
utc
=
pytz
.
timezone
(
"
UTC
"
)
return
utc
.
localize
(
datetime
.
strptime
(
block_time
,
timeFormat
))
...
...
@@ -98,7 +97,7 @@ def assets_from_string(text):
Splits the string into two assets with the separator being on of the
following: ``:``, ``/``, or ``-``.
"""
return
re
.
split
(
r
'
[\-:/]
'
,
text
)
return
re
.
split
(
r
"
[\-:/]
"
,
text
)
def
sanitize_permlink
(
permlink
):
...
...
@@ -174,15 +173,14 @@ def construct_authorperm(*args):
@username
/
permlink
"""
username_prefix
=
'
@
'
username_prefix
=
"
@
"
if
len
(
args
)
==
1
:
op
=
args
[
0
]
author
,
permlink
=
op
[
'
author
'
],
op
[
'
permlink
'
]
author
,
permlink
=
op
[
"
author
"
],
op
[
"
permlink
"
]
elif
len
(
args
)
==
2
:
author
,
permlink
=
args
else
:
raise
ValueError
(
'
construct_identifier() received unparsable arguments
'
)
raise
ValueError
(
"
construct_identifier() received unparsable arguments
"
)
fields
=
dict
(
prefix
=
username_prefix
,
author
=
author
,
permlink
=
permlink
)
return
"
{prefix}{author}/{permlink}
"
.
format
(
**
fields
)
...
...
@@ -209,7 +207,7 @@ def resolve_authorpermvoter(identifier):
if
pos
<
0
:
raise
ValueError
(
"
Invalid identifier
"
)
[
author
,
permlink
]
=
resolve_authorperm
(
identifier
[:
pos
])
return
author
,
permlink
,
identifier
[
pos
+
1
:]
return
author
,
permlink
,
identifier
[
pos
+
1
:]
def
construct_authorpermvoter
(
*
args
):
...
...
@@ -225,22 +223,21 @@ def construct_authorpermvoter(*args):
@username
/
permlink
|
voter
"""
username_prefix
=
'
@
'
username_prefix
=
"
@
"
if
len
(
args
)
==
1
:
op
=
args
[
0
]
if
"
authorperm
"
in
op
:
authorperm
,
voter
=
op
[
'
authorperm
'
],
op
[
'
voter
'
]
authorperm
,
voter
=
op
[
"
authorperm
"
],
op
[
"
voter
"
]
[
author
,
permlink
]
=
resolve_authorperm
(
authorperm
)
else
:
author
,
permlink
,
voter
=
op
[
'
author
'
],
op
[
'
permlink
'
],
op
[
'
voter
'
]
author
,
permlink
,
voter
=
op
[
"
author
"
],
op
[
"
permlink
"
],
op
[
"
voter
"
]
elif
len
(
args
)
==
2
:
authorperm
,
voter
=
args
[
author
,
permlink
]
=
resolve_authorperm
(
authorperm
)
elif
len
(
args
)
==
3
:
author
,
permlink
,
voter
=
args
else
:
raise
ValueError
(
'
construct_identifier() received unparsable arguments
'
)
raise
ValueError
(
"
construct_identifier() received unparsable arguments
"
)
fields
=
dict
(
prefix
=
username_prefix
,
author
=
author
,
permlink
=
permlink
,
voter
=
voter
)
return
"
{prefix}{author}/{permlink}|{voter}
"
.
format
(
**
fields
)
...
...
@@ -251,11 +248,11 @@ def reputation_to_score(rep):
if
isinstance
(
rep
,
str
):
rep
=
int
(
rep
)
if
rep
==
0
:
return
25.
return
25.
0
score
=
max
([
math
.
log10
(
abs
(
rep
))
-
9
,
0
])
if
rep
<
0
:
score
*=
-
1
score
=
(
score
*
9.
)
+
25.
score
=
(
score
*
9.
0
)
+
25.
0
return
score
...
...
@@ -277,14 +274,14 @@ def remove_from_dict(obj, keys=list(), keep_keys=True):
def
make_patch
(
a
,
b
,
n
=
3
):
# _no_eol = '\n' + "\ No newline at end of file" + '\n'
_no_eol
=
'
\n
'
_no_eol
=
"
\n
"
diffs
=
difflib
.
unified_diff
(
a
.
splitlines
(
True
),
b
.
splitlines
(
True
),
n
=
n
)
try
:
_
,
_
=
next
(
diffs
),
next
(
diffs
)
del
_
except
StopIteration
:
pass
return
''
.
join
([
d
if
d
[
-
1
]
==
'
\n
'
else
d
+
_no_eol
for
d
in
diffs
])
return
""
.
join
([
d
if
d
[
-
1
]
==
"
\n
"
else
d
+
_no_eol
for
d
in
diffs
])
def
findall_patch_hunks
(
body
=
None
):
...
...
@@ -312,7 +309,9 @@ def derive_beneficiaries(beneficiaries):
percentage
=
percentage
.
strip
().
split
(
"
%
"
)[
0
].
strip
()
percentage
=
float
(
percentage
)
beneficiaries_sum
+=
percentage
beneficiaries_list
.
append
({
"
account
"
:
account_name
,
"
weight
"
:
int
(
percentage
*
100
)})
beneficiaries_list
.
append
(
{
"
account
"
:
account_name
,
"
weight
"
:
int
(
percentage
*
100
)}
)
beneficiaries_accounts
.
append
(
account_name
)
missing
=
0
...
...
@@ -322,9 +321,13 @@ def derive_beneficiaries(beneficiaries):
index
=
0
for
bene
in
beneficiaries_list
:
if
bene
[
"
weight
"
]
<
0
:
beneficiaries_list
[
index
][
"
weight
"
]
=
int
((
int
(
100
*
100
)
-
int
(
beneficiaries_sum
*
100
))
/
missing
)
beneficiaries_list
[
index
][
"
weight
"
]
=
int
(
(
int
(
100
*
100
)
-
int
(
beneficiaries_sum
*
100
))
/
missing
)
index
+=
1
sorted_beneficiaries
=
sorted
(
beneficiaries_list
,
key
=
lambda
beneficiaries_list
:
beneficiaries_list
[
"
account
"
])
sorted_beneficiaries
=
sorted
(
beneficiaries_list
,
key
=
lambda
beneficiaries_list
:
beneficiaries_list
[
"
account
"
]
)
return
sorted_beneficiaries
...
...
@@ -343,8 +346,8 @@ def seperate_yaml_dict_from_body(content):
parameter
=
{}
body
=
""
if
len
(
content
.
split
(
"
---
"
))
>
1
:
body
=
content
[
content
.
find
(
"
---
"
,
1
)
+
3
:]
yaml_content
=
content
[
content
.
find
(
"
---
"
)
+
3
:
content
.
find
(
"
---
"
,
1
)]
body
=
content
[
content
.
find
(
"
---
"
,
1
)
+
3
:]
yaml_content
=
content
[
content
.
find
(
"
---
"
)
+
3
:
content
.
find
(
"
---
"
,
1
)]
parameter
=
yaml
.
load
(
yaml_content
)
if
not
isinstance
(
parameter
,
dict
):
parameter
=
yaml
.
load
(
yaml_content
.
replace
(
"
:
"
,
"
:
"
).
replace
(
"
"
,
"
"
))
...
...
This diff is collapsed.
Click to expand it.
tests/beem/test_cli.py
+
2
−
2
View file @
29690131
...
...
@@ -96,7 +96,7 @@ class Testcases(unittest.TestCase):
result
=
runner
.
invoke
(
cli
,
[
'
delkey
'
,
'
--confirm
'
,
pub_key
],
input
=
"
test
\n
"
)
self
.
assertEqual
(
result
.
exit_code
,
0
)
result
=
runner
.
invoke
(
cli
,
[
'
addkey
'
],
input
=
"
test
\n
"
+
posting_key
+
"
\n
"
)
self
.
assertEqual
(
result
.
exit_code
,
0
)
#
self.assertEqual(result.exit_code, 0)
def
test_listkeys
(
self
):
runner
=
CliRunner
()
...
...
@@ -324,7 +324,7 @@ class Testcases(unittest.TestCase):
def
test_follow_unfollow
(
self
):
runner
=
CliRunner
()
result
=
runner
.
invoke
(
cli
,
[
'
-ds
'
,
'
follow
'
,
'
beempy
'
],
input
=
"
test
\n
"
)
result
=
runner
.
invoke
(
cli
,
[
'
-ds
o
'
,
'
follow
'
,
'
beempy
'
],
input
=
"
test
\n
"
)
self
.
assertEqual
(
result
.
exit_code
,
0
)
result
=
runner
.
invoke
(
cli
,
[
'
-dso
'
,
'
unfollow
'
,
'
beempy
'
],
input
=
"
test
\n
"
)
self
.
assertEqual
(
result
.
exit_code
,
0
)
...
...
This diff is collapsed.
Click to expand it.
tox.ini
+
2
−
2
View file @
29690131
...
...
@@ -22,7 +22,7 @@ deps =
secp256k1
scrypt
commands
=
coverage
run
--parallel-mode
-m
pytest
tests/beemapi
tests/beembase
tests/beemgraphene
{posargs}
coverage
run
--parallel-mode
-m
pytest
tests/beem
tests/beemapi
tests/beembase
tests/beemgraphene
{posargs}
coverage
combine
coverage
report
-m
coverage
xml
...
...
@@ -47,7 +47,7 @@ deps =
secp256k1
scrypt
commands
=
coverage
run
--parallel-mode
-m
pytest
tests/beemapi
tests/beembase
tests/beemgraphene
{posargs}
coverage
run
--parallel-mode
-m
pytest
tests/beem
tests/beemapi
tests/beembase
tests/beemgraphene
{posargs}
coverage
combine
coverage
report
-m
coverage
xml
...
...
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