Browse Source

[Test] Provide new test for the neuron Launcher

monf 8 years ago
parent
commit
34fb432719
1 changed files with 53 additions and 1 deletions
  1. 53 1
      Tests/test_neuron_launcher.py

+ 53 - 1
Tests/test_neuron_launcher.py

@@ -18,7 +18,7 @@ class TestNeuronLauncher(unittest.TestCase):
 
     ####
     # Neurons Launcher
-    def test_start_neuron(self):
+    def test_launch_neuron(self):
         """
         Test the Neuron Launcher trying to start a Neuron
         """
@@ -35,4 +35,56 @@ class TestNeuronLauncher(unittest.TestCase):
                                                                  resources_dir=sl.settings.resources.neuron_folder)
             mock_get_class_instantiation.reset_mock()
 
+    def test_start_neuron(self):
+        """
+        Testing params association and starting a Neuron
+        """
+
+        with mock.patch("kalliope.core.NeuronLauncher.launch_neuron") as mock_launch_neuron_method:
+            # Assert to the neuron is launched
+            neuron1 = Neuron(name='neurone1', parameters={'var1': 'val1'})
+            params = {
+                'param1':'parval1'
+            }
+            NeuronLauncher.start_neuron(neuron=neuron1,
+                                        parameters_dict=params)
+            mock_launch_neuron_method.assert_called_with(neuron1)
+            mock_launch_neuron_method.reset_mock()
+
+            # Assert the params are well passed to the neuron
+            neuron2 = Neuron(name='neurone2', parameters={'var2': 'val2', 'args': ['arg1', 'arg2']})
+            params = {
+                'arg1':'argval1',
+                'arg2':'argval2'
+            }
+            NeuronLauncher.start_neuron(neuron=neuron2,
+                                        parameters_dict=params)
+            neuron2_params = Neuron(name='neurone2',
+                                    parameters={'var2': 'val2',
+                                                'args': ['arg1', 'arg2'],
+                                                'arg1':'argval1',
+                                                'arg2':'argval2'}
+                                    )
+            mock_launch_neuron_method.assert_called_with(neuron2_params)
+            mock_launch_neuron_method.reset_mock()
+
+            # Assert the Neuron is not started when missing args
+            neuron3 = Neuron(name='neurone3', parameters={'var3': 'val3', 'args': ['arg3', 'arg4']})
+            params = {
+                'arg1': 'argval1',
+                'arg2': 'argval2'
+            }
+            NeuronLauncher.start_neuron(neuron=neuron3,
+                                        parameters_dict=params)
+            mock_launch_neuron_method.assert_not_called()
+            mock_launch_neuron_method.reset_mock()
+
+            # Assert no neuron is launched when waiting for args and none are given
+            neuron4 = Neuron(name='neurone4', parameters={'var4': 'val4', 'args': ['arg5', 'arg6']})
+            params = {}
+            NeuronLauncher.start_neuron(neuron=neuron4,
+                                        parameters_dict=params)
+            mock_launch_neuron_method.assert_not_called()
+            mock_launch_neuron_method.reset_mock()
+