def test_start_synapse_by_list_name_single_synapse(self): # existing synapse in the brain with mock.patch("brain.core.Lifo.LIFOBuffer.execute"): should_be_created_matched_synapse = MatchedSynapse( matched_synapse=self.synapse1) SynapseLauncher.start_synapse_by_list_name(["Synapse1"], brain=self.brain_test) # we expect that the lifo has been loaded with the synapse to run expected_result = [[should_be_created_matched_synapse]] lifo_buffer = LifoManager.get_singleton_lifo() self.assertEqual(expected_result, lifo_buffer.lifo_list) # we expect that the lifo has been loaded with the synapse to run and overwritten parameters Singleton._instances = dict() LifoManager.clean_saved_lifo() lifo_buffer = LifoManager.get_singleton_lifo() overriding_param = {"val1": "val"} SynapseLauncher.start_synapse_by_list_name( ["Synapse1"], brain=self.brain_test, overriding_parameter_dict=overriding_param) should_be_created_matched_synapse = MatchedSynapse( matched_synapse=self.synapse1, overriding_parameter=overriding_param) # we expect that the lifo has been loaded with the synapse to run expected_result = [[should_be_created_matched_synapse]] self.assertEqual(expected_result, lifo_buffer.lifo_list) # non existing synapse in the brain with self.assertRaises(SynapseNameNotFound): SynapseLauncher.start_synapse_by_list_name(["not_existing"], brain=self.brain_test)
def test_MatchedSynapse(self): user_order = "user order" matched_synapse1 = MatchedSynapse(matched_synapse=self.synapse1, matched_order=user_order) matched_synapse2 = MatchedSynapse(matched_synapse=self.synapse2, matched_order=user_order) matched_synapse3 = MatchedSynapse(matched_synapse=self.synapse1, matched_order=user_order) expected_result_serialize = { 'matched_order': 'user order', 'neuron_module_list': [], 'synapse_name': 'Synapse1' } self.assertDictEqual(expected_result_serialize, matched_synapse1.serialize()) self.assertTrue(matched_synapse1.__eq__(matched_synapse3)) self.assertFalse(matched_synapse1.__eq__(matched_synapse2)) # test neuron parameter loader is called with mock.patch("brain.core.NeuronParameterLoader.get_parameters" ) as mock_get_parameters: MatchedSynapse(matched_synapse=self.synapse1, matched_order=user_order, user_order=user_order) mock_get_parameters.assert_called_once_with( synapse_order=user_order, user_order=user_order) mock_get_parameters.reset_mock()
def test_process_synapse_list(self): """ Testing the neuron list from a synapse """ synapse = BrainLoader().brain.get_synapse_by_name("synapse1") order = "enter in synapse 1" matched_synapse = MatchedSynapse(matched_synapse=synapse, user_order=order, matched_order=order) list_matched_synapse = list() list_matched_synapse.append(matched_synapse) with mock.patch("brain.core.Lifo.LIFOBuffer._process_neuron_list"): self.lifo_buffer._process_synapse_list(list_matched_synapse) expected_response = { 'status': None, 'matched_synapses': [{ 'matched_order': 'enter in synapse 1', 'neuron_module_list': [], 'synapse_name': 'synapse1' }], 'user_order': None } self.assertEqual(expected_response, self.lifo_buffer.api_response.serialize()) self.assertEqual(0, len(self.lifo_buffer.lifo_list))
def run_synapse_by_name(synapse_name, user_order=None, synapse_order=None, high_priority=False, is_api_call=False, overriding_parameter_dict=None): """ call the lifo for adding a synapse to execute in the list of synapse list to process :param synapse_name: The name of the synapse to run :param user_order: The user order :param synapse_order: The synapse order :param high_priority: If True, the synapse is executed before the end of the current synapse list :param is_api_call: If true, the current call comes from the api :param overriding_parameter_dict: dict of value to add to neuron parameters """ synapse = BrainLoader().brain.get_synapse_by_name(synapse_name) matched_synapse = MatchedSynapse( matched_synapse=synapse, matched_order=synapse_order, user_order=user_order, overriding_parameter=overriding_parameter_dict) list_synapse_to_process = list() list_synapse_to_process.append(matched_synapse) # get the singleton lifo_buffer = LifoManager.get_singleton_lifo() lifo_buffer.add_synapse_list_to_lifo(list_synapse_to_process, high_priority=high_priority) lifo_buffer.execute(is_api_call=is_api_call)
def get_list_synapses_to_process(cls, list_match_synapse, order): list_synapse_to_process = list() for tuple_el in list_match_synapse: new_matching_synapse = MatchedSynapse(matched_synapse=tuple_el.synapse, matched_order=tuple_el.order, user_order=order) list_synapse_to_process.append(new_matching_synapse) return list_synapse_to_process
def test_process_neuron_list(self): # Test with a neuron that doesn't wait for an answer synapse = BrainLoader().brain.get_synapse_by_name("synapse5") order = "synapse5" matched_synapse = MatchedSynapse(matched_synapse=synapse, user_order=order, matched_order=order) with mock.patch("brain.core.TTS.TTSModule.generate_and_play"): self.lifo_buffer.set_api_call(True) self.lifo_buffer._process_neuron_list( matched_synapse=matched_synapse) self.assertEqual("complete", self.lifo_buffer.api_response.status) # test with neuron that wait for an answer LifoManager.clean_saved_lifo() synapse = BrainLoader().brain.get_synapse_by_name("synapse6") order = "synapse6" matched_synapse = MatchedSynapse(matched_synapse=synapse, user_order=order, matched_order=order) self.lifo_buffer.set_api_call(True) with mock.patch("brain.core.TTS.TTSModule.generate_and_play"): with self.assertRaises(Serialize): self.lifo_buffer._process_neuron_list( matched_synapse=matched_synapse) # test with a neuron that want to add a synapse list to the LIFO LifoManager.clean_saved_lifo() synapse = BrainLoader().brain.get_synapse_by_name("synapse6") order = "synapse6" matched_synapse = MatchedSynapse(matched_synapse=synapse, user_order=order, matched_order=order) self.lifo_buffer.set_api_call(True) self.lifo_buffer.set_answer("synapse 6 answer") with mock.patch("brain.core.TTS.TTSModule.generate_and_play"): self.assertRaises( SynapseListAddedToLIFO, self.lifo_buffer._process_neuron_list( matched_synapse=matched_synapse))
def run_synapse_by_name(self, synapse_name): """ Run a synapse by its name test with curl: curl -i --user admin:secret -X POST http://127.0.0.1:5000/synapses/start/id/say-hello-fr run a synapse without making brain speaking curl -i -H "Content-Type: application/json" --user admin:secret -X POST \ -d '{"mute":"true"}' http://127.0.0.1:5000/synapses/start/id/say-hello-fr Run a synapse by its name and pass order's parameters curl -i -H "Content-Type: application/json" --user admin:secret -X POST \ -d '{"mute":"true", "parameters": {"parameter1": "value1" }}' \ http://127.0.0.1:5000/synapses/start/id/say-hello-fr :param synapse_name: name(id) of the synapse to execute :return: """ # get a synapse object from the name logger.debug("[FlaskAPI] run_synapse_by_name: synapse name -> %s" % synapse_name) synapse_target = BrainLoader().brain.get_synapse_by_name( synapse_name=synapse_name) # Store the mute value, then apply depending of the request parameters old_mute_value = self.settings.options.mute mute = self.get_value_flag_from_request(http_request=request, flag_to_find="mute", is_boolean=True) if mute is not None: SettingEditor.set_mute_status(mute=mute) # get parameters parameters = self.get_parameters_from_request(request) if synapse_target is None: data = {"synapse name not found": "%s" % synapse_name} if mute is not None: SettingEditor.set_mute_status(mute=old_mute_value) return jsonify(error=data), 404 else: # generate a MatchedSynapse from the synapse matched_synapse = MatchedSynapse(matched_synapse=synapse_target, overriding_parameter=parameters) # get the current LIFO buffer from the singleton lifo_buffer = LifoManager.get_singleton_lifo() lifo_buffer.add_synapse_list_to_lifo([matched_synapse]) response = lifo_buffer.execute(is_api_call=True) data = jsonify(response) if mute is not None: SettingEditor.set_mute_status(mute=old_mute_value) return data, 201
def test_add_synapse_list_to_lifo(self): """ Testing to add a synapse to the lifo """ synapse = BrainLoader().brain.get_synapse_by_name("synapse1") order = "enter in synapse 1" matched_synapse = MatchedSynapse(matched_synapse=synapse, user_order=order, matched_order=order) list_matched_synapse = list() list_matched_synapse.append(matched_synapse) self.lifo_buffer.add_synapse_list_to_lifo(list_matched_synapse) self.assertEqual(self.lifo_buffer.lifo_list, [list_matched_synapse])
def test_clean(self): """ Test the Cleaning of the matched synapses list """ synapse = BrainLoader().brain.get_synapse_by_name("synapse1") order = "enter in synapse 1" matched_synapse = MatchedSynapse(matched_synapse=synapse, user_order=order, matched_order=order) list_matched_synapse = list() list_matched_synapse.append(matched_synapse) self.lifo_buffer.add_synapse_list_to_lifo(list_matched_synapse) self.lifo_buffer.clean() self.assertEqual(0, len(self.lifo_buffer.lifo_list))
def start_synapse_by_list_name(cls, list_name, brain=None, overriding_parameter_dict=None, new_lifo=False): """ Start synapses by their name :param list_name: List of name of the synapse to launch :param brain: Brain instance :param overriding_parameter_dict: parameter to pass to neurons :param new_lifo: If True, ask the LifoManager to return a new lifo and not the singleton """ logger.debug( "[SynapseLauncher] start_synapse_by_list_name called with synapse list: %s " % list_name) if list_name: if brain is None: brain = BrainLoader().brain # get all synapse object list_synapse_object_to_start = list() for name in list_name: synapse_to_start = brain.get_synapse_by_name(synapse_name=name) if not synapse_to_start: raise SynapseNameNotFound( "[SynapseLauncher] The synapse name \"%s\" does not exist in the brain file" % name) list_synapse_object_to_start.append(synapse_to_start) # run the LIFO with all synapse if new_lifo: lifo_buffer = LifoManager.get_new_lifo() else: lifo_buffer = LifoManager.get_singleton_lifo() list_synapse_to_process = list() for synapse in list_synapse_object_to_start: if synapse is not None: new_matching_synapse = MatchedSynapse( matched_synapse=synapse, matched_order=None, user_order=None, overriding_parameter=overriding_parameter_dict) list_synapse_to_process.append(new_matching_synapse) lifo_buffer.add_synapse_list_to_lifo(list_synapse_to_process) return lifo_buffer.execute(is_api_call=True) return None
def test_APIResponse(self): user_order = "user order" self.matched_synapse = MatchedSynapse(matched_synapse=self.synapse1, matched_order=user_order) api_response = APIResponse() api_response.user_order = user_order api_response.list_processed_matched_synapse = [self.matched_synapse] expected_result_serialize = { 'status': None, 'matched_synapses': [{ 'matched_order': 'user order', 'neuron_module_list': [], 'synapse_name': 'Synapse1' }], 'user_order': 'user order' } self.assertDictEqual(expected_result_serialize, api_response.serialize())
def test_start_synapse_by_list_name(self): # test to start a list of synapse with mock.patch("brain.core.Lifo.LIFOBuffer.execute"): created_matched_synapse1 = MatchedSynapse( matched_synapse=self.synapse1) created_matched_synapse2 = MatchedSynapse( matched_synapse=self.synapse2) expected_list_matched_synapse = [ created_matched_synapse1, created_matched_synapse2 ] SynapseLauncher.start_synapse_by_list_name( ["Synapse1", "Synapse2"], brain=self.brain_test) # we expect that the lifo has been loaded with the synapse to run expected_result = [expected_list_matched_synapse] lifo_buffer = LifoManager.get_singleton_lifo() self.maxDiff = None self.assertEqual(expected_result, lifo_buffer.lifo_list) # empty list should return none empty_list = list() self.assertIsNone( SynapseLauncher.start_synapse_by_list_name(empty_list)) # test to start a synapse list with a new lifo # we create a Lifo that is the current singleton Singleton._instances = dict() LifoManager.clean_saved_lifo() lifo_buffer = LifoManager.get_singleton_lifo() created_matched_synapse1 = MatchedSynapse( matched_synapse=self.synapse1) lifo_buffer.lifo_list = [created_matched_synapse1] # the current status of the singleton lifo should not move even after the call of SynapseLauncher expected_result = [created_matched_synapse1] # create a new call with mock.patch("brain.core.Lifo.LIFOBuffer.execute"): SynapseLauncher.start_synapse_by_list_name( ["Synapse2", "Synapse3"], brain=self.brain_test, new_lifo=True) # the current singleton should be the same self.assertEqual(expected_result, lifo_buffer.lifo_list) # test to start a synapse list with the singleton lifo Singleton._instances = dict() LifoManager.clean_saved_lifo() lifo_buffer = LifoManager.get_singleton_lifo() created_matched_synapse1 = MatchedSynapse( matched_synapse=self.synapse1) # place a synapse in the singleton lifo_buffer.lifo_list = [created_matched_synapse1] # the current status of the singleton lifo should contain synapse launched in the next call created_matched_synapse2 = MatchedSynapse( matched_synapse=self.synapse2) created_matched_synapse3 = MatchedSynapse( matched_synapse=self.synapse3) expected_result = [ created_matched_synapse1, [created_matched_synapse2, created_matched_synapse3] ] with mock.patch("brain.core.Lifo.LIFOBuffer.execute"): SynapseLauncher.start_synapse_by_list_name( ["Synapse2", "Synapse3"], brain=self.brain_test) # the singleton should now contains the synapse that was already there and the 2 other synapses self.assertEqual(expected_result, lifo_buffer.lifo_list)
def test_run_matching_synapse_from_order(self): # ------------------ # test_match_synapse1 # ------------------ with mock.patch("brain.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("brain.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( "brain.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("brain.core.Lifo.LIFOBuffer.execute"): with mock.patch( "brain.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_execute(self): """ In this test the brain contains a neurotransmitter """ # -------------------------------------- # Test 1. The user answers correctly to all neurotransmitter # -------------------------------------- # we suppose that the first synapse has matched the first synapse synapse = BrainLoader().brain.get_synapse_by_name("synapse1") order = "enter in synapse 1" matched_synapse = MatchedSynapse(matched_synapse=synapse, user_order=order, matched_order=order) list_matched_synapse = list() list_matched_synapse.append(matched_synapse) self.lifo_buffer.add_synapse_list_to_lifo(list_matched_synapse) self.lifo_buffer.api_response.user_order = order with mock.patch("brain.core.TTS.TTSModule.generate_and_play"): response = self.lifo_buffer.execute(is_api_call=True) expected_result = { 'status': 'waiting_for_answer', 'matched_synapses': [{ 'matched_order': 'enter in synapse 1', 'neuron_module_list': [{ 'neuron_name': 'Say', 'generated_message': 'question in synapse 1' }], 'synapse_name': 'synapse1' }], 'user_order': 'enter in synapse 1' } self.assertEqual(response, expected_result) # give an answer answer = "answer synapse1" response = self.lifo_buffer.execute(answer=answer, is_api_call=True) expected_result = { 'status': 'waiting_for_answer', 'matched_synapses': [{ 'matched_order': 'enter in synapse 1', 'neuron_module_list': [{ 'neuron_name': 'Say', 'generated_message': 'question in synapse 1' }, { 'neuron_name': 'Neurotransmitter', 'generated_message': None }], 'synapse_name': 'synapse1' }, { 'matched_order': 'answer synapse1', 'neuron_module_list': [{ 'neuron_name': 'Say', 'generated_message': 'enter synapse 2' }], 'synapse_name': 'synapse2' }], 'user_order': None } self.assertEqual(response, expected_result) # give the last answer answer = "synapse5" response = self.lifo_buffer.execute(answer=answer, is_api_call=True) expected_result = { 'status': 'complete', 'matched_synapses': [{ 'matched_order': 'answer synapse1', 'neuron_module_list': [{ 'neuron_name': 'Say', 'generated_message': 'enter synapse 2' }, { 'neuron_name': 'Neurotransmitter', 'generated_message': None }], 'synapse_name': 'synapse2' }, { 'matched_order': 'synapse5', 'neuron_module_list': [{ 'neuron_name': 'Say', 'generated_message': 'execution of synapse 5' }], 'synapse_name': 'synapse5' }, { 'matched_order': 'enter in synapse 1', 'neuron_module_list': [{ 'neuron_name': 'Say', 'generated_message': 'question in synapse 1' }, { 'neuron_name': 'Neurotransmitter', 'generated_message': None }, { 'neuron_name': 'Say', 'generated_message': 'last neuron in synapse 1' }], 'synapse_name': 'synapse1' }], 'user_order': None } self.assertEqual(response, expected_result) # -------------------------------------- # Test 2. The user doesn't answered correctly to the first neurotransmitter # -------------------------------------- # we suppose that the first synapse has matched the first synapse synapse = BrainLoader().brain.get_synapse_by_name("synapse1") order = "enter in synapse 1" matched_synapse = MatchedSynapse(matched_synapse=synapse, user_order=order, matched_order=order) list_matched_synapse = list() list_matched_synapse.append(matched_synapse) self.lifo_buffer.add_synapse_list_to_lifo(list_matched_synapse) self.lifo_buffer.api_response.user_order = order with mock.patch("brain.core.TTS.TTSModule.generate_and_play"): # fist call to enter in the neurotransmitter self.lifo_buffer.execute(is_api_call=True) wrong_answer = "wrong answer" response = self.lifo_buffer.execute(answer=wrong_answer, is_api_call=True) expected_result = { 'status': 'complete', 'matched_synapses': [{ 'matched_order': 'enter in synapse 1', 'neuron_module_list': [{ 'neuron_name': 'Say', 'generated_message': 'question in synapse 1' }, { 'neuron_name': 'Neurotransmitter', 'generated_message': None }, { 'neuron_name': 'Say', 'generated_message': 'last neuron in synapse 1' }], 'synapse_name': 'synapse1' }, { 'matched_order': None, 'neuron_module_list': [{ 'neuron_name': 'Say', 'generated_message': 'not understood' }], 'synapse_name': 'synapse4' }], 'user_order': None } self.assertEqual(response, expected_result) # -------------------------------------- # Test 3. No synapse matched, we still execute the list # -------------------------------------- list_matched_synapse = list() self.lifo_buffer.add_synapse_list_to_lifo(list_matched_synapse) self.lifo_buffer.api_response.user_order = "this is an order" with mock.patch("brain.core.TTS.TTSModule.generate_and_play"): # fist call to enter in the neurotransmitter response = self.lifo_buffer.execute(is_api_call=True) expected_result = { 'status': None, 'matched_synapses': [], 'user_order': 'this is an order' } self.assertEqual(response, expected_result)
def test_get_matching_synapse(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") signal4 = Signal(name="order", parameters={ "matching-type": "strict", "text": "that is part of the fourth sentence" }) signal5 = Signal(name="order", parameters={ "matching-type": "ordered-strict", "text": "sentence 5 with specific order" }) signal6 = Signal(name="order", parameters={ "matching-type": "normal", "text": "matching type normal" }) signal7 = Signal(name="order", parameters={ "matching-type": "non-existing", "text": "matching type non existing" }) signal8 = Signal(name="order", parameters={ "matching-type": "non-existing", "non-existing-parameter": "will not match order" }) signal9 = Signal( name="order", parameters= "order that should be triggered because synapse is disabled") 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]) synapse4 = Synapse(name="Synapse4", neurons=[neuron2, neuron4], signals=[signal4]) synapse5 = Synapse(name="Synapse5", neurons=[neuron1, neuron2], signals=[signal5]) synapse6 = Synapse(name="Synapse6", neurons=[neuron1, neuron2], signals=[signal6]) synapse7 = Synapse(name="Synapse7", neurons=[neuron1, neuron2], signals=[signal7]) synapse8 = Synapse(name="Synapse8", neurons=[neuron1, neuron2], signals=[signal8]) synapse9 = Synapse(name="Synapse9", enabled=False, neurons=[neuron1, neuron2], signals=[signal9]) all_synapse_list = [ synapse1, synapse2, synapse3, synapse4, synapse5, synapse6, synapse7, synapse8, synapse9 ] br = Brain(synapses=all_synapse_list) # TEST1: should return synapse1 spoken_order = "this is the sentence" # Create the matched synapse expected_matched_synapse_1 = MatchedSynapse(matched_synapse=synapse1, matched_order=spoken_order, user_order=spoken_order) matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertEqual(len(matched_synapses), 1) self.assertTrue(expected_matched_synapse_1 in matched_synapses) # with defined normal matching type spoken_order = "matching type normal" expected_matched_synapse_5 = MatchedSynapse(matched_synapse=synapse6, matched_order=spoken_order, user_order=spoken_order) matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertEqual(len(matched_synapses), 1) self.assertTrue(expected_matched_synapse_5 in matched_synapses) # TEST2: should return synapse1 and 2 spoken_order = "this is the second sentence" expected_matched_synapse_2 = MatchedSynapse(matched_synapse=synapse1, matched_order=spoken_order, user_order=spoken_order) matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertEqual(len(matched_synapses), 2) self.assertTrue(expected_matched_synapse_1, expected_matched_synapse_2 in matched_synapses) # TEST3: should empty spoken_order = "not a valid order" matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertFalse(matched_synapses) # TEST4: with matching type strict spoken_order = "that is part of the fourth sentence" expected_matched_synapse_3 = MatchedSynapse(matched_synapse=synapse4, matched_order=spoken_order, user_order=spoken_order) matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertTrue(expected_matched_synapse_3 in matched_synapses) spoken_order = "that is part of the fourth sentence with more word" matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertFalse(matched_synapses) # TEST5: with matching type ordered strict spoken_order = "sentence 5 with specific order" expected_matched_synapse_4 = MatchedSynapse(matched_synapse=synapse5, matched_order=spoken_order, user_order=spoken_order) matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertEqual(len(matched_synapses), 1) self.assertTrue(expected_matched_synapse_4 in matched_synapses) spoken_order = "order specific with 5 sentence" matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertFalse(matched_synapses) # TEST6: non supported type of matching. should fallback to normal spoken_order = "matching type non existing" expected_matched_synapse_5 = MatchedSynapse(matched_synapse=synapse7, matched_order=spoken_order, user_order=spoken_order) matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertTrue(expected_matched_synapse_5 in matched_synapses) # TEST7: should not match the disabled synapse spoken_order = "order that should be triggered because synapse is disabled" # we expect an empty list matched_synapses = OrderAnalyser.get_matching_synapse( order=spoken_order, brain=br) self.assertTrue(len(matched_synapses) == 0)