Commit f58a358c authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME
Browse files

[test][test_{cache,databases,dataformats,experiments,plotterparameters,plotter...

[test][test_{cache,databases,dataformats,experiments,plotterparameters,plotters,status,toolchains] Fix test for Click commands

Tests are now calling Click commands.
parent 492b57f1
......@@ -29,13 +29,14 @@
# Basic tests for the command line beat program: cache
import os
import click
from click.testing import CliRunner
import nose.tools
from . import prefix, tmp_prefix, temp_cwd
from .utils import index_experiment_dbs
from ..scripts.beat import main
from beat.cmdline.scripts import main_cli
from beat.core.test.utils import cleanup, slow
......@@ -45,12 +46,14 @@ def call(*args, **kwargs):
use_prefix = kwargs.get('prefix', prefix)
with temp_cwd():
return main((
'--prefix=%s' % use_prefix,
'--cache=%s' % tmp_prefix,
'--test-mode',
) + args)
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
main_cli.main,
['--test-mode', '--prefix', use_prefix, '--cache', tmp_prefix] +
list(args)
)
return result.exit_code, result.output
def setup_module():
......@@ -63,21 +66,30 @@ def setup_module():
def teardown_module():
cleanup()
@slow
def test_cache_info():
assert len(os.listdir(tmp_prefix)) != 0
nose.tools.eq_(call('cache', 'info'), 0)
nose.tools.eq_(call('cache', 'info', '--sizes'), 0)
nose.tools.eq_(call('cache', 'info', '--start=0'), 0)
ex_code, out = call('cache', 'info')
nose.tools.eq_(ex_code, 0, out)
ex_code, out = call('cache', 'info', '--sizes')
nose.tools.eq_(ex_code, 0, out)
ex_code, out = call('cache', '--start', 0, 'info')
nose.tools.eq_(ex_code, 0, out)
@slow
def test_cache_view():
assert len(os.listdir(tmp_prefix)) != 0
nose.tools.eq_(call('cache', 'view'), 0)
nose.tools.eq_(call('cache', 'view', '--start=0'), 0)
ex_code, out = call('cache', 'view')
nose.tools.eq_(ex_code, 0, out)
ex_code, out = call('cache', '--start', 0, 'view')
nose.tools.eq_(ex_code, 0, out)
@slow
def test_cache_clear():
assert len(os.listdir(tmp_prefix)) != 0
nose.tools.eq_(call('cache', 'clear'), 0)
ex_code, out = call('cache', 'clear')
nose.tools.eq_(ex_code, 0, out)
nose.tools.eq_(len(os.listdir(tmp_prefix)), 0)
......@@ -29,10 +29,11 @@
# Basic tests for the command line beat program: databases
import nose.tools
import click
from click.testing import CliRunner
from . import platform, disconnected, prefix, tmp_prefix, user, token, temp_cwd
from ..scripts.beat import main
from beat.cmdline.scripts import main_cli
from beat.core.test.utils import slow, cleanup, skipif
from beat.core.database import Storage, Database
......@@ -47,15 +48,17 @@ def call(*args, **kwargs):
use_prefix = kwargs.get('prefix', prefix)
use_platform = kwargs.get('platform', platform)
with temp_cwd():
return main((
'--platform=%s' % use_platform,
'--user=%s' % user,
'--token=%s' % token,
'--prefix=%s' % use_prefix,
'--test-mode',
'database',
) + args)
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
main_cli.main,
['--test-mode', '--prefix', use_prefix, '--token', token,
'--user', user, '--platform', use_platform, 'databases'] +
list(args)
)
if result.exit_code != 0:
click.echo(result.output)
return result.exit_code
@slow
......
......@@ -29,10 +29,11 @@
# Basic tests for the command line beat program: dataformats
import nose.tools
import click
from click.testing import CliRunner
from . import platform, disconnected, prefix, tmp_prefix, user, token
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.dataformat import Storage, DataFormat
......@@ -43,14 +44,18 @@ def call(*args, **kwargs):
use_prefix = kwargs.get('prefix', prefix)
use_platform = kwargs.get('platform', platform)
return main((
'--platform=%s' % use_platform,
'--user=%s' % user,
'--token=%s' % token,
'--prefix=%s' % use_prefix,
'--test-mode',
'dataformat',
) + args)
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
main_cli.main,
['--test-mode', '--prefix', use_prefix, '--token', token,
'--user', user, '--platform', use_platform, 'dataformats'] +
list(args)
)
if result.exit_code != 0:
click.echo(result.output)
return result.exit_code
@slow
......
......@@ -32,11 +32,12 @@ import os
import sys
import logging
import nose.tools
import click
from click.testing import CliRunner
from . import platform, disconnected, prefix, tmp_prefix, user, token, temp_cwd
from .utils import index_experiment_dbs, MockLoggingHandler
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.experiment import Storage, Experiment
......@@ -53,16 +54,18 @@ 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',
'experiment',
) + args)
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
main_cli.main,
['--test-mode', '--prefix', use_prefix, '--token', token,
'--user', user, '--platform', use_platform, '--cache', use_cache,
'experiments'] +
list(args)
)
if result.exit_code != 0:
click.echo(result.output)
return result.exit_code
@slow
......@@ -192,11 +195,11 @@ def test_run_integers_addition_1_twice():
obj = 'user/user/integers_addition/1/integers_addition'
nose.tools.eq_(call('run', obj, cache=tmp_prefix), 0)
info_len = len(log_messages['info'])
nose.tools.eq_(info_len, 5)
assert info_len > 4
assert log_messages['info'][info_len - 1].startswith(' Results')
nose.tools.eq_(call('run', obj, cache=tmp_prefix), 0)
info_len = len(log_messages['info'])
nose.tools.eq_(info_len, 8)
assert info_len > 7
assert log_messages['info'][info_len - 1].startswith(' Results')
......
......@@ -33,12 +33,14 @@ import sys
import nose.tools
import shutil
import json
import click
from click.testing import CliRunner
from . import platform, disconnected, prefix, tmp_prefix, user, token, temp_cwd
from .utils import index_experiment_dbs
from ..common import Selector
from ..scripts.beat import main
from beat.core.test.utils import slow, cleanup, skipif
from beat.cmdline.scripts import main_cli
def call(*args, **kwargs):
......@@ -48,17 +50,17 @@ 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',
'plotterparameters',
) + args)
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
main_cli.main,
['--test-mode', '--prefix', use_prefix, '--token', token,
'--user', user, '--cache', use_cache, 'plotterparameters'] +
list(args)
)
if result.exit_code != 0:
click.echo(result.output)
return result.exit_code
@slow
@nose.tools.with_setup(teardown=cleanup)
......
......@@ -35,12 +35,14 @@ import shutil
import json
import simplejson
import collections
import click
from click.testing import CliRunner
from . import platform, disconnected, prefix, tmp_prefix, user, token, temp_cwd
from . import platform, disconnected, prefix, tmp_prefix, user, token
from .utils import index_experiment_dbs
from ..common import Selector
from ..scripts.beat import main
from beat.core.test.utils import slow, cleanup, skipif
from beat.cmdline.scripts import main_cli
from beat.core.plotter import Storage, Plotter
......@@ -51,17 +53,17 @@ 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',
'plotters',
) + args)
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
main_cli.main,
['--test-mode', '--prefix', use_prefix, '--token', token,
'--user', user, '--cache', use_cache, '--platform', use_platform,
'plotters'] + list(args)
)
if result.exit_code != 0:
click.echo(result.output)
return result.exit_code
@slow
@nose.tools.with_setup(teardown=cleanup)
......@@ -101,7 +103,8 @@ def test_pull_all():
def test_plot_sample_data_no_output_name():
obj = 'plot/bar/1'
test_pull_one()
nose.tools.eq_(call('plot', obj, '--sample_data', prefix=tmp_prefix), 0)
print(tmp_prefix)
nose.tools.eq_(call('plot', obj, '--sample-data', prefix=tmp_prefix), 0)
assert os.path.exists(os.path.join(tmp_prefix, 'plotters/' + obj.rsplit('/', 1)[0] + '/output_image.png'))
......@@ -111,7 +114,7 @@ def test_plot_sample_data_no_output_name():
def test_plot_sample_data_change_name():
obj = 'plot/bar/1'
test_pull_one()
nose.tools.eq_(call('plot', obj, '--sample_data', '--outputimage=test.png', prefix=tmp_prefix), 0)
nose.tools.eq_(call('plot', obj, '--sample-data', '--output-image=test.png', prefix=tmp_prefix), 0)
assert os.path.exists(os.path.join(tmp_prefix,'test.png'))
......@@ -127,7 +130,12 @@ def test_plot_sample_input_data_file():
obj = 'plot/bar/1'
test_pull_one()
nose.tools.eq_(call('plot', obj, '--inputdata=%s'%os.path.join(tmp_prefix, "temp_file.json"), '--outputimage=test.png', prefix=tmp_prefix), 0)
nose.tools.eq_(
call('plot', obj,
'--input-data=%s'%os.path.join(tmp_prefix, "temp_file.json"),
'--output-image=test.png', prefix=tmp_prefix),
0
)
assert os.path.exists(os.path.join(tmp_prefix,'test.png'))
......@@ -147,5 +155,9 @@ def test_plot_plotterparameter(obj=None):
f.write(simplejson.dumps(data))
f.closed
nose.tools.eq_(call('plot', obj, '--sample_data', '--outputimage=test.png', '--plotterparameter=temp_file', prefix=tmp_prefix), 0)
nose.tools.eq_(
call('plot', obj, '--sample-data', '--output-image=test.png',
'--plotter-parameter=temp_file', prefix=tmp_prefix),
0
)
assert os.path.exists(os.path.join(tmp_prefix,'test.png'))
......@@ -32,11 +32,13 @@ import os
import nose.tools
import simplejson
import click
from click.testing import CliRunner
from . import platform, disconnected, tmp_prefix, user
from ..common import Selector
from ..scripts.beat import main
from beat.core.test.utils import slow, cleanup, skipif
from beat.cmdline.scripts import main_cli
from beat.core.algorithm import Storage
......@@ -46,12 +48,17 @@ def call(*args, **kwargs):
use_prefix = kwargs.get('prefix', tmp_prefix)
use_platform = kwargs.get('platform', platform)
return main((
'--platform=%s' % use_platform,
'--prefix=%s' % use_prefix,
'--user=%s' % user,
'--test-mode',
) + args)
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
main_cli.main,
['--test-mode', '--prefix', use_prefix, '--platform', use_platform,
'--user', user] +
list(args)
)
if result.exit_code != 0:
click.echo(result.output)
return result.exit_code
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_status():
......
......@@ -30,10 +30,11 @@
import os
import nose.tools
from . import platform, disconnected, prefix, tmp_prefix, user, token, temp_cwd
import click
from click.testing import CliRunner
from . import platform, disconnected, prefix, tmp_prefix, user, token
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.toolchain import Storage, Toolchain
......@@ -44,16 +45,17 @@ def call(*args, **kwargs):
use_prefix = kwargs.get('prefix', prefix)
use_platform = kwargs.get('platform', platform)
with temp_cwd():
return main((
'--platform=%s' % use_platform,
'--user=%s' % user,
'--token=%s' % token,
'--prefix=%s' % use_prefix,
'--test-mode',
'toolchain',
) + args)
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
main_cli.main,
['--test-mode', '--prefix', use_prefix, '--token', token,
'--user', user, '--platform', use_platform, 'toolchains'] +
list(args)
)
if result.exit_code != 0:
click.echo(result.output)
return result.exit_code
@slow
@nose.tools.with_setup(teardown=cleanup)
......
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