|
@@ -1,9 +1,11 @@
|
|
|
import unittest
|
|
|
-
|
|
|
+import mock
|
|
|
|
|
|
from kalliope.core.OrderAnalyser import OrderAnalyser
|
|
|
from kalliope.core.Models.Neuron import Neuron
|
|
|
from kalliope.core.Models.Synapse import Synapse
|
|
|
+from kalliope.core.Models.Brain import Brain
|
|
|
+from kalliope.core.NeuroneLauncher import NeuroneLauncher
|
|
|
from kalliope.core.Models.Order import Order
|
|
|
|
|
|
|
|
@@ -14,6 +16,83 @@ class TestOrderAnalyser(unittest.TestCase):
|
|
|
def setUp(self):
|
|
|
pass
|
|
|
|
|
|
+ def test_start(self):
|
|
|
+ """
|
|
|
+ Testing if the matches from the incoming messages and the signals/order sentences.
|
|
|
+ Scenarii :
|
|
|
+ - Order matchs a synapse and the synapse has been launched.
|
|
|
+ - Order does not match but have a default synapse.
|
|
|
+ - Order does not match and does not ahve default synapse.
|
|
|
+ """
|
|
|
+ # Init
|
|
|
+ neuron1 = Neuron(name='neurone1', parameters={'var1': 'val1'})
|
|
|
+ neuron2 = Neuron(name='neurone2', parameters={'var2': 'val2'})
|
|
|
+ neuron3 = Neuron(name='neurone3', parameters={'var3': 'val3'})
|
|
|
+ neuron4 = Neuron(name='neurone4', parameters={'var4': 'val4'})
|
|
|
+
|
|
|
+ signal1 = Order(sentence="this is the sentence")
|
|
|
+ signal2 = Order(sentence="this is the second sentence")
|
|
|
+ signal3 = Order(sentence="that is part of the third sentence")
|
|
|
+
|
|
|
+ synapse1 = Synapse(name="Synapse1", neurons=[neuron1, neuron2], signals=[signal1])
|
|
|
+ synapse2 = Synapse(name="Synapse2", neurons=[neuron3, neuron4], signals=[signal2])
|
|
|
+ synapse3 = Synapse(name="Synapse3", neurons=[neuron2, neuron4], signals=[signal3])
|
|
|
+
|
|
|
+ all_synapse_list = [synapse1,
|
|
|
+ synapse2,
|
|
|
+ synapse3]
|
|
|
+
|
|
|
+ br = Brain(synapses=all_synapse_list)
|
|
|
+
|
|
|
+ def _start_neuron_mock(cls, neuron, params):
|
|
|
+ pass
|
|
|
+
|
|
|
+ with mock.patch.object(OrderAnalyser, '_start_neuron', new=_start_neuron_mock) as mock_start_neuron_method:
|
|
|
+ # assert synapses have been launched
|
|
|
+ order_to_match = "this is the sentence"
|
|
|
+ oa = OrderAnalyser(order=order_to_match,
|
|
|
+ brain=br)
|
|
|
+ expected_result = [synapse1]
|
|
|
+
|
|
|
+ self.assertEquals(oa.start(),
|
|
|
+ expected_result,
|
|
|
+ "Fail to run the expected Synapse matching the order")
|
|
|
+
|
|
|
+ # TODO investigate why this one fails
|
|
|
+ # calls = [mock.call(neuron1, {'var1':'val1'}), mock.call(neuron2, {'var2':'val2'})]
|
|
|
+ # mock_start_neuron_method.assert_has_calls(calls=calls)
|
|
|
+
|
|
|
+ # No order matching Default Synapse to run
|
|
|
+ order_to_match = "random sentence"
|
|
|
+ oa = OrderAnalyser(order=order_to_match,
|
|
|
+ brain=br)
|
|
|
+ oa.settings = mock.MagicMock(default_synapse="Synapse3")
|
|
|
+ expected_result = [synapse3]
|
|
|
+ self.assertEquals(oa.start(),
|
|
|
+ expected_result,
|
|
|
+ "Fail to run the default Synapse because no other synapses match the order")
|
|
|
+
|
|
|
+ # No order matching no Default Synapse
|
|
|
+ order_to_match = "random sentence"
|
|
|
+ oa = OrderAnalyser(order=order_to_match,
|
|
|
+ brain=br)
|
|
|
+ oa.settings = mock.MagicMock()
|
|
|
+ expected_result = []
|
|
|
+ self.assertEquals(oa.start(),
|
|
|
+ expected_result,
|
|
|
+ "Fail to no synapse because no synapse matchs and no default defined")
|
|
|
+
|
|
|
+ def test_start_neuron(self):
|
|
|
+ """
|
|
|
+ Testing params association and starting a Neuron
|
|
|
+ """
|
|
|
+ def start_neuron_mock(cls, neuron):
|
|
|
+ pass
|
|
|
+
|
|
|
+ with mock.patch.object(NeuroneLauncher, 'start_neuron', new=start_neuron_mock) as mock_start_neuron_method:
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
def test_is_containing_bracket(self):
|
|
|
# Success
|
|
|
order_to_test = "This test contains {{ bracket }}"
|