|
@@ -1,28 +1,39 @@
|
|
|
+import os
|
|
|
import unittest
|
|
|
import mock
|
|
|
|
|
|
-from kalliope.core.NeuronModule import NeuronModule
|
|
|
+from kalliope.core.NeuronModule import NeuronModule, TemplateFileNotFoundException
|
|
|
|
|
|
|
|
|
class TestNeuronModule(unittest.TestCase):
|
|
|
|
|
|
def setUp(self):
|
|
|
- pass
|
|
|
+ self.expected_result = "hello, this is a replaced word"
|
|
|
+
|
|
|
+ if "/Tests" in os.getcwd():
|
|
|
+ self.file_template = "templates/template_test.j2"
|
|
|
+ else:
|
|
|
+ self.file_template = "Tests/templates/template_test.j2"
|
|
|
+ self.say_template = "hello, this is a {{ test }}"
|
|
|
+ self.message = {
|
|
|
+ "test": "replaced word"
|
|
|
+ }
|
|
|
+ self.neuron_module_test = NeuronModule()
|
|
|
|
|
|
def tearDown(self):
|
|
|
- pass
|
|
|
+ del self.neuron_module_test
|
|
|
|
|
|
def test_get_audio_from_stt(self):
|
|
|
"""
|
|
|
Test the OrderListener thread is started
|
|
|
"""
|
|
|
|
|
|
- with mock.patch("kalliope.core.OrderListener.start") as mock_orderListerner_start:
|
|
|
+ with mock.patch("kalliope.core.OrderListener.start") as mock_orderListener_start:
|
|
|
def callback():
|
|
|
pass
|
|
|
NeuronModule.get_audio_from_stt(callback=callback())
|
|
|
- mock_orderListerner_start.assert_called_once_with()
|
|
|
- mock_orderListerner_start.reset_mock()
|
|
|
+ mock_orderListener_start.assert_called_once_with()
|
|
|
+ mock_orderListener_start.reset_mock()
|
|
|
|
|
|
def test_update_cache_var(self):
|
|
|
"""
|
|
@@ -54,6 +65,45 @@ class TestNeuronModule(unittest.TestCase):
|
|
|
|
|
|
self.assertTrue(args_dict["cache"])
|
|
|
|
|
|
+ def test_get_message_from_dict(self):
|
|
|
+
|
|
|
+ self.neuron_module_test.say_template = self.say_template
|
|
|
+
|
|
|
+ self.assertEqual(self.neuron_module_test._get_message_from_dict(self.message), self.expected_result)
|
|
|
+ del self.neuron_module_test
|
|
|
+ self.neuron_module_test = NeuronModule()
|
|
|
+
|
|
|
+
|
|
|
+ self.neuron_module_test.file_template = self.file_template
|
|
|
+ self.assertEqual(self.neuron_module_test._get_message_from_dict(self.message), self.expected_result)
|
|
|
+ del self.neuron_module_test
|
|
|
+
|
|
|
+
|
|
|
+ self.neuron_module_test = NeuronModule()
|
|
|
+ self.assertEqual(self.neuron_module_test._get_message_from_dict(self.message), None)
|
|
|
+
|
|
|
+ def test_get_say_template(self):
|
|
|
+
|
|
|
+ self.assertEqual(NeuronModule._get_say_template(self.say_template, self.message), self.expected_result)
|
|
|
+
|
|
|
+
|
|
|
+ say_template = list()
|
|
|
+ say_template.append("hello, this is a {{ test }} one")
|
|
|
+ say_template.append("hello, this is a {{ test }} two")
|
|
|
+ expected_result = list()
|
|
|
+ expected_result.append("hello, this is a replaced word one")
|
|
|
+ expected_result.append("hello, this is a replaced word two")
|
|
|
+ self.assertTrue(NeuronModule._get_say_template(say_template, self.message) in expected_result)
|
|
|
|
|
|
+ def test_get_file_template(self):
|
|
|
+
|
|
|
+ self.assertEqual(NeuronModule._get_file_template(self.file_template, self.message), self.expected_result)
|
|
|
|
|
|
+
|
|
|
+ file_template = "does_not_exist.j2"
|
|
|
+ with self.assertRaises(TemplateFileNotFoundException):
|
|
|
+ NeuronModule._get_file_template(file_template, self.message)
|
|
|
|
|
|
+ def test_get_content_of_file(self):
|
|
|
+ expected_result = "hello, this is a {{ test }}"
|
|
|
+ self.assertEqual(NeuronModule._get_content_of_file(self.file_template), expected_result)
|