def test_save_parameter_from_order_in_memory(self): # Test with a value that exist in the temp memory order_parameters = { "key1": "value1", "key2": "value2" } Cortex.temp = order_parameters dict_val_to_save = {"my_key_in_memory": "{{key1}}"} expected_dict = {"my_key_in_memory": "value1"} Cortex.save_parameter_from_order_in_memory(dict_val_to_save) self.assertDictEqual(expected_dict, Cortex.memory) # test with a value that does not exsit order_parameters = { "key1": "value1", "key2": "value2" } Cortex.temp = order_parameters dict_val_to_save = {"my_key_in_memory": "{{key3}}"} self.assertFalse(Cortex.save_parameter_from_order_in_memory(dict_val_to_save))
def __init__(self, **kwargs): """ Class used by neuron for talking :param kwargs: Same parameter as the Child. Can contain info about the tts to use instead of the default one """ # get the child who called the class child_name = self.__class__.__name__ self.neuron_name = child_name sl = SettingLoader() self.settings = sl.settings brain_loader = BrainLoader() self.brain = brain_loader.brain self.tts = self._get_tts_object(settings=self.settings) # get templates if provided # Check if there is a template associate to the output message self.say_template = kwargs.get('say_template', None) # check if there is a template file associate to the output message self.file_template = kwargs.get('file_template', None) # keep the generated message self.tts_message = None # if the current call is api one self.is_api_call = kwargs.get('is_api_call', False) # boolean to know id the synapse is waiting for an answer self.is_waiting_for_answer = False # the synapse name to add the the buffer self.pending_synapse = None # a dict of parameters the user ask to save in short term memory self.kalliope_memory = kwargs.get('kalliope_memory', None) # parameters loaded from the order can be save now Cortex.save_parameter_from_order_in_memory(self.kalliope_memory)
def __init__(self, **kwargs): super(Background_sound_player, self).__init__(**kwargs) self.state = kwargs.get('state', None) # "on" / "off" self.sounds = kwargs.get( 'sounds', None) # "[{'title1': 'link1'}, {'title2': 'link2'}, ...]" self.random_option = kwargs.get( 'random_option', "random-select-one" ) # "random-order-play" / "random-select-one" / "no-random" self.loop_option = kwargs.get('loop_option', 'no-loop') # "loop" / "no-loop" self.mplayer_path = kwargs.get('mplayer_path', "/usr/bin/mplayer") self.auto_stop_minutes = kwargs.get('auto_stop_minutes', None) self.currently_playing_sound = None # a dict of parameters the user ask to save in short term memory self.kalliope_memory = kwargs.get('kalliope_memory', None) # parameters loaded from the order can be save now Cortex.save_parameter_from_order_in_memory(self.kalliope_memory) Cortex.save("current_playing_background_sound", "Aucun fond sonore lancé actuellement") # message dict that will be passed to the neuron template self.message = dict() # check if sent parameters are in good state if self._is_parameters_ok(): if self.state == "off": self.stop_last_process() self.clean_pid_file() Cortex.save("current_playing_background_sound", "Aucun fond sonore lancé actuellement") else: # we stop the last process if exist self.stop_last_process() # pick one sound randomly in all sounds entered if self.random_option == "random-select-one": self.currently_playing_sound = [random.choice(self.sounds)] # play all sounds in random order elif self.random_option == "random-order-play": random.shuffle(self.sounds) self.currently_playing_sound = self.sounds # play all sounds the specified order else: self.currently_playing_sound = self.sounds # then we can start a new process self.start_new_process(self.currently_playing_sound) # run auto stop thread if self.auto_stop_minutes: thread_auto_stop = threading.Thread( target=self.wait_before_stop) thread_auto_stop.start() # give the message dict to the neuron template self.say(self.message)
def test_save_parameter_from_order_in_memory(self): # Test with a value that exist in the temp memory order_parameters = {"key1": "value1", "key2": "value2"} Cortex.temp = order_parameters dict_val_to_save = {"my_key_in_memory": "{{key1}}"} expected_dict = {"my_key_in_memory": "value1"} Cortex.save_parameter_from_order_in_memory(dict_val_to_save) self.assertDictEqual(expected_dict, Cortex.memory) # test with a value that does not exist order_parameters = {"key1": "value1", "key2": "value2"} Cortex.temp = order_parameters dict_val_to_save = {"my_key_in_memory": "{{key3}}"} self.assertFalse( Cortex.save_parameter_from_order_in_memory(dict_val_to_save)) # save a value with no brackets dict_val_to_save = {"my_key_in_memory": "my value"} expected_dict = {"my_key_in_memory": "my value"} self.assertTrue( Cortex.save_parameter_from_order_in_memory(dict_val_to_save)) self.assertDictEqual(expected_dict, Cortex.memory)