def test_resolve_no_defaults_inside_topic(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateTopicStarNode(index=1) self.assertIsNotNone(node) self.assertEqual(1, node.index) root.append(node) self.assertEqual(len(root.children), 1) conversation = Conversation(self._client_context) question = Question.create_from_text(self._client_context.brain.tokenizer, "Hello world") question.current_sentence()._response = "Hello matey" conversation.record_dialog(question) question = Question.create_from_text(self._client_context.brain.tokenizer, "How are you") question.current_sentence()._response = "Very well thanks" conversation.record_dialog(question) match = PatternOneOrMoreWildCardNode("*") context = MatchContext(max_search_depth=100, max_search_timeout=-1, tokenizer=self._client_context.brain.tokenizer) context.add_match(Match(Match.TOPIC, match, "Matched")) question.current_sentence()._matched_context = context conversation.record_dialog(question) self._client_context.bot._conversations["testid"] = conversation self.assertEqual("Matched", node.resolve(self._client_context))
def test_resolve_no_defaults_inside_topic(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateTopicStarNode(index=1) self.assertIsNotNone(node) self.assertEqual(1, node.index) root.append(node) self.assertEqual(len(root.children), 1) conversation = Conversation("testid", self.bot) question = Question.create_from_text("Hello world") question.current_sentence()._response = "Hello matey" conversation.record_dialog(question) question = Question.create_from_text("How are you") question.current_sentence()._response = "Very well thanks" conversation.record_dialog(question) match = PatternOneOrMoreWildCardNode("*") context = MatchContext(max_search_depth=100, max_search_timeout=-1) context.add_match(Match(Match.TOPIC, match, "Matched")) question.current_sentence()._matched_context = context conversation.record_dialog(question) self.bot._conversations["testid"] = conversation self.assertEqual("Matched", node.resolve(self.bot, "testid"))
def test_to_xml_defaults(self): root = TemplateNode() node = TemplateTopicStarNode() root.append(node) xml = root.xml_tree(self.bot, self.clientid) self.assertIsNotNone(xml) xml_str = ET.tostring(xml, "utf-8").decode("utf-8") self.assertEqual("<template><topicstar /></template>", xml_str)
def test_to_xml_no_defaults(self): root = TemplateNode() node = TemplateTopicStarNode(index=3) root.append(node) xml = root.xml_tree(self._client_context) self.assertIsNotNone(xml) xml_str = ET.tostring(xml, "utf-8").decode("utf-8") self.assertEqual('<template><topicstar index="3" /></template>', xml_str)
def test_node(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateTopicStarNode() self.assertIsNotNone(node) root.append(node) self.assertEqual(len(root.children), 1)
def test_node_no_defaults(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateTopicStarNode(position=3, index=2) self.assertIsNotNone(node) root.append(node) self.assertEqual(len(root.children), 1) self.assertEqual(2, node.index) self.assertEqual(3, node.position)
def test_node_no_star(self): root = TemplateNode() node = TemplateTopicStarNode() root.append(node) conversation = Conversation("testid", self.bot) question = Question.create_from_text("Hello world") question.current_sentence()._response = "Hello matey" conversation.record_dialog(question) question = Question.create_from_text("How are you") question.current_sentence()._response = "Very well thanks" conversation.record_dialog(question) self.bot._conversations["testid"] = conversation self.assertEqual("", root.resolve(self.bot, self.clientid))
def test_node_with_star_with_none(self): root = TemplateNode() node = TemplateTopicStarNode() root.append(node) conversation = Conversation("testid", self.bot) question = Question.create_from_text("Hello world") question.current_sentence()._response = "Hello matey" conversation.record_dialog(question) question = Question.create_from_text("How are you") question.current_sentence()._response = "Very well thanks" conversation.record_dialog(question) match = PatternOneOrMoreWildCardNode("*") context = MatchContext() context.add_match(Match(Match.TOPIC, match, None)) question.current_sentence()._matched_context = context conversation.record_dialog(question) self.bot._conversations["testid"] = conversation self.assertEqual("", root.resolve(self.bot, self.clientid))
def test_to_str_no_defaults(self): node = TemplateTopicStarNode(index=2) self.assertEquals("TOPICSTAR index=2", node.to_string())
def __init__(self): TemplateTopicStarNode.__init__(self)
def test_to_str_defaults(self): node = TemplateTopicStarNode() self.assertEqual("[TOPICSTAR[WORD]1]", node.to_string())
def test_to_str_no_defaults(self): node = TemplateTopicStarNode(index=2) self.assertEquals("TOPICSTAR index=2", node.to_string())
def __init__(self): TemplateTopicStarNode.__init__(self)