From 8ac5ad4b2e0e3f71a287adbb69b0a0c1656a4745 Mon Sep 17 00:00:00 2001 From: Samuel Gaist <samuel.gaist@idiap.ch> Date: Wed, 27 Jan 2021 18:01:58 +0100 Subject: [PATCH] [test][databases][simple_rawdata_access] Add new version following V2 implementation --- test/databases/simple_rawdata_access/2.json | 60 +++++ test/databases/simple_rawdata_access/2.py | 247 ++++++++++++++++++++ test/databases/simple_rawdata_access/2.rst | 1 + 3 files changed, 308 insertions(+) create mode 100644 test/databases/simple_rawdata_access/2.json create mode 100644 test/databases/simple_rawdata_access/2.py create mode 100644 test/databases/simple_rawdata_access/2.rst diff --git a/test/databases/simple_rawdata_access/2.json b/test/databases/simple_rawdata_access/2.json new file mode 100644 index 0000000..4ed14fb --- /dev/null +++ b/test/databases/simple_rawdata_access/2.json @@ -0,0 +1,60 @@ +{ + "description": "A test database that emits integers", + "root_folder": "/this/database/does/not/require/a/path", + "environment": { + "name": "Example databases", + "version": "1.4.1" + }, + "direct_rawdata_access": true, + "protocols": [ + { + "name": "protocol", + "template": "test_integers/1", + "views": { + "set": { + "view": "View", + "parameters": {} + }, + "set2": { + "view": "View2", + "parameters": {} + } + } + }, + { + "name": "protocol2", + "template": "test_integers/1", + "views": { + "set": { + "view": "LargeView", + "parameters": {} + }, + "set2": { + "view": "View2", + "parameters": {} + } + } + }, + { + "name": "10_numbers", + "template": "one_block/1", + "views": { + "numbers": { + "view": "View10", + "parameters": {} + } + } + }, + { + "name": "duo", + "template": "one_block_two_inputs/1", + "views": { + "numbers": { + "view": "ViewDuo", + "parameters": {} + } + } + } + ], + "schema_version": 2 +} \ No newline at end of file diff --git a/test/databases/simple_rawdata_access/2.py b/test/databases/simple_rawdata_access/2.py new file mode 100644 index 0000000..d887ae8 --- /dev/null +++ b/test/databases/simple_rawdata_access/2.py @@ -0,0 +1,247 @@ +############################################################################### +# # +# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ # +# Contact: beat.support@idiap.ch # +# # +# This file is part of the beat.examples 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/. # +# # +############################################################################### + +import numpy as np +from collections import namedtuple +from beat.backend.python.database import View as BaseView + + +#---------------------------------------------------------- + + +class View(BaseView): + """Outputs: + - out: "{{ system_user.username }}/integer/1" + + --------------- --------------- --------------- --------------- + | out | | out | | out | | out | + --------------- --------------- --------------- --------------- + """ + + def index(self, root_folder, parameters): + Entry = namedtuple('Entry', ['out']) + + return [ + Entry(42), + ] + + + def get(self, output, index): + obj = self.objs[index] + + if output == 'out': + return { + 'value': np.int32(obj.out) + } + + +#---------------------------------------------------------- + + +class View2(BaseView): + """Outputs: + - out: "{{ system_user.username }}/integer/1" + + --------------- --------------- --------------- --------------- + | out | | out | | out | | out | + --------------- --------------- --------------- --------------- + """ + + def index(self, root_folder, parameters): + Entry = namedtuple('Entry', ['out']) + + return [ + Entry(53), + ] + + + def get(self, output, index): + obj = self.objs[index] + + if output == 'out': + return { + 'value': np.int32(obj.out) + } + + +#---------------------------------------------------------- + + +class LargeView(BaseView): + + """Outputs: + - out: "{{ system_user.username }}/integer/1" + + --------------- --------------- --------------- --------------- + | out | | out | | out | | out | + --------------- --------------- --------------- --------------- + """ + + def index(self, root_folder, parameters): + Entry = namedtuple('Entry', ['out']) + + return [ + Entry(0), + Entry(1), + Entry(2), + Entry(3), + Entry(4), + ] + + + def get(self, output, index): + obj = self.objs[index] + + if output == 'out': + return { + 'value': np.int32(obj.out) + } + + +#---------------------------------------------------------- + + +class View10(BaseView): + + """Outputs: + - out: "{{ system_user.username }}/integer/1" + + --------------- --------------- --------------- --------------- + | out | | out | | out | | out | + --------------- --------------- --------------- --------------- + """ + + def index(self, root_folder, parameters): + Entry = namedtuple('Entry', ['out']) + + return [ + Entry(0), + Entry(1), + Entry(2), + Entry(3), + Entry(4), + Entry(5), + Entry(6), + Entry(7), + Entry(8), + Entry(9), + ] + + + def get(self, output, index): + obj = self.objs[index] + + if output == 'out': + return { + 'value': np.int32(obj.out) + } + + +#---------------------------------------------------------- + + +class ViewDuo(BaseView): + + """Outputs: + - a: "{{ system_user.username }}/integer/1" + - b: "{{ system_user.username }}/integer/1" + + ------------------------------- ------------------------------- + | a | | a | + ------------------------------- ------------------------------- + --------------- --------------- --------------- --------------- + | b | | b | | b | | b | + --------------- --------------- --------------- --------------- + """ + + def index(self, root_folder, parameters): + Entry = namedtuple('Entry', ['a', 'b']) + + return [ + Entry(0, 0), + Entry(0, 1), + Entry(0, 2), + Entry(10, 3), + Entry(10, 4), + Entry(10, 5), + Entry(20, 6), + Entry(20, 7), + Entry(20, 8), + ] + + + def get(self, output, index): + obj = self.objs[index] + + if output == 'a': + return { + 'value': np.int32(obj.a) + } + + elif output == 'b': + return { + 'value': np.int32(obj.b) + } + + +#---------------------------------------------------------- + + +def setup_tests(): + pass + + +#---------------------------------------------------------- + + +# Test the behavior of the views (on fake data) +if __name__ == '__main__': + + setup_tests() + + from beat.backend.python.database import DatabaseTester + + DatabaseTester('View', View, + [ + 'out', + ], + parameters=dict( + ), + ) + + DatabaseTester('View2', View2, + [ + 'out', + ], + parameters=dict( + ), + ) + + DatabaseTester('LargeView', LargeView, + [ + 'out', + ], + parameters=dict( + ), + ) diff --git a/test/databases/simple_rawdata_access/2.rst b/test/databases/simple_rawdata_access/2.rst new file mode 100644 index 0000000..2a8928c --- /dev/null +++ b/test/databases/simple_rawdata_access/2.rst @@ -0,0 +1 @@ +A test database that emits integers \ No newline at end of file -- GitLab