Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.cmdline
Commits
32ef41f9
Commit
32ef41f9
authored
May 22, 2018
by
Theophile GENTILHOMME
Browse files
[test][test_algorithms] Fix tests for Click commands
parent
801ee820
Changes
1
Hide whitespace changes
Inline
Side-by-side
beat/cmdline/test/test_algorithms.py
View file @
32ef41f9
...
...
@@ -30,12 +30,14 @@
import
nose.tools
import
os
import
click
from
click.testing
import
CliRunner
import
shutil
import
json
from
.
import
platform
,
disconnected
,
prefix
,
tmp_prefix
,
user
,
token
,
temp_cwd
from
..common
import
Selector
from
.
.scripts
.beat
import
main
from
beat.cmdline
.scripts
import
main
_cli
from
beat.core.test.utils
import
slow
,
cleanup
,
skipif
from
beat.core.algorithm
import
Storage
...
...
@@ -47,28 +49,29 @@ def call(*args, **kwargs):
use_platform
=
kwargs
.
get
(
'platform'
,
platform
)
use_cache
=
kwargs
.
get
(
'cache'
,
'cache'
)
with
temp_cwd
():
return
main
((
'--platform=%s'
%
use_platform
,
'--user=%s'
%
user
,
'--token=%s'
%
token
,
'--prefix=%s'
%
use_prefix
,
'--cache=%s'
%
use_cache
,
'--test-mode'
,
'algorithm'
,
)
+
args
)
runner
=
CliRunner
()
with
runner
.
isolated_filesystem
():
result
=
runner
.
invoke
(
main_cli
.
main
,
[
'--platform'
,
use_platform
,
'--user'
,
user
,
'--token'
,
token
,
'--prefix'
,
use_prefix
,
'--cache'
,
use_cache
,
'--test-mode'
,
'algorithms'
]
+
list
(
args
)
)
return
result
.
exit_code
,
result
.
output
@
slow
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
@
skipif
(
disconnected
,
"missing test platform (%s)"
%
platform
)
def
test_remote_list
():
nose
.
tools
.
eq_
(
call
(
'list'
,
'--remote'
),
0
)
exit_code
,
outputs
=
call
(
'list'
,
'--remote'
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
msg
=
outputs
)
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_local_list
():
nose
.
tools
.
eq_
(
call
(
'list'
),
0
)
exit_code
,
outputs
=
call
(
'list'
,
'--remote'
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
outputs
)
@
slow
...
...
@@ -76,7 +79,8 @@ def test_local_list():
@
skipif
(
disconnected
,
"missing test platform (%s)"
%
platform
)
def
test_pull_one
():
obj
=
'user/integers_add/1'
nose
.
tools
.
eq_
(
call
(
'pull'
,
obj
,
prefix
=
tmp_prefix
),
0
)
exit_code
,
outputs
=
call
(
'pull'
,
obj
,
prefix
=
tmp_prefix
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
outputs
)
s
=
Storage
(
tmp_prefix
,
obj
)
assert
s
.
exists
()
...
...
@@ -85,7 +89,8 @@ def test_pull_one():
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
@
skipif
(
disconnected
,
"missing test platform (%s)"
%
platform
)
def
test_pull_all
():
nose
.
tools
.
eq_
(
call
(
'pull'
,
prefix
=
tmp_prefix
),
0
)
exit_code
,
outputs
=
call
(
'pull'
,
prefix
=
tmp_prefix
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
outputs
)
@
slow
...
...
@@ -93,13 +98,15 @@ def test_pull_all():
@
skipif
(
disconnected
,
"missing test platform (%s)"
%
platform
)
def
test_diff
():
obj
=
'user/integers_add/1'
nose
.
tools
.
eq_
(
call
(
'pull'
,
obj
,
prefix
=
tmp_prefix
),
0
)
exit_code
,
outputs
=
call
(
'pull'
,
obj
,
prefix
=
tmp_prefix
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
outputs
)
# quickly modify the user algorithm by emptying it
storage
=
Storage
(
tmp_prefix
,
obj
)
storage
.
code
.
save
(
'class Algorithm:
\n
pass'
)
nose
.
tools
.
eq_
(
call
(
'diff'
,
obj
,
prefix
=
tmp_prefix
),
0
)
exit_code
,
outputs
=
call
(
'diff'
,
obj
,
prefix
=
tmp_prefix
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
outputs
)
@
slow
...
...
@@ -108,23 +115,27 @@ def test_diff():
def
test_status
():
test_diff
()
test_pull_one
()
nose
.
tools
.
eq_
(
call
(
'status'
,
prefix
=
tmp_prefix
),
0
)
exit_code
,
outputs
=
call
(
'status'
,
prefix
=
tmp_prefix
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
outputs
)
def
test_check_valid
():
obj
=
'legacy/valid_algorithm/1'
nose
.
tools
.
eq_
(
call
(
'check'
,
obj
),
0
)
exit_code
,
outputs
=
call
(
'check'
,
obj
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
outputs
)
def
test_check_invalid
():
obj
=
'legacy/no_inputs_declarations/1'
nose
.
tools
.
eq_
(
call
(
'check'
,
obj
),
1
)
exit_code
,
outputs
=
call
(
'check'
,
obj
)
nose
.
tools
.
eq_
(
exit_code
,
1
,
outputs
)
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_create
(
obj
=
None
):
obj
=
obj
or
'legacy/algorithm/1'
nose
.
tools
.
eq_
(
call
(
'create'
,
obj
,
prefix
=
tmp_prefix
),
0
)
exit_code
,
outputs
=
call
(
'create'
,
obj
,
prefix
=
tmp_prefix
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
outputs
)
s
=
Storage
(
tmp_prefix
,
obj
)
assert
s
.
exists
()
return
s
...
...
@@ -135,7 +146,8 @@ def test_new_version():
obj
=
'legacy/algorithm/1'
test_create
(
obj
)
obj2
=
'legacy/algorithm/2'
nose
.
tools
.
eq_
(
call
(
'version'
,
obj
,
prefix
=
tmp_prefix
),
0
)
exit_code
,
outputs
=
call
(
'version'
,
obj
,
prefix
=
tmp_prefix
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
outputs
)
s
=
Storage
(
tmp_prefix
,
obj2
)
assert
s
.
exists
()
...
...
@@ -149,7 +161,8 @@ def test_fork():
obj
=
'legacy/algorithm/1'
test_create
(
obj
)
obj2
=
'legacy/different/1'
nose
.
tools
.
eq_
(
call
(
'fork'
,
obj
,
obj2
,
prefix
=
tmp_prefix
),
0
)
exit_code
,
outputs
=
call
(
'fork'
,
obj
,
obj2
,
prefix
=
tmp_prefix
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
outputs
)
s
=
Storage
(
tmp_prefix
,
obj2
)
assert
s
.
exists
()
...
...
@@ -167,7 +180,8 @@ def test_delete_local():
storage
=
Storage
(
tmp_prefix
,
obj
)
assert
storage
.
exists
()
nose
.
tools
.
eq_
(
call
(
'rm'
,
obj
,
prefix
=
tmp_prefix
),
0
)
exit_code
,
outputs
=
call
(
'rm'
,
obj
,
prefix
=
tmp_prefix
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
outputs
)
assert
not
storage
.
exists
()
...
...
@@ -178,5 +192,7 @@ def test_push_and_delete():
test_create
(
obj
)
# now push the new object and then delete it remotely
nose
.
tools
.
eq_
(
call
(
'push'
,
obj
,
prefix
=
tmp_prefix
),
0
)
nose
.
tools
.
eq_
(
call
(
'rm'
,
'--remote'
,
obj
,
prefix
=
tmp_prefix
),
0
)
exit_code
,
outputs
=
call
(
'push'
,
obj
,
prefix
=
tmp_prefix
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
outputs
)
exit_code
,
outputs
=
call
(
'rm'
,
'--remote'
,
obj
,
prefix
=
tmp_prefix
)
nose
.
tools
.
eq_
(
exit_code
,
0
,
outputs
)
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment