Commit f5dc2b93 authored by Samuel GAIST's avatar Samuel GAIST

[test][database] Moved keyword test in own test

The test prefix of this package is also used in other tests like
those of beat.core. Modifying such a base element can have far
reaching consequences.
parent 0087b3b6
Pipeline #23699 failed with stages
in 14 minutes and 9 seconds
......@@ -12,8 +12,7 @@
"outputs": {
"a": "user/single_integer/1",
"b": "user/single_integer/1",
"sum": "user/single_integer/1",
"class": "user/single_integer/1"
"sum": "user/single_integer/1"
}
}
]
......@@ -46,8 +45,7 @@
"outputs": {
"a": "user/single_integer/1",
"b": "user/single_integer/1",
"sum": "user/single_integer/1",
"class": "user/single_integer/1"
"sum": "user/single_integer/1"
}
},
{
......
......@@ -32,23 +32,20 @@ from beat.backend.python.database import View
class Double(View):
def __init__(self):
super(Double, self)
self.output_member_map = {'class': 'cls'}
def index(self, root_folder, parameters):
Entry = namedtuple('Entry', ['a', 'b', 'sum', 'cls'])
Entry = namedtuple('Entry', ['a', 'b', 'sum'])
return [
Entry(1, 10, 11, 41),
Entry(2, 20, 22, 42),
Entry(3, 30, 33, 43),
Entry(4, 40, 44, 44),
Entry(5, 50, 55, 45),
Entry(6, 60, 66, 46),
Entry(7, 70, 77, 47),
Entry(8, 80, 88, 48),
Entry(9, 90, 99, 49),
Entry(1, 10, 11),
Entry(2, 20, 22),
Entry(3, 30, 33),
Entry(4, 40, 44),
Entry(5, 50, 55),
Entry(6, 60, 66),
Entry(7, 70, 77),
Entry(8, 80, 88),
Entry(9, 90, 99),
]
......
{
"root_folder": "/path/not/set",
"protocols": [
{
"name": "keyword",
"template": "keyword",
"sets": [
{
"name": "keyword",
"template": "keyword",
"view": "Keyword",
"outputs": {
"def": "user/single_integer/1",
"class": "user/single_integer/1",
"sum": "user/single_integer/1"
}
}
]
}
]
}
#!/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/. #
# #
###############################################################################
import random
import numpy
from collections import namedtuple
from beat.backend.python.database import View
class Keyword(View):
def __init__(self):
super(Keyword, self)
self.output_member_map = {
'class': 'cls',
'def': 'definition'
}
def index(self, root_folder, parameters):
Entry = namedtuple('Entry', ['cls', 'definition', 'sum'])
return [
Entry(1, 10, 11),
Entry(2, 20, 22),
Entry(3, 30, 33),
Entry(4, 40, 44),
Entry(5, 50, 55),
Entry(6, 60, 66),
Entry(7, 70, 77),
Entry(8, 80, 88),
Entry(9, 90, 99),
]
def get(self, output, index):
obj = self.objs[index]
if output == 'class':
return {
'value': numpy.int32(obj.cls)
}
elif output == 'def':
return {
'value': numpy.int32(obj.definition)
}
elif output == 'sum':
return {
'value': numpy.int32(obj.sum)
}
......@@ -397,7 +397,7 @@ class TestDatabaseOutputDataSource(unittest.TestCase):
view.setup(os.path.join(self.cache_root, 'data.db'), pack=False)
self.assertTrue(view.data_sources is not None)
self.assertEqual(len(view.data_sources), 4)
self.assertEqual(len(view.data_sources), 3)
for output_name, data_source in view.data_sources.items():
self.assertEqual(9, len(data_source))
......
......@@ -68,12 +68,11 @@ def test_load_protocol_with_one_set():
set = database.set("double", "double")
nose.tools.eq_(set['name'], 'double')
nose.tools.eq_(len(set['outputs']), 4)
nose.tools.eq_(len(set['outputs']), 3)
assert set['outputs']['a'] is not None
assert set['outputs']['b'] is not None
assert set['outputs']['sum'] is not None
assert set['outputs']['class'] is not None
#----------------------------------------------------------
......@@ -89,12 +88,11 @@ def test_load_protocol_with_two_sets():
set = database.set("two_sets", "double")
nose.tools.eq_(set['name'], 'double')
nose.tools.eq_(len(set['outputs']), 4)
nose.tools.eq_(len(set['outputs']), 3)
assert set['outputs']['a'] is not None
assert set['outputs']['b'] is not None
assert set['outputs']['sum'] is not None
assert set['outputs']['class'] is not None
set = database.set("two_sets", "triple")
......
......@@ -121,9 +121,26 @@ class TestDatabaseViewRunner(unittest.TestCase):
view.setup(os.path.join(self.cache_root, 'data.db'))
self.assertTrue(view.data_sources is not None)
self.assertEqual(len(view.data_sources), 4)
self.assertEqual(len(view.data_sources), 3)
for i in range(0, 9):
self.assertEqual(view.get('a', i)['value'], i + 1)
self.assertEqual(view.get('b', i)['value'], (i + 1) * 10)
self.assertEqual(view.get('sum', i)['value'], (i + 1) * 10 + i + 1)
def test_success_using_keywords(self):
db = Database(prefix, 'python_keyword/1')
self.assertTrue(db.valid)
view = db.view('keyword', 'keyword', MyExc)
view.index(os.path.join(self.cache_root, 'data.db'))
view.setup(os.path.join(self.cache_root, 'data.db'))
self.assertTrue(view.data_sources is not None)
self.assertEqual(len(view.data_sources), 3)
for i in range(0, 9):
self.assertEqual(view.get('class', i)['value'], i + 1)
self.assertEqual(view.get('def', i)['value'], (i + 1) * 10)
self.assertEqual(view.get('sum', i)['value'], (i + 1) * 10 + i + 1)
Markdown is supported
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