浏览代码

update tests for neuron module

nico 8 年之前
父节点
当前提交
5805332f70
共有 5 个文件被更改,包括 18 次插入25 次删除
  1. 1 1
      Tests/__init__.py
  2. 0 0
      Tests/backup_test_order_analyser.py
  3. 15 16
      Tests/test_neuron_module.py
  4. 0 7
      Tests/test_order_analyser2.py
  5. 2 1
      kalliope/core/NeuronModule.py

+ 1 - 1
Tests/__init__.py

@@ -2,7 +2,7 @@ from test_brain_loader import TestBrainLoader
 from test_configuration_checker import TestConfigurationChecker
 from test_dynamic_loading import TestDynamicLoading
 from test_file_manager import TestFileManager
-from test_order_analyser import TestOrderAnalyser
+# from test_order_analyser import TestOrderAnalyser
 from test_rest_api import TestRestAPI
 from test_settings_loader import TestSettingLoader
 from test_singleton import TestSingleton

+ 0 - 0
Tests/test_order_analyser.py → Tests/backup_test_order_analyser.py


+ 15 - 16
Tests/test_neuron_module.py

@@ -145,31 +145,30 @@ class TestNeuronModule(unittest.TestCase):
         order = "This is the order"
         synapse_name = "Synapse2"
         answer = "This is the {{ answer }}"
+        expected_parameter = {"answer": "order"}
 
-        with mock.patch("kalliope.core.OrderAnalyser.start") as mock_orderAnalyser_start:
+        with mock.patch("kalliope.core.NeuronLauncher.start_neuron_list") as mock_NeuronLauncher_start:
             neuron_mod = NeuronModule()
             neuron_mod.brain = br
 
-            # Success
-            self.assertTrue(neuron_mod.run_synapse_by_name_with_order(order=order,
-                                                                        synapse_name=synapse_name,
-                                                                        order_template=answer),
-                              "fail to find the proper synapse")
+            # Success, run synapse 1
+            launched_synapse = neuron_mod.run_synapse_by_name_with_order(order=order,
+                                                                         synapse_name=synapse_name,
+                                                                         order_template=answer)
+            self.assertEqual(synapse2, launched_synapse)
 
-            # mock_orderAnalyser_start.assert_called_once()
-            mock_orderAnalyser_start.assert_called_once_with(synapses_to_run=[synapse2],
-                                                             external_order=answer)
-            mock_orderAnalyser_start.reset_mock()
+            mock_NeuronLauncher_start.assert_called_once_with(neuron_list=[neuron3, neuron4],
+                                                              parameters_dict=expected_parameter)
+            mock_NeuronLauncher_start.reset_mock()
 
             # Fail
             synapse_name = "Synapse5"
-            self.assertFalse(neuron_mod.run_synapse_by_name_with_order(order=order,
-                                                                      synapse_name=synapse_name,
-                                                                       order_template=answer),
-                            "fail to NOT find the synapse")
+            self.assertIsNone(neuron_mod.run_synapse_by_name_with_order(order=order,
+                                                                        synapse_name=synapse_name,
+                                                                        order_template=answer))
 
-            mock_orderAnalyser_start.assert_not_called()
-            mock_orderAnalyser_start.reset_mock()
+            mock_NeuronLauncher_start.assert_not_called()
+            mock_NeuronLauncher_start.reset_mock()
 
 
 

+ 0 - 7
Tests/test_order_analyser2.py

@@ -1,20 +1,13 @@
 import unittest
 
-import logging
 
 from kalliope.core.Models import Brain
 from kalliope.core.Models import Neuron
 from kalliope.core.Models import Order
 from kalliope.core.Models import Synapse
-from kalliope.core.Models.Settings import Settings
 from kalliope.core.OrderAnalyser2 import OrderAnalyser2
 
 
-logging.basicConfig()
-logger = logging.getLogger("kalliope")
-logger.setLevel(logging.DEBUG)
-
-
 class TestOrderAnalyser2(unittest.TestCase):
 
     """Test case for the OrderAnalyser Class"""

+ 2 - 1
kalliope/core/NeuronModule.py

@@ -210,6 +210,7 @@ class NeuronModule(object):
             list_to_run = list()
             list_to_run.append(synapse_to_run)
 
+            # load parameters from the answer
             parameters = None
             for signal in synapse_to_run.signals:
                 if isinstance(signal, Order):
@@ -225,7 +226,7 @@ class NeuronModule(object):
         else:
             logger.debug("[NeuronModule]-> run_synapse_by_name_with_order, the synapse has not been found : %s"
                          % synapse_name)
-        return synapse_to_run is not None
+        return synapse_to_run
 
     @staticmethod
     def _get_content_of_file(real_file_template_path):