Browse Source

[Tests] adding tests to the new methods coming from the previous refactor

monf 8 years ago
parent
commit
0018003a3d
2 changed files with 58 additions and 4 deletions
  1. 6 4
      core/OrderAnalyser.py
  2. 52 0
      core/Tests/test_order_analyser.py

+ 6 - 4
core/OrderAnalyser.py

@@ -31,7 +31,6 @@ class OrderAnalyser:
         logger.debug("OrderAnalyser, Received order: %s" % self.order)
 
     def start(self):
-        # TODO : refactor this method !!
         """
         This method matches the incoming messages to the signals/order sentences provided in the Brain
         """
@@ -53,10 +52,11 @@ class OrderAnalyser:
     @classmethod
     def _get_matching_synapse_list(cls, all_synapses_list, order_to_match):
         """
-            Class method to return all the matching synapses with the order from the complete of synapses.
+        Class method to return all the matching synapses with the order from the complete of synapses.
 
         :param all_synapses_list: the complete list of all synapses
         :param order_to_match: the order to match
+        :type order_to_check: str
         :return: the list of matching synapses
         """
         matching_synapses_list = list()
@@ -72,10 +72,11 @@ class OrderAnalyser:
     @classmethod
     def _get_synapse_params(cls, synapse, order_to_check):
         """
-            Class method to get all params comming from a synapse. Returns a dict of key/value.
+        Class method to get all params coming from a synapse. Returns a dict of key/value.
 
         :param synapse: the synapse to check
         :param order_to_check: the order to match
+        :type order_to_check: str
         :return: the dict key/value
         """
         params = dict()
@@ -88,7 +89,8 @@ class OrderAnalyser:
     @classmethod
     def _start_neuron(cls, neuron, params):
         """
-            Associate params and Starts a neuron.
+        Associate params and Starts a neuron.
+
         :param neuron: the neuron to start
         :param params: the params to check and associate to the neuron args.
         """

+ 52 - 0
core/Tests/test_order_analyser.py

@@ -2,6 +2,9 @@ import unittest
 
 
 from core.OrderAnalyser import OrderAnalyser
+from core.Models.Neuron import Neuron
+from core.Models.Synapse import Synapse
+from core.Models.Order import Order
 
 
 class TestOrderAnalyser(unittest.TestCase):
@@ -190,5 +193,54 @@ class TestOrderAnalyser(unittest.TestCase):
        self.assertEqual(OrderAnalyser._associate_order_params_to_values(order_user,order_brain), expected_result,
                         "Fail to match the order_brain multiple variables with multiple words as values'")
 
+
+    def test_get_matching_synapse_list(self):
+        # 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="this is 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})
+
+        order_to_match = "this is the sentence"
+        all_synapse_list = [synapse1,
+                            synapse2,
+                            synapse3]
+
+        expected_result = [synapse1]
+
+        # Success
+        self.assertEquals(OrderAnalyser._get_matching_synapse_list(all_synapses_list=all_synapse_list, order_to_match=order_to_match),
+                          expected_result,
+                          "Fail matching the expected synapse from the complete synapse list and the order")
+
+        # TODO : to be continued
+
+    def test_get_synapse_params(self):
+        # Init
+        neuron1 = Neuron(name='neurone1', parameters={'var1': 'val1'})
+        neuron2 = Neuron(name='neurone2', parameters={'var2': 'val2'})
+
+        signal1 = Order(sentence="this is the {{ sentence }}")
+
+        synapse1 = Synapse(name="Synapse1", neurons={neuron1, neuron2}, signals={signal1})
+
+        order_to_check = "this is the value"
+        expected_resut = {'sentence':'value'}
+
+        self.assertEquals(OrderAnalyser._get_synapse_params(synapse=synapse1, order_to_check=order_to_check),
+                          expected_resut,
+                          "Fail to retrieve the params of the synapse from the order")
+
+        # TODO : to be continued
+
+
 if __name__ == '__main__':
     unittest.main()