def test_get_neurons(self): """ Test to get neurons from the brainLoader scenarii: - 1/ get a simple neuron from the brainloader - 2/ get a neuron with global variables as parameters """ # 1/ get a simple neuron from the brainloader st = Settings() neuron_list = [{'say': {'message': ['test message']}}] neuron = Neuron(name='say', parameters={'message': ['test message']}) bl = BrainLoader(file_path=self.brain_to_test) neurons_from_brain_loader = bl._get_neurons(neuron_list, settings=st) self.assertEqual([neuron], neurons_from_brain_loader) # 2/ get a neuron with global variables as parameters neuron_list = [{'say': {'message': ['bonjour {{name}}']}}] variables = {"author": "Lamonf", "test_number": 60, "name": "kalliope"} st = Settings(variables=variables) bl = BrainLoader(file_path=self.brain_to_test) neurons_from_brain_loader = bl._get_neurons(neuron_list, settings=st) neuron = Neuron(name='say', parameters={'message': ['bonjour kalliope']}) self.assertEqual([neuron], neurons_from_brain_loader)
def test_get_player(self): """ Test the PlayerLauncher trying to run the Player """ player1 = Player("Player", {}) player2 = Player("Player2", {'test': "hitheparamtest"}) settings = Settings() settings.players = [player1, player2] with mock.patch("kalliope.core.Utils.get_dynamic_class_instantiation" ) as mock_get_class_instantiation: # Get the player1 settings.default_player_name = "Player" PlayerLauncher.get_player(settings=settings) mock_get_class_instantiation.assert_called_once_with( package_name="players", module_name=player1.name, parameters=player1.parameters) mock_get_class_instantiation.reset_mock() # Get the player 2 settings.default_player_name = "Player2" PlayerLauncher.get_player(settings=settings) mock_get_class_instantiation.assert_called_once_with( package_name="players", module_name=player2.name, parameters=player2.parameters) mock_get_class_instantiation.reset_mock()
def test_get_global_variable(self): """ Test the get_global_variable of the OrderAnalyser Class """ sentence = "i am {{name2}}" variables = { "name": "LaMonf", "name2": "kalliope", "name3": u"kalliopé", "name4": 1 } st = Settings(variables=variables) expected_result = "i am kalliope" self.assertEqual(BrainLoader._get_global_variable(sentence=sentence, settings=st), expected_result) # test with accent sentence = "i am {{name3}}" expected_result = u"i am kalliopé" self.assertEqual(BrainLoader._get_global_variable(sentence=sentence, settings=st), expected_result) # test with int sentence = "i am {{name4}}" expected_result = "i am 1" self.assertEqual(BrainLoader._get_global_variable(sentence=sentence, settings=st), expected_result)
def setUp(self): # Kill the singleton Singleton._instances = dict() # 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="that is part of the third sentence") self.synapse1 = Synapse(name="Synapse1", neurons=[neuron1, neuron2], signals=[signal1]) self.synapse2 = Synapse(name="Synapse2", neurons=[neuron3, neuron4], signals=[signal2]) self.synapse3 = Synapse(name="Synapse3", neurons=[neuron2, neuron4], signals=[signal3]) self.all_synapse_list1 = [self.synapse1, self.synapse2, self.synapse3] self.all_synapse_list2 = [self.synapse2, self.synapse3] self.brain_test1 = Brain(synapses=self.all_synapse_list1) self.brain_test2 = Brain(synapses=self.all_synapse_list2) # this brain is the same as the first one self.brain_test3 = Brain(synapses=self.all_synapse_list1) self.settings_test = Settings(default_synapse="Synapse3") # clean the LiFO LIFOBuffer.lifo_list = list()
def setUp(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 = Signal(name="order", parameters="this is the sentence") signal2 = Signal(name="order", parameters="this is the second sentence") signal3 = Signal(name="order", parameters="that is part of the third sentence") self.synapse1 = Synapse(name="Synapse1", neurons=[neuron1, neuron2], signals=[signal1]) self.synapse2 = Synapse(name="Synapse2", neurons=[neuron3, neuron4], signals=[signal2]) self.synapse3 = Synapse(name="Synapse3", neurons=[neuron2, neuron4], signals=[signal3]) self.all_synapse_list = [self.synapse1, self.synapse2, self.synapse3] self.brain_test = Brain(synapses=self.all_synapse_list) self.settings_test = Settings(default_synapse="Synapse3") # clean the LiFO Singleton._instances = dict()
def test_get_settings(self): settings_object = Settings() settings_object.default_tts_name = "pico2wave" settings_object.default_stt_name = "google" settings_object.default_trigger_name = "snowboy" tts1 = Tts(name="pico2wave", parameters={ 'cache': True, 'language': 'fr-FR' }) tts2 = Tts(name="voxygen", parameters={ 'voice': 'Agnes', 'cache': True }) settings_object.ttss = [tts1, tts2] stt = Stt(name="google", parameters={'language': 'fr-FR'}) settings_object.stts = [stt] settings_object.random_wake_up_answers = ['Oui monsieur?'] settings_object.random_wake_up_sounds = [ 'sounds/ding.wav', 'sounds/dong.wav' ] settings_object.play_on_ready_notification = "never" settings_object.on_ready_answers = ['Kalliope is ready'] settings_object.on_ready_sounds = [ 'sounds/ding.wav', 'sounds/dong.wav' ] trigger1 = Trigger( name="snowboy", parameters={ 'pmdl_file': 'trigger/snowboy/resources/kalliope-FR-6samples.pmdl' }) settings_object.triggers = [trigger1] settings_object.rest_api = RestAPI(password_protected=True, active=True, login="******", password="******", port=5000, allowed_cors_origin=False) settings_object.cache_path = '/tmp/kalliope_tts_cache' settings_object.default_synapse = 'Default-synapse' resources = Resources( neuron_folder="/tmp/kalliope/tests/kalliope_resources_dir/neurons", stt_folder="/tmp/kalliope/tests/kalliope_resources_dir/stt", tts_folder="/tmp/kalliope/tests/kalliope_resources_dir/tts", trigger_folder="/tmp/kalliope/tests/kalliope_resources_dir/trigger" ) settings_object.resources = resources settings_object.variables = { "author": "Lamonf", "test_number": 60, "test": "kalliope" } settings_object.machine = platform.machine() sl = SettingLoader(file_path=self.settings_file_to_test) self.assertEqual(settings_object, sl.settings)
def _get_settings(self): """ Class Methods which loads default or the provided YAML file and return a Settings Object :return: The loaded Settings :rtype: Settings :Example: settings = SettingLoader.get_settings(file_path="/var/tmp/settings.yml") .. seealso:: Settings .. warnings:: Class Method """ # create a new setting setting_object = Settings() # Get the setting parameters settings = self._get_yaml_config() default_stt_name = self._get_default_speech_to_text(settings) default_tts_name = self._get_default_text_to_speech(settings) default_trigger_name = self._get_default_trigger(settings) stts = self._get_stts(settings) ttss = self._get_ttss(settings) triggers = self._get_triggers(settings) random_wake_up_answers = self._get_random_wake_up_answers(settings) random_wake_up_sound = self._get_random_wake_up_sounds(settings) play_on_ready_notification = self._get_play_on_ready_notification( settings) on_ready_answers = self._get_on_ready_answers(settings) on_ready_sounds = self._get_on_ready_sounds(settings) rest_api = self._get_rest_api(settings) cache_path = self._get_cache_path(settings) default_synapse = self._get_default_synapse(settings) resources = self._get_resources(settings) # Load the setting singleton with the parameters setting_object.default_tts_name = default_tts_name setting_object.default_stt_name = default_stt_name setting_object.default_trigger_name = default_trigger_name setting_object.stts = stts setting_object.ttss = ttss setting_object.triggers = triggers setting_object.random_wake_up_answers = random_wake_up_answers setting_object.random_wake_up_sounds = random_wake_up_sound setting_object.play_on_ready_notification = play_on_ready_notification setting_object.on_ready_answers = on_ready_answers setting_object.on_ready_sounds = on_ready_sounds setting_object.rest_api = rest_api setting_object.cache_path = cache_path setting_object.default_synapse = default_synapse setting_object.resources = resources return setting_object
def test_generate_and_play(self): """ Test to generate and play sound """ def new_play_audio(TTSModule): pass words = "kalliope" with mock.patch.object(TTSModule, 'play_audio', new=new_play_audio): settings = Settings(cache_path="/tmp/kalliope/tests") self.TTSMod.settings = settings # test missing callback with self.assertRaises(TtsGenerateAudioFunctionNotFound): self.TTSMod.generate_and_play(words=words) # Assert Callback is called # no Cache self.TTSMod.cache = False generate_audio_function_from_child = mock.Mock() self.TTSMod.generate_and_play(words=words, generate_audio_function_from_child= generate_audio_function_from_child) generate_audio_function_from_child.assert_called() # with cache True but not existing on system self.TTSMod.cache = True generate_audio_function_from_child = mock.Mock() self.TTSMod.generate_and_play(words=words, generate_audio_function_from_child= generate_audio_function_from_child) generate_audio_function_from_child.assert_called() # with cache True and existing on system # create tmp file tmp_base_path = "/tmp/kalliope/tests/TTSModule/tests/default/" file_path = os.path.join(tmp_base_path, "5c186d1e123be2667fb5fd54640e4fd0.tts") if os.path.isfile(file_path): # Remove the file FileManager.remove_file(file_path) if not os.path.exists(tmp_base_path): os.makedirs(tmp_base_path) FileManager.write_in_file( file_path, "[kalliope-test] test_generate_and_play") self.TTSMod.cache = True generate_audio_function_from_child = mock.Mock() self.TTSMod.generate_and_play(words=words, generate_audio_function_from_child= generate_audio_function_from_child) generate_audio_function_from_child.assert_not_called() # Remove the tmp file FileManager.remove_file(file_path)
def _get_settings(self): """ Class Methods which loads default or the provided YAML file and return a Settings Object :return: The loaded Settings :rtype: Settings :Example: settings = SettingLoader.get_settings(file_path="/var/tmp/settings.yml") .. seealso:: Settings .. warnings:: Class Method """ # create a new setting setting_object = Settings() # Get the setting parameters settings = self._get_yaml_config() default_stt_name = self._get_default_speech_to_text(settings) default_tts_name = self._get_default_text_to_speech(settings) default_trigger_name = self._get_default_trigger(settings) default_player_name = self._get_default_player(settings) stts = self._get_stts(settings) ttss = self._get_ttss(settings) triggers = self._get_triggers(settings) players = self._get_players(settings) rest_api = self._get_rest_api(settings) cache_path = self._get_cache_path(settings) resources = self._get_resources(settings) variables = self._get_variables(settings) recognition_options = self._get_recognition_options(settings) start_options = self._get_start_options(settings) hooks = self._get_hooks(settings) # Load the setting singleton with the parameters setting_object.default_tts_name = default_tts_name setting_object.default_stt_name = default_stt_name setting_object.default_trigger_name = default_trigger_name setting_object.default_player_name = default_player_name setting_object.stts = stts setting_object.ttss = ttss setting_object.triggers = triggers setting_object.players = players setting_object.rest_api = rest_api setting_object.cache_path = cache_path setting_object.resources = resources setting_object.variables = variables setting_object.recognition_options = recognition_options setting_object.start_options = start_options setting_object.hooks = hooks return setting_object
def test_get_path_to_store_audio(self): """ Test the path to store audio """ self.TTSMod.words = "kalliope" settings = Settings(cache_path="/tmp/kalliope/tests") self.TTSMod.settings = settings expected_result = "/tmp/kalliope/tests/TTSModule/tests/default/5c186d1e123be2667fb5fd54640e4fd0.tts" self.assertEquals( self.TTSMod._get_path_to_store_audio(), expected_result, "fail test_get_path_to_store_audio, expected path not corresponding to result" )
def test_get_global_variable(self): """ Test the get_global_variable of the OrderAnalyser Class """ sentence = "i am {{name2}}" variables = { "name": "LaMonf", "name2": "kalliope", } st = Settings(variables=variables) expected_result = "i am kalliope" self.assertEquals( BrainLoader._get_global_variable(sentence=sentence, settings=st), expected_result, "Fail to get the global variable from the sentence")
def test_get_settings(self): settings_object = Settings() settings_object.default_tts_name = "pico2wave" settings_object.default_stt_name = "google" settings_object.default_trigger_name = "snowboy" settings_object.default_player_name = "mplayer" tts1 = Tts(name="pico2wave", parameters={ 'cache': True, 'language': 'fr-FR' }) tts2 = Tts(name="voxygen", parameters={ 'voice': 'Agnes', 'cache': True }) settings_object.ttss = [tts1, tts2] stt = Stt(name="google", parameters={'language': 'fr-FR'}) settings_object.stts = [stt] trigger1 = Trigger( name="snowboy", parameters={ 'pmdl_file': 'trigger/snowboy/resources/kalliope-FR-6samples.pmdl' }) settings_object.triggers = [trigger1] player1 = Player(name="mplayer", parameters={}) player2 = Player(name="pyalsaaudio", parameters={"device": "default"}) settings_object.players = [player1, player2] settings_object.rest_api = RestAPI(password_protected=True, active=True, login="******", password="******", port=5000, allowed_cors_origin=False) settings_object.cache_path = '/tmp/kalliope_tts_cache' resources = Resources( neuron_folder="/tmp/kalliope/tests/kalliope_resources_dir/neurons", stt_folder="/tmp/kalliope/tests/kalliope_resources_dir/stt", tts_folder="/tmp/kalliope/tests/kalliope_resources_dir/tts", trigger_folder="/tmp/kalliope/tests/kalliope_resources_dir/trigger" ) settings_object.resources = resources settings_object.variables = { "author": "Lamonf", "test_number": 60, "test": "kalliope" } settings_object.start_options = {"muted": True} settings_object.machine = platform.machine() settings_object.recognition_options = RecognitionOptions() settings_object.hooks = { 'on_waiting_for_trigger': 'test', 'on_stop_listening': None, 'on_start_listening': None, 'on_order_found': None, 'on_start': ['on-start-synapse', 'bring-led-on'], 'on_unmute': [], 'on_triggered': ['on-triggered-synapse'], 'on_mute': [], 'on_order_not_found': ['order-not-found-synapse'], 'on_start_speaking': None, 'on_stop_speaking': None, } sl = SettingLoader(file_path=self.settings_file_to_test) self.assertEqual(settings_object, sl.settings)
def test_find_synapse_to_run(self): """ Test to find the good synapse to run Scenarii: - Find the synapse - No synpase found, no default synapse - No synapse found, run the default synapse """ # 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="that is part of 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]) all_synapse_list = [synapse1, synapse2, synapse3] br = Brain(synapses=all_synapse_list) st = Settings() # Find synapse order = "this is the sentence" expected_result = synapse1 oa_tuple_list = OrderAnalyser._find_synapse_to_run(brain=br, settings=st, order=order) self.assertEquals(oa_tuple_list[0].synapse, expected_result, "Fail to run the proper synapse matching the order") expected_result = signal1.sentence self.assertEquals(oa_tuple_list[0].order, expected_result, "Fail to run the proper synapse matching the order") # No Default synapse order = "No default synapse" expected_result = [] self.assertEquals( OrderAnalyser._find_synapse_to_run(brain=br, settings=st, order=order), expected_result, "Fail to run no synapse, when no default is defined") # Default synapse st = Settings(default_synapse="Synapse2") order = "default synapse" expected_result = synapse2 oa_tuple_list = OrderAnalyser._find_synapse_to_run(brain=br, settings=st, order=order) self.assertEquals(oa_tuple_list[0].synapse, expected_result, "Fail to run the default synapse")
def test_run_matching_synapse_from_order(self): # ------------------ # test_match_synapse1 # ------------------ with mock.patch("kalliope.core.Lifo.LIFOBuffer.execute"): order_to_match = "this is the sentence" should_be_created_matched_synapse = MatchedSynapse( matched_synapse=self.synapse1, user_order=order_to_match, matched_order="this is the sentence") expected_result = [[should_be_created_matched_synapse]] SynapseLauncher.run_matching_synapse_from_order( order_to_match, brain=self.brain_test, settings=self.settings_test) lifo_buffer = LifoManager.get_singleton_lifo() self.assertEqual(expected_result, lifo_buffer.lifo_list) # ------------------------- # test_match_synapse1_and_2 # ------------------------- # clean LIFO Singleton._instances = dict() LifoManager.clean_saved_lifo() with mock.patch("kalliope.core.Lifo.LIFOBuffer.execute"): order_to_match = "this is the second sentence" should_be_created_matched_synapse1 = MatchedSynapse( matched_synapse=self.synapse1, user_order=order_to_match, matched_order="this is the sentence") should_be_created_matched_synapse2 = MatchedSynapse( matched_synapse=self.synapse2, user_order=order_to_match, matched_order="this is the second sentence") expected_result = [[ should_be_created_matched_synapse1, should_be_created_matched_synapse2 ]] SynapseLauncher.run_matching_synapse_from_order( order_to_match, brain=self.brain_test, settings=self.settings_test) lifo_buffer = LifoManager.get_singleton_lifo() self.assertEqual(expected_result, lifo_buffer.lifo_list) # ------------------------- # test_call_hook_order_not_found # ------------------------- # clean LIFO Singleton._instances = dict() LifoManager.clean_saved_lifo() with mock.patch( "kalliope.core.HookManager.on_order_not_found") as mock_hook: order_to_match = "not existing sentence" SynapseLauncher.run_matching_synapse_from_order( order_to_match, brain=self.brain_test, settings=self.settings_test) mock_hook.assert_called_with() mock_hook.reset_mock() # ------------------------- # test_call_hook_order_found # ------------------------- # clean LIFO Singleton._instances = dict() with mock.patch("kalliope.core.Lifo.LIFOBuffer.execute"): with mock.patch( "kalliope.core.HookManager.on_order_found") as mock_hook: order_to_match = "this is the second sentence" new_settings = Settings() SynapseLauncher.run_matching_synapse_from_order( order_to_match, brain=self.brain_test, settings=new_settings) mock_hook.assert_called_with() mock_hook.reset_mock()
def test_replace_global_variables(self): """ Testing the _replace_global_variables function from the NeuronLauncher. Scenarii: - 1/ only one global variable - 2/ global variable with string after - 3/ global variable with int after - 4/ multiple global variables - 5/ parameter value is a list - 6/ parameter is a dict """ # 1/ only one global variable parameters = {'var1': '{{hello}}'} variables = { "hello": "test", "hello2": "test2", } st = Settings(variables=variables) expected_parameters = {'var1': 'test'} self.assertEquals( BrainLoader._replace_global_variables(parameter=parameters, settings=st), expected_parameters, "Fail to assign a single global variable to parameters") # 2/ global variable with string after parameters = {'var1': '{{hello}} Sispheor'} variables = { "hello": "test", "hello2": "test2", } st = Settings(variables=variables) expected_parameters = {'var1': 'test Sispheor'} self.assertEquals( BrainLoader._replace_global_variables(parameter=parameters, settings=st), expected_parameters, "Fail to assign a global variable with string after to parameters") # 3/ global variable with int after parameters = {'var1': '{{hello}}0'} variables = { "hello": 60, "hello2": "test2", } st = Settings(variables=variables) expected_parameters = {'var1': '600'} self.assertEquals( BrainLoader._replace_global_variables(parameter=parameters, settings=st), expected_parameters, "Fail to assign global variable with int after to parameters") # 4/ multiple global variables parameters = {'var1': '{{hello}} {{me}}'} variables = {"hello": "hello", "me": "LaMonf"} st = Settings(variables=variables) expected_parameters = {'var1': 'hello LaMonf'} self.assertEquals( BrainLoader._replace_global_variables(parameter=parameters, settings=st), expected_parameters, "Fail to assign multiple global variables to parameters") # 5/ parameter value is a list parameters = {'var1': '[hello {{name}}, bonjour {{name}}]'} variables = { "name": "LaMonf", "hello2": "test2", } st = Settings(variables=variables) expected_parameters = {'var1': '[hello LaMonf, bonjour LaMonf]'} self.assertEquals( BrainLoader._replace_global_variables(parameter=parameters, settings=st), expected_parameters, "Fail to assign a single global when parameter value is a list to neuron" ) # 6/ parameter is a dict parameters = { 'from_answer_link': [{ 'synapse': 'synapse2', 'answers': ['absolument', '{{ name }}'] }, { 'synapse': 'synapse3', 'answers': ['{{ name }}'] }], 'default': 'synapse4' } variables = {"name": "nico"} st = Settings(variables=variables) expected_parameters = { 'from_answer_link': [{ 'synapse': 'synapse2', 'answers': ['absolument', 'nico'] }, { 'synapse': 'synapse3', 'answers': ['nico'] }], 'default': 'synapse4' } self.assertEquals( BrainLoader._replace_global_variables(parameter=parameters, settings=st), expected_parameters, "Fail to assign a single global when parameter value is a list to neuron" )
def test_run_matching_synapse_from_order(self): # ------------------ # test_match_synapse1 # ------------------ with mock.patch("kalliope.core.LIFOBuffer.execute"): order_to_match = "this is the sentence" should_be_created_matched_synapse = MatchedSynapse( matched_synapse=self.synapse1, user_order=order_to_match, matched_order="this is the sentence") expected_result = [[should_be_created_matched_synapse]] SynapseLauncher.run_matching_synapse_from_order( order_to_match, brain=self.brain_test, settings=self.settings_test) lifo_buffer = LIFOBuffer() self.assertEqual(expected_result, lifo_buffer.lifo_list) # ------------------------- # test_match_synapse1_and_2 # ------------------------- # clean LIFO Singleton._instances = dict() with mock.patch("kalliope.core.LIFOBuffer.execute"): order_to_match = "this is the second sentence" should_be_created_matched_synapse1 = MatchedSynapse( matched_synapse=self.synapse1, user_order=order_to_match, matched_order="this is the sentence") should_be_created_matched_synapse2 = MatchedSynapse( matched_synapse=self.synapse2, user_order=order_to_match, matched_order="this is the second sentence") expected_result = [[ should_be_created_matched_synapse1, should_be_created_matched_synapse2 ]] SynapseLauncher.run_matching_synapse_from_order( order_to_match, brain=self.brain_test, settings=self.settings_test) lifo_buffer = LIFOBuffer() self.assertEqual(expected_result, lifo_buffer.lifo_list) # ------------------------- # test_match_default_synapse # ------------------------- # clean LIFO Singleton._instances = dict() with mock.patch("kalliope.core.LIFOBuffer.execute"): order_to_match = "not existing sentence" should_be_created_matched_synapse = MatchedSynapse( matched_synapse=self.synapse3, user_order=order_to_match, matched_order=None) expected_result = [[should_be_created_matched_synapse]] SynapseLauncher.run_matching_synapse_from_order( order_to_match, brain=self.brain_test, settings=self.settings_test) lifo_buffer = LIFOBuffer() self.assertEqual(expected_result, lifo_buffer.lifo_list) # ------------------------- # test_no_match_and_no_default_synapse # ------------------------- # clean LIFO Singleton._instances = dict() with mock.patch("kalliope.core.LIFOBuffer.execute"): order_to_match = "not existing sentence" new_settings = Settings() expected_result = [[]] SynapseLauncher.run_matching_synapse_from_order( order_to_match, brain=self.brain_test, settings=new_settings) lifo_buffer = LIFOBuffer() self.assertEqual(expected_result, lifo_buffer.lifo_list)
def test_Settings(self): with mock.patch('platform.machine', return_value='pumpkins'): rest_api1 = RestAPI(password_protected=True, login="******", password="******", active=True, port=5000, allowed_cors_origin="*") recognition_options = RecognitionOptions() setting1 = Settings(default_tts_name="pico2wav", default_stt_name="google", default_trigger_name="swoyboy", default_player_name="mplayer", ttss=["ttts"], stts=["stts"], random_wake_up_answers=["yes"], random_wake_up_sounds=None, play_on_ready_notification=False, on_ready_answers=None, on_ready_sounds=None, triggers=["snowboy"], players=["mplayer"], rest_api=rest_api1, cache_path="/tmp/kalliope", default_synapse="default_synapse", resources=None, variables={"key1": "val1"}, recognition_options=recognition_options) setting1.kalliope_version = "0.4.5" setting2 = Settings(default_tts_name="accapela", default_stt_name="bing", default_trigger_name="swoyboy", default_player_name="mplayer", ttss=["ttts"], stts=["stts"], random_wake_up_answers=["no"], random_wake_up_sounds=None, play_on_ready_notification=False, on_ready_answers=None, on_ready_sounds=None, triggers=["snowboy"], rest_api=rest_api1, cache_path="/tmp/kalliope_tmp", default_synapse="my_default_synapse", resources=None, variables={"key1": "val1"}, recognition_options=recognition_options) setting2.kalliope_version = "0.4.5" setting3 = Settings(default_tts_name="pico2wav", default_stt_name="google", default_trigger_name="swoyboy", default_player_name="mplayer", ttss=["ttts"], stts=["stts"], random_wake_up_answers=["yes"], random_wake_up_sounds=None, play_on_ready_notification=False, on_ready_answers=None, on_ready_sounds=None, triggers=["snowboy"], players=["mplayer"], rest_api=rest_api1, cache_path="/tmp/kalliope", default_synapse="default_synapse", resources=None, variables={"key1": "val1"}, recognition_options=recognition_options) setting3.kalliope_version = "0.4.5" expected_result_serialize = { 'default_synapse': 'default_synapse', 'default_tts_name': 'pico2wav', 'rest_api': { 'password_protected': True, 'port': 5000, 'active': True, 'allowed_cors_origin': '*', 'password': '******', 'login': '******' }, 'play_on_ready_notification': False, 'default_stt_name': 'google', 'kalliope_version': '0.4.5', 'random_wake_up_sounds': None, 'on_ready_answers': None, 'default_trigger_name': 'swoyboy', 'default_player_name': 'mplayer', 'cache_path': '/tmp/kalliope', 'stts': ['stts'], 'machine': 'pumpkins', 'random_wake_up_answers': ['yes'], 'on_ready_sounds': None, 'ttss': ['ttts'], 'variables': { 'key1': 'val1' }, 'resources': None, 'triggers': ['snowboy'], 'rpi_settings': None, 'players': ['mplayer'], 'recognition_options': { 'energy_threshold': 4000, 'adjust_for_ambient_noise_second': 0 } } self.assertDictEqual(expected_result_serialize, setting1.serialize()) self.assertTrue(setting1.__eq__(setting3)) self.assertFalse(setting1.__eq__(setting2))