Skip to content
Snippets Groups Projects
Commit 8a3d08f5 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[algorithm] Implement warning if prepare is present with api_version 1 property

parent 36bb8d18
No related branches found
No related tags found
1 merge request!22Implement warning if prepare is present with api_version 1 property for algorithm
Pipeline #23999 passed
......@@ -36,6 +36,7 @@ Validation for algorithms
import os
import sys
import logging
import six
import numpy
......@@ -47,6 +48,9 @@ from . import loader
from . import utils
logger = logging.getLogger(__name__)
# ----------------------------------------------------------
......@@ -116,7 +120,15 @@ class Runner(object):
self.exc = exc
self.ready = not hasattr(self.obj, 'setup')
self.prepared = (self.algorithm.api_version == 1) or not hasattr(self.obj, 'prepare')
has_api_v1 = self.algorithm.api_version == 1
has_prepare = hasattr(self.obj, 'prepare')
self.prepared = has_api_v1 or not has_prepare
if has_api_v1 and has_prepare:
logger.warning("Prepare is a reserved function name starting with API V2")
def _check_parameters(self, parameters):
......
{
"language": "python",
"splittable": false,
"parameters": {
"sync": {
"default": "in1",
"type": "string"
}
},
"groups": [
{
"inputs": {
"in1": {
"type": "user/single_integer/1"
},
"in2": {
"type": "user/single_integer/1"
}
},
"outputs": {
"out": {
"type": "user/single_integer/1"
}
}
}
]
}
\ No newline at end of file
#!/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.backend.python 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/. #
# #
###############################################################################
class Algorithm:
def setup(self, parameters):
self.sync = parameters['sync']
return True
def prepare(self):
return True
def process(self, inputs, outputs):
if inputs[self.sync].isDataUnitDone():
outputs['out'].write({
'value': inputs['in1'].data.value + inputs['in2'].data.value,
})
return True
......@@ -31,6 +31,8 @@ import six
import os
import glob
import tempfile
import logging
import numpy as np
from ..algorithm import Algorithm
......@@ -47,6 +49,8 @@ from ..outputs import OutputList
from ..outputs import SynchronizationListener
from .mocks import MockDataSink
from .mocks import MockLoggingHandler
from . import prefix
......@@ -451,6 +455,23 @@ class TestLegacyAPI_Prepare(unittest.TestCase):
self.assertTrue(runnable.prepared)
def test_prepare_warning(self):
log_handler = MockLoggingHandler(level='DEBUG')
logging.getLogger().addHandler(log_handler)
log_messages = log_handler.messages
algorithm = Algorithm(prefix, 'legacy/prepare/1')
self.assertTrue(algorithm.valid)
runnable = algorithm.runner()
self.assertTrue(runnable.prepared)
self.assertTrue(runnable.prepare(DataLoaderList()))
self.assertTrue(runnable.prepared)
info_len = len(log_messages['warning'])
self.assertEqual(info_len, 1)
self.assertEqual(log_messages['warning'][info_len - 1], 'Prepare is a reserved function name starting with API V2')
#----------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment