Commit 24b96f94 authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[tests] added tests for plotters/plotterparameters

parent 42c84417
Pipeline #19901 passed with stages
in 35 minutes and 42 seconds
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.cmdline module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
# Basic tests for the command line beat program: plotterparameters
import os
import sys
import nose.tools
import shutil
import json
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
def call(*args, **kwargs):
'''A central mechanism to call the main routine with the right parameters'''
use_prefix = kwargs.get('prefix', prefix)
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)
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_pull_one(obj=None):
obj = obj or 'plot/bar/1'
nose.tools.eq_(call('pull', obj, prefix=tmp_prefix), 0)
assert os.path.exists(os.path.join(tmp_prefix, 'plotterparameters', obj + '.json'))
@slow
@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)
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.cmdline module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
# Basic tests for the command line beat program: plotters
import os
import sys
import nose.tools
import shutil
import json
import simplejson
import collections
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.core.plotter import Storage, Plotter
def call(*args, **kwargs):
'''A central mechanism to call the main routine with the right parameters'''
use_prefix = kwargs.get('prefix', prefix)
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)
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_pull_one(obj=None):
obj = obj or 'plot/bar/1'
nose.tools.eq_(call('pull', obj, prefix=tmp_prefix), 0)
s = Storage(tmp_prefix, obj)
assert s.exists()
return s
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_pull_one_check_deps(obj=None):
obj = obj or 'plot/bar/1'
nose.tools.eq_(call('pull', obj, prefix=tmp_prefix), 0)
assert os.path.exists(os.path.join(tmp_prefix, 'plotterparameters', obj + '.json'))
assert os.path.exists(os.path.join(tmp_prefix, 'libraries', 'plot/baselib/1' + '.json'))
assert os.path.exists(os.path.join(tmp_prefix, 'dataformats', obj + '.json'))
s = Storage(tmp_prefix, obj)
assert s.exists()
return s
@slow
@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)
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
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)
assert os.path.exists(os.path.join(tmp_prefix, 'plotters/' + obj.rsplit('/', 1)[0] + '/output_image.png'))
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
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)
assert os.path.exists(os.path.join(tmp_prefix,'test.png'))
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_plot_sample_input_data_file():
INPUT_DATA = '{"data":[{"label":"negative scores","x":[-5673.502545751196,-5417.040747386832,-5160.578949022467,-4904.117150658103,-4647.655352293739,-4391.193553929375,-4134.731755565012,-3878.269957200647,-3621.808158836283,-3365.346360471919,-3108.8845621075548,-2852.4227637431904,-2595.9609653788266,-2339.4991670144627,-2083.0373686500984,-1826.575570285734,-1570.1137719213702,-1313.6519735570064,-1057.1901751926425,-800.7283768282778],"y":[4.0,7.0,25.0,24.0,30.0,82.0,83.0,100.0,116.0,119.0,173.0,193.0,179.0,195.0,142.0,169.0,131.0,70.0,42.0,16.0]},{"label":"positivescores","x":[-1675.9012965728323,-1597.174480302131,-1518.44766403143,-1439.7208477607287,-1360.9940314900277,-1282.2672152193263,-1203.5403989486254,-1124.8135826779242,-1046.086766407223,-967.3599501365218,-888.6331338658206,-809.9063175951195,-731.1795013244183,-652.4526850537171,-573.725868783016,-494.99905251231485,-416.27223624161365,-337.54541997091246,-258.81860370021127,-180.09178742951008],"y":[1.0,3.0,2.0,0.0,0.0,1.0,1.0,3.0,3.0,2.0,2.0,7.0,13.0,7.0,11.0,13.0,11.0,11.0,6.0,3.0]}]}'
with open(os.path.join(tmp_prefix, "temp_file.json"), "w") as f:
f.write(INPUT_DATA)
f.closed
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)
assert os.path.exists(os.path.join(tmp_prefix,'test.png'))
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_plot_plotterparameter(obj=None):
obj = 'plot/bar/1'
test_pull_one()
assert os.path.exists(os.path.join(tmp_prefix, 'plotterparameters', obj + '.json'))
with open(os.path.join(tmp_prefix, 'plotterparameters', obj + '.json'), 'r') as f:
data = simplejson.load(f, object_pairs_hook=collections.OrderedDict)
f.closed
with open(os.path.join(tmp_prefix, 'plotterparameters', 'temp_file.json'), "w") as f:
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)
assert os.path.exists(os.path.join(tmp_prefix,'test.png'))
Supports Markdown
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