diff --git a/beat/backend/python/test/prefix/algorithms/autonomous/invalid_loop_output/1.json b/beat/backend/python/test/prefix/algorithms/autonomous/invalid_loop_output/1.json new file mode 100644 index 0000000000000000000000000000000000000000..f407f19b5ae4af3108acd9facc5330b62ce806ec --- /dev/null +++ b/beat/backend/python/test/prefix/algorithms/autonomous/invalid_loop_output/1.json @@ -0,0 +1,24 @@ +{ + "schema_version": 2, + "language": "python", + "api_version": 2, + "type": "loop", + "splittable": false, + "groups": [ + { + "inputs": { + "in": { + "type": "user/single_integer/1" + } + }, + "loop": { + "input": { + "type": "user/single_integer/1" + }, + "output": { + "type": "user/single_integer/1" + } + } + } + ] +} diff --git a/beat/backend/python/test/prefix/algorithms/autonomous/invalid_loop_output/1.py b/beat/backend/python/test/prefix/algorithms/autonomous/invalid_loop_output/1.py new file mode 100644 index 0000000000000000000000000000000000000000..157d8ffd163fee0033b59c8a023119e46ef76e63 --- /dev/null +++ b/beat/backend/python/test/prefix/algorithms/autonomous/invalid_loop_output/1.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# vim: set fileencoding=utf-8 : + +############################################################################### +# # +# Copyright (c) 2018 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 validate(self, result): + value = result.value + + return value < 6 diff --git a/beat/backend/python/test/test_loop_executor.py b/beat/backend/python/test/test_loop_executor.py index 1878e4285d845d1ae6bc3e106941503929e6ec6b..769ea50b6826e606705737ee9b4606aeabfbbc60 100644 --- a/beat/backend/python/test/test_loop_executor.py +++ b/beat/backend/python/test/test_loop_executor.py @@ -43,6 +43,7 @@ from ..loop_executor import Executor as LoopExecutor from ..loop_executor import LoopMessageHandler from ..executor import Executor from ..message_handler import MessageHandler +from ..exceptions import RemoteException from ..algorithm import Algorithm from ..dataformat import DataFormat @@ -105,6 +106,7 @@ class TestExecution(unittest.TestCase): self.message_handler = None self.loop_message_handler = None self.executor_socket = None + self.loop_executor = None self.loop_socket = None self.zmq_context = None @@ -114,6 +116,9 @@ class TestExecution(unittest.TestCase): shutil.rmtree(self.working_dir) shutil.rmtree(self.loop_working_dir) + if self.loop_executor: + self.loop_executor.wait() + for handler in [self.message_handler, self.loop_message_handler]: if handler is not None: handler.kill() @@ -201,15 +206,16 @@ class TestExecution(unittest.TestCase): self.loop_socket = self.zmq_context.socket(zmq.PAIR) self.loop_socket.connect(self.loop_message_handler.address) - loop_executor = LoopExecutor(self.loop_message_handler, self.loop_working_dir, cache_root=self.cache_root) - self.assertTrue(loop_executor.setup()) - self.assertTrue(loop_executor.prepare()) - loop_executor.process() + self.loop_executor = LoopExecutor(self.loop_message_handler, self.loop_working_dir, cache_root=self.cache_root) + self.assertTrue(self.loop_executor.setup()) + self.assertTrue(self.loop_executor.prepare()) + self.loop_executor.process() executor = Executor(self.executor_socket, self.working_dir, cache_root=self.cache_root, loop_socket=self.loop_socket) self.assertTrue(executor.setup()) self.assertTrue(executor.prepare()) + self.assertTrue(executor.process()) cached_file = CachedDataSource() @@ -225,4 +231,9 @@ class TestExecution(unittest.TestCase): def test_autonomous_loop(self): self.process('autonomous/loop_user/1', - 'autonomous/loop/1') \ No newline at end of file + 'autonomous/loop/1') + + def test_autonomous_loop_invalid_output(self): + with self.assertRaises(RemoteException): + self.process('autonomous/loop_user/1', + 'autonomous/invalid_loop_output/1') \ No newline at end of file