Пример #1
0
    def test_resolve_with_no_defaults(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateRequestNode(index=1)
        self.assertIsNotNone(node)

        root.append(node)
        self.assertEqual(len(root.children), 1)
        self.assertEqual(1, node.index)

        conversation = Conversation(self._client_context)
        self._client_context.bot._conversations["testid"] = conversation

        question = Question.create_from_text(
            self._client_context.brain.nlp.tokenizer, "Hello world")
        question.current_sentence()._response = "Hello matey"
        conversation._questions.append(question)

        question = Question.create_from_text(
            self._client_context.brain.nlp.tokenizer, "What did you say")
        question.current_sentence()._response = "Hello matey"
        conversation._questions.append(question)

        response = root.resolve(self._client_context)
        self.assertIsNotNone(response)
        self.assertEqual(response, "Hello world")
Пример #2
0
    def test_resolve_no_sentence(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateRequestNode(index=3)
        self.assertIsNotNone(node)

        root.append(node)
        self.assertEqual(len(root.children), 1)
        self.assertEqual(3, node.index)

        conversation = Conversation(self._client_context)

        question = Question.create_from_text(
            self._client_context.brain.nlp.tokenizer, "Hello world")
        question.current_sentence()._response = "Hello matey"
        conversation.record_question(question)

        question = Question.create_from_text(
            self._client_context.brain.nlp.tokenizer,
            "How are you. Are you well")
        question.current_sentence()._response = "Fine thanks"
        conversation.record_question(question)

        self._client_context.bot._conversations["testid"] = conversation

        response = root.resolve(self._client_context)
        self.assertIsNotNone(response)
        self.assertEqual(response, "")
Пример #3
0
    def test_to_xml_no_defaults(self):
        root = TemplateNode()
        node = TemplateRequestNode(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><request index="3" /></template>', xml_str)
Пример #4
0
 def test_to_str_no_defaults(self):
     node = TemplateRequestNode(index=2)
     self.assertEquals("REQUEST index=2", node.to_string())
Пример #5
0
 def test_to_str_defaults(self):
     node = TemplateRequestNode()
     self.assertEquals("REQUEST", node.to_string())
Пример #6
0
 def __init__(self):
     TemplateRequestNode.__init__(self)