Commit ec74eae8 authored by Philip ABBET's avatar Philip ABBET

[unittest] Add a lot of unit tests (moved from beat.core)

parent fa97b2cd
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###############################################################################
# #
# Copyright (c) 2017 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/. #
# #
###############################################################################
import pkg_resources
import tempfile
import sys
prefix = pkg_resources.resource_filename(__name__, 'prefix')
if sys.platform == 'darwin':
tmp_prefix = tempfile.mkdtemp(prefix=__name__, suffix='.tmpdir', dir='/tmp')
else:
tmp_prefix = tempfile.mkdtemp(prefix=__name__, suffix='.tmpdir')
#!/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.core 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/. #
# #
###############################################################################
from ..data import DataSource
from ..data import DataSink
class MockDataSource(DataSource):
def __init__(self, data, indexes):
self.data = list(data)
self.indexes = list(indexes)
self.current = 0
def next(self):
result = (self.data[self.current], self.indexes[self.current][0], self.indexes[self.current][1])
self.current += 1
return result
def hasMoreData(self):
return self.current < sum(1 for i in self.data)
#----------------------------------------------------------
class MockDataSink(DataSink):
class WrittenData:
def __init__(self, data, start, end):
self.data = data
self.start = start
self.end = end
def __init__(self, dataformat):
self.written = []
self.can_write = True
self.dataformat = dataformat
def write(self, data, start_data_index, end_data_index):
if not(self.can_write): raise IOError
self.written.append(
MockDataSink.WrittenData(data, start_data_index, end_data_index)
)
def isConnected(self):
return True
#----------------------------------------------------------
class MockDataSource_Crash(DataSource):
def next(self):
a = b
def hasMoreData(self):
a = b
return False
{
"language": "python",
"splittable": false,
"groups": [
{
"inputs": {
"images": {
"type": "user/2d_array_of_integers/1"
},
"labels": {
"type": "user/floats/1"
}
},
"outputs": {
"features": {
"type": "user/1d_array_of_integers/1"
}
}
}
]
}
#!/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.core 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 InvalidAlgorithmClassName:
def process(self, inputs, outputs):
return True
{
"language": "python",
"splittable": false,
"groups": [
{
"inputs": {
"in_data": {
"type": "user/single_integer/1"
}
},
"outputs": {
"out_data": {
"type": "user/single_integer/1"
}
}
}
]
}
#!/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.core 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 process(self, inputs, outputs):
outputs['out_data'].write(inputs['in_data'].data)
return True
{
"language": "python",
"splittable": false,
"groups": [
{
"inputs": {
"in_data": {
"type": "user/single_integer/1"
}
},
"outputs": {
"out_data": {
"type": "user/single_integer/1"
}
}
}
]
}
#!/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.core 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 __init__(self):
self.delayed = True
def process(self, inputs, outputs):
if not(self.delayed):
outputs['out_data'].write(inputs['in_data'].data)
self.delayed = not(self.delayed)
return True
{
"language": "python",
"splittable": false,
"groups": [
{
"inputs": {
"images": {
"type": "user/2d_array_of_integers/1"
},
"labels": {
"type": "user/floats/1"
}
},
"outputs": {
"features": {
"type": "user/1d_array_of_integers/1"
}
}
}
],
"parameters": {
"int8_value": {
"default": "5",
"type": "int8",
"description": "Some comment"
},
"int8_range": {
"default": "6",
"range": [
0,
"10"
],
"type": "int8",
"description": "Another comment"
},
"int8_choices": {
"default": "4",
"type": "int8",
"choice": [
"2",
"4",
"6",
"8",
"10"
]
},
"int16_value": {
"default": "500",
"type": "int16"
},
"int16_range": {
"default": "300",
"type": "int16",
"range": [
"0",
"1000"
]
},
"int16_choices": {
"default": "400",
"type": "int16",
"choice": [
"200",
"400",
"600",
"800",
"1000"
]
},
"int16_choices2": {
"default": "400",
"type": "int16",
"choice": [
"600",
"400"
]
},
"int32_value": {
"default": "500000",
"type": "int32"
},
"int32_range": {
"default": "500000",
"type": "int32",
"range": [
"0",
"1000000"
]
},
"int32_choices": {
"default": "400000",
"type": "int32",
"choice": [
"200000",
"400000",
"600000",
"800000",
"1000000"
]
},
"int64_value": {
"default": "5000000000",
"type": "int64"
},
"int64_range": {
"default": "5000000000",
"type": "int64",
"range": [
"0",
"10000000000"
]
},
"int64_choices": {
"default": "4000000000",
"type": "int64",
"choice": [
"2000000000",
"4000000000",
"6000000000",
"8000000000",
"10000000000"
]
},
"uint8_value": {
"default": "5",
"type": "uint8"
},
"uint8_range": {
"default": "6",
"type": "uint8",
"range": [
"0",
"10"
]
},
"uint8_choices": {
"default": "4",
"type": "uint8",
"choice": [
"2",
"4",
"6",
"8",
"10"
]
},
"uint16_value": {
"default": "500",
"type": "uint16"
},
"uint16_range": {
"default": "500",
"type": "uint16",
"range": [
"0",
"1000"
]
},
"uint16_choices": {
"default": "400",
"type": "uint16",
"choice": [
"200",
"400",
"600",
"800",
"1000"
]
},
"uint32_value": {
"default": "500000",
"type": "uint32"
},
"uint32_range": {
"default": "500000",
"type": "uint32",
"range": [
"0",
"1000000"
]
},
"uint32_choices": {
"default": "400000",
"type": "uint32",
"choice": [
"200000",
"400000",
"600000",
"800000",
"1000000"
]
},
"uint64_value": {
"default": "5000000000",
"type": "uint64"
},
"uint64_range": {
"default": "5000000000",
"type": "uint64",
"range": [
"0",
"10000000000"
]
},
"uint64_choices": {
"default": "4000000000",
"type": "uint64",
"choice": [
"2000000000",
"4000000000",
"6000000000",
"8000000000",
"10000000000"
]
},
"float32_value": {
"default": "0.0",
"type": "float32"
},
"float32_range": {
"default": "0.0",
"type": "float32",
"range": [
"-10.0",
"10.0"
]
},
"float32_choices": {
"default": "0.0",
"type": "float32",
"choice": [
"-10.0",
"-5.0",
"0.0",
"5.0",
"10.0"
]
},
"float64_value": {
"default": "0.0",
"type": "float64"
},
"float64_range": {
"default": "0.0",
"type": "float64",
"range": [
"-100.0",
"100.0"
]
},
"float64_choices": {
"default": "0.0",
"type": "float64",
"choice": [
-10.0,
-5.0,
0.0,
5.0,
10.0
]
},
"bool_value": {
"default": true,
"type": "bool"
},
"string_value": {
"default": "choice1",
"type": "string",
"choice": [
"choice1",
"choice2",
"choice3"
]
}
}
}
#!/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.core 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.int8_value = parameters['int8_value']
self.int8_range = parameters['int8_range']
self.int8_choices = parameters['int8_choices']
self.int16_value = parameters['int16_value']
self.int16_range = parameters['int16_range']
self.int16_choices = parameters['int16_choices']
self.int32_value = parameters['int32_value']
self.int32_range = parameters['int32_range']
self.int32_choices = parameters['int32_choices']
self.int64_value = parameters['int64_value']
self.int64_range = parameters['int64_range']
self.int64_choices = parameters['int64_choices']
self.uint8_value = parameters['uint8_value']
self.uint8_range = parameters['uint8_range']
self.uint8_choices = parameters['uint8_choices']
self.uint16_value = parameters['uint16_value']
self.uint16_range = parameters['uint16_range']
self.uint16_choices = parameters['uint16_choices']
self.uint32_value = parameters['uint32_value']
self.uint32_range = parameters['uint32_range']
self.uint32_choices = parameters['uint32_choices']
self.uint64_value = parameters['uint64_value']
self.uint64_range = parameters['uint64_range']
self.uint64_choices = parameters['uint64_choices']
self.float32_value = parameters['float32_value']
self.float32_range = parameters['float32_range']
self.float32_choices = parameters['float32_choices']
self.float64_value = parameters['float64_value']
self.float64_range = parameters['float64_range']
self.float64_choices = parameters['float64_choices']
self.bool_value = parameters['bool_value']
self.string_value = parameters['string_value']
return True
def process(self, inputs, outputs):
return True
{
"language": "python",
"splittable": false,
"groups": [
{