|
@@ -9,6 +9,7 @@ from kalliope.core.Models import Neuron
|
|
|
from kalliope.core.Models import Synapse
|
|
|
from kalliope.core.Models import Order
|
|
|
from kalliope.core.Models.Brain import Brain
|
|
|
+from kalliope.core.Models.Settings import Settings
|
|
|
|
|
|
|
|
|
class TestBrainLoader(unittest.TestCase):
|
|
@@ -63,12 +64,37 @@ class TestBrainLoader(unittest.TestCase):
|
|
|
self.assertEqual(brain, brain_loader.brain)
|
|
|
|
|
|
def test_get_neurons(self):
|
|
|
+ """
|
|
|
+ Test to get neurons from the brainLoader
|
|
|
+ scenarii:
|
|
|
+ - 1/ get a simple neuron from the brainloader
|
|
|
+ - 2/ get a neuron with global variables as parameters
|
|
|
+ """
|
|
|
+ # 1/ get a simple neuron from the brainloader
|
|
|
+ st = Settings()
|
|
|
neuron_list = [{'say': {'message': ['test message']}}]
|
|
|
|
|
|
neuron = Neuron(name='say', parameters={'message': ['test message']})
|
|
|
|
|
|
bl = BrainLoader(file_path=self.brain_to_test)
|
|
|
- neurons_from_brain_loader = bl._get_neurons(neuron_list)
|
|
|
+ neurons_from_brain_loader = bl._get_neurons(neuron_list,
|
|
|
+ settings=st)
|
|
|
+
|
|
|
+ self.assertEqual([neuron], neurons_from_brain_loader)
|
|
|
+
|
|
|
+ # 2/ get a neuron with global variables as parameters
|
|
|
+ neuron_list = [{'say': {'message': ['bonjour {{name}}']}}]
|
|
|
+ variables = {
|
|
|
+ "author": "Lamonf",
|
|
|
+ "test_number": 60,
|
|
|
+ "name": "kalliope"
|
|
|
+ }
|
|
|
+ st = Settings(variables=variables)
|
|
|
+ bl = BrainLoader(file_path=self.brain_to_test)
|
|
|
+ neurons_from_brain_loader = bl._get_neurons(neuron_list,
|
|
|
+ settings=st)
|
|
|
+
|
|
|
+ neuron = Neuron(name='say', parameters={'message': ['bonjour kalliope']})
|
|
|
|
|
|
self.assertEqual([neuron], neurons_from_brain_loader)
|
|
|
|
|
@@ -103,5 +129,131 @@ class TestBrainLoader(unittest.TestCase):
|
|
|
|
|
|
self.assertTrue(bl1.brain is bl2.brain)
|
|
|
|
|
|
+ def test_replace_global_variables(self):
|
|
|
+ """
|
|
|
+ Testing the _replace_global_variables function from the NeuronLauncher.
|
|
|
+ Scenarii:
|
|
|
+ - 1/ only one global variable
|
|
|
+ - 2/ global variable with string after
|
|
|
+ - 3/ global variable with int after
|
|
|
+ - 4/ multiple global variables
|
|
|
+ - 5/ parameter value is a list
|
|
|
+
|
|
|
+ """
|
|
|
+
|
|
|
+ # 1/ only one global variable
|
|
|
+ parameters={
|
|
|
+ 'var1': '{{hello}}'
|
|
|
+ }
|
|
|
+
|
|
|
+ variables = {
|
|
|
+ "hello": "test",
|
|
|
+ "hello2": "test2",
|
|
|
+ }
|
|
|
+ st = Settings(variables=variables)
|
|
|
+
|
|
|
+ expected_parameters={
|
|
|
+ 'var1': 'test'
|
|
|
+ }
|
|
|
+
|
|
|
+ self.assertEquals(BrainLoader._replace_global_variables(parameters=parameters,
|
|
|
+ settings=st),
|
|
|
+ expected_parameters,
|
|
|
+ "Fail to assign a single global variable to parameters")
|
|
|
+
|
|
|
+ # 2/ global variable with string after
|
|
|
+ parameters={
|
|
|
+ 'var1': '{{hello}} Sispheor'
|
|
|
+ }
|
|
|
+ variables = {
|
|
|
+ "hello": "test",
|
|
|
+ "hello2": "test2",
|
|
|
+ }
|
|
|
+ st = Settings(variables=variables)
|
|
|
+
|
|
|
+ expected_parameters = {
|
|
|
+ 'var1': 'test Sispheor'
|
|
|
+ }
|
|
|
+
|
|
|
+ self.assertEquals(BrainLoader._replace_global_variables(parameters=parameters,
|
|
|
+ settings=st),
|
|
|
+ expected_parameters,
|
|
|
+ "Fail to assign a global variable with string after to parameters")
|
|
|
+
|
|
|
+ # 3/ global variable with int after
|
|
|
+ parameters={
|
|
|
+ 'var1': '{{hello}}0'
|
|
|
+ }
|
|
|
+ variables = {
|
|
|
+ "hello": 60,
|
|
|
+ "hello2": "test2",
|
|
|
+ }
|
|
|
+ st = Settings(variables=variables)
|
|
|
+
|
|
|
+ expected_parameters={
|
|
|
+ 'var1': '600'
|
|
|
+ }
|
|
|
+
|
|
|
+ self.assertEquals(BrainLoader._replace_global_variables(parameters=parameters,
|
|
|
+ settings=st),
|
|
|
+ expected_parameters,
|
|
|
+ "Fail to assign global variable with int after to parameters")
|
|
|
+
|
|
|
+ # 4/ multiple global variables
|
|
|
+ parameters={
|
|
|
+ 'var1': '{{hello}} {{me}}'
|
|
|
+ }
|
|
|
+ variables = {
|
|
|
+ "hello": "hello",
|
|
|
+ "me": "LaMonf"
|
|
|
+ }
|
|
|
+ st = Settings(variables=variables)
|
|
|
+
|
|
|
+ expected_parameters={
|
|
|
+ 'var1': 'hello LaMonf'
|
|
|
+ }
|
|
|
+
|
|
|
+ self.assertEquals(BrainLoader._replace_global_variables(parameters=parameters,
|
|
|
+ settings=st),
|
|
|
+ expected_parameters,
|
|
|
+ "Fail to assign multiple global variables to parameters")
|
|
|
+
|
|
|
+ # 5/ parameter value is a list
|
|
|
+ parameters={
|
|
|
+ 'var1': '[hello {{name}}, bonjour {{name}}]'
|
|
|
+ }
|
|
|
+ variables = {
|
|
|
+ "name": "LaMonf",
|
|
|
+ "hello2": "test2",
|
|
|
+ }
|
|
|
+ st = Settings(variables=variables)
|
|
|
+
|
|
|
+ expected_parameters={
|
|
|
+ 'var1': '[hello LaMonf, bonjour LaMonf]'
|
|
|
+ }
|
|
|
+
|
|
|
+ self.assertEquals(BrainLoader._replace_global_variables(parameters=parameters,
|
|
|
+ settings=st),
|
|
|
+ expected_parameters,
|
|
|
+ "Fail to assign a single global when parameter value is a list to neuron")
|
|
|
+
|
|
|
+ def test_get_global_variable(self):
|
|
|
+ """
|
|
|
+ Test the get_global_variable of the OrderAnalyser Class
|
|
|
+ """
|
|
|
+ sentence = "i am {{name2}}"
|
|
|
+ variables = {
|
|
|
+ "name": "LaMonf",
|
|
|
+ "name2": "kalliope",
|
|
|
+ }
|
|
|
+ st = Settings(variables=variables)
|
|
|
+
|
|
|
+ expected_result = "i am kalliope"
|
|
|
+
|
|
|
+ self.assertEquals(BrainLoader._get_global_variable(sentence=sentence,
|
|
|
+ settings=st),
|
|
|
+ expected_result,
|
|
|
+ "Fail to get the global variable from the sentence")
|
|
|
+
|
|
|
if __name__ == '__main__':
|
|
|
unittest.main()
|