浏览代码

[Test] Add first raw of tests for NeuronModules

monf 8 年之前
父节点
当前提交
cdd12d2323
共有 2 个文件被更改,包括 66 次插入7 次删除
  1. 59 0
      Tests/test_neuron_module.py
  2. 7 7
      kalliope/core/NeuronModule.py

+ 59 - 0
Tests/test_neuron_module.py

@@ -0,0 +1,59 @@
+import unittest
+import mock
+
+from kalliope.core.NeuronModule import NeuronModule
+
+
+class TestNeuronModule(unittest.TestCase):
+
+    def setUp(self):
+        pass
+
+    def tearDown(self):
+        pass
+
+    def test_get_audio_from_stt(self):
+        """
+        Test the OrderListener thread is started
+        """
+
+        with mock.patch("kalliope.core.OrderListener.start") as mock_orderListerner_start:
+            def callback():
+                pass
+            NeuronModule.get_audio_from_stt(callback=callback())
+            mock_orderListerner_start.assert_called_once_with()
+            mock_orderListerner_start.reset_mock()
+
+    def test_update_cache_var(self):
+        """
+        Test Update the value of the cache in the provided arg list
+        """
+
+        # True -> False
+        args_dict = {
+            "cache": True
+        }
+        expected_dict = {
+            "cache": False
+        }
+        self.assertEquals(NeuronModule._update_cache_var(False, args_dict=args_dict),
+                          expected_dict,
+                          "Fail to update the cache value from True to False")
+        self.assertFalse(args_dict["cache"])
+
+        # False -> True
+        args_dict = {
+            "cache": False
+        }
+        expected_dict = {
+            "cache": True
+        }
+        self.assertEquals(NeuronModule._update_cache_var(True, args_dict=args_dict),
+                          expected_dict,
+                          "Fail to update the cache value from False to True")
+
+        self.assertTrue(args_dict["cache"])
+
+
+
+

+ 7 - 7
kalliope/core/NeuronModule.py

@@ -189,17 +189,17 @@ class NeuronModule(object):
             return content_file.read()
 
     @staticmethod
-    def _update_cache_var(new_override_cache, args_list):
+    def _update_cache_var(new_override_cache, args_dict):
         """
         update the value for the key "cache" in the dict args_list
-        :param new_override_cache: cache bolean to set in place of the current one in args_list
-        :param args_list: arg list that contain "cache" to update
+        :param new_override_cache: cache boolean to set in place of the current one in args_list
+        :param args_dict: arg list that contain "cache" to update
         :return:
         """
-        logger.debug("args for TTS plugin before update: %s" % str(args_list))
-        args_list["cache"] = new_override_cache
-        logger.debug("args for TTS plugin after update: %s" % str(args_list))
-        return args_list
+        logger.debug("args for TTS plugin before update: %s" % str(args_dict))
+        args_dict["cache"] = new_override_cache
+        logger.debug("args for TTS plugin after update: %s" % str(args_dict))
+        return args_dict
 
     @staticmethod
     def get_audio_from_stt(callback):