Commit 440618eb authored by Samuel GAIST's avatar Samuel GAIST

[tests][algorithms] Create default dataformat for algorithm prototype loading

This patch adds a setup method that should be called for all tests
requiring the use of the Algorithm prototype.
parent d1ba73ba
...@@ -35,11 +35,24 @@ from click.testing import CliRunner ...@@ -35,11 +35,24 @@ from click.testing import CliRunner
import shutil import shutil
import json import json
from . import platform, disconnected, prefix, tmp_prefix, user, token, temp_cwd
from ..common import Selector
from beat.cmdline.scripts import main_cli
from beat.core.test.utils import slow, cleanup, skipif from beat.core.test.utils import slow, cleanup, skipif
from beat.core.algorithm import Storage from beat.core.algorithm import Storage
from beat.cmdline.scripts import main_cli
from .. import common
from . import platform, disconnected, prefix, tmp_prefix, user, token, temp_cwd
def setup():
"""Create default dataformat for algorithm prototype loading"""
from .test_dataformats import test_create as df_test_create
from .test_dataformats import call as df_call
obj = 'user/integers/1'
nose.tools.eq_(df_call('create', obj, prefix=tmp_prefix), 0)
nose.tools.eq_(df_call('push', obj, prefix=tmp_prefix), 0)
def call(*args, **kwargs): def call(*args, **kwargs):
...@@ -55,7 +68,8 @@ def call(*args, **kwargs): ...@@ -55,7 +68,8 @@ def call(*args, **kwargs):
main_cli.main, main_cli.main,
['--platform', use_platform, '--user', user, '--token', token, ['--platform', use_platform, '--user', user, '--token', token,
'--prefix', use_prefix, '--cache', use_cache, '--test-mode', '--prefix', use_prefix, '--cache', use_cache, '--test-mode',
'algorithms'] + list(args) 'algorithms'] + list(args),
catch_exceptions=False
) )
return result.exit_code, result.output return result.exit_code, result.output
...@@ -131,7 +145,7 @@ def test_check_invalid(): ...@@ -131,7 +145,7 @@ def test_check_invalid():
nose.tools.eq_(exit_code, 1, outputs) nose.tools.eq_(exit_code, 1, outputs)
@nose.tools.with_setup(teardown=cleanup) @nose.tools.with_setup(setup=setup, teardown=cleanup)
def test_create(obj=None): def test_create(obj=None):
obj = obj or 'legacy/algorithm/1' obj = obj or 'legacy/algorithm/1'
exit_code, outputs = call('create', obj, prefix=tmp_prefix) exit_code, outputs = call('create', obj, prefix=tmp_prefix)
...@@ -141,7 +155,7 @@ def test_create(obj=None): ...@@ -141,7 +155,7 @@ def test_create(obj=None):
return s return s
@nose.tools.with_setup(teardown=cleanup) @nose.tools.with_setup(setup=setup, teardown=cleanup)
def test_new_version(): def test_new_version():
obj = 'legacy/algorithm/1' obj = 'legacy/algorithm/1'
test_create(obj) test_create(obj)
...@@ -152,11 +166,11 @@ def test_new_version(): ...@@ -152,11 +166,11 @@ def test_new_version():
assert s.exists() assert s.exists()
# check version status # check version status
with Selector(tmp_prefix) as selector: with common.Selector(tmp_prefix) as selector:
assert selector.version_of('algorithm', obj2) == obj assert selector.version_of('algorithm', obj2) == obj
@nose.tools.with_setup(teardown=cleanup) @nose.tools.with_setup(setup=setup, teardown=cleanup)
def test_fork(): def test_fork():
obj = 'legacy/algorithm/1' obj = 'legacy/algorithm/1'
test_create(obj) test_create(obj)
...@@ -167,11 +181,11 @@ def test_fork(): ...@@ -167,11 +181,11 @@ def test_fork():
assert s.exists() assert s.exists()
# check fork status # check fork status
with Selector(tmp_prefix) as selector: with common.Selector(tmp_prefix) as selector:
assert selector.forked_from('algorithm', obj2) == obj assert selector.forked_from('algorithm', obj2) == obj
@nose.tools.with_setup(teardown=cleanup) @nose.tools.with_setup(setup=setup, teardown=cleanup)
def test_delete_local(): def test_delete_local():
obj = 'legacy/algorithm/1' obj = 'legacy/algorithm/1'
storage = test_create(obj) storage = test_create(obj)
...@@ -185,7 +199,7 @@ def test_delete_local(): ...@@ -185,7 +199,7 @@ def test_delete_local():
assert not storage.exists() assert not storage.exists()
@nose.tools.with_setup(teardown=cleanup) @nose.tools.with_setup(setup=setup, teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform) @skipif(disconnected, "missing test platform (%s)" % platform)
def test_push_and_delete(): def test_push_and_delete():
obj = 'user/newobject/1' obj = 'user/newobject/1'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment