def test_message_set_facts_always_list2(self): message = Message(self.fact1, 0.1, 0.2, 0.3) message.facts = [self.fact2] self.assertIsInstance(message.facts, list) self.assertListEqual(message.facts, [self.fact2]) self.assertEqual(message.main_fact, self.fact2)
def _add_template_to_message(message: Message, template_original: Template, all_messages: List[Message]) -> None: """ Adds a matching template to a message, also adding the facts used by the template to the message. :param message: The message to be fitted with a template :param template_original: The template to be added to the message. :param all_messages: Other available messages, some of which will be needed to match possible secondary rules in the template. :return: Nothing """ template = template_original.copy() used_facts = template.fill(message, all_messages) if used_facts: log.debug("Successfully linked template to message") else: log.error( "Chosen template '{}' for fact '{}' could not be used! " "Falling back to default templates".format(template.display_template(), message.main_fact) ) template = DefaultTemplate("") message.template = template message.facts = used_facts