예제 #1
0
파일: graph.py 프로젝트: Doshmaku/program-y
    def parse_bot_expression(self, expression, branch):

        bot_node = TemplateBotNode()
        branch.children.append(bot_node)

        name_found = False

        if 'name' in expression.attrib:
            node = TemplateNode()
            name_node = TemplateWordNode(expression.attrib['name'])
            node.append(name_node)
            name_found = True
            bot_node.name = node

        self.parse_text(self.get_text_from_element(expression), bot_node)

        for child in expression:

            if child.tag == 'name':
                node = TemplateNode()
                self.parse_text(self.get_text_from_element(child), node)
                for sub_child in child:
                    self.parse_tag_expression(sub_child, node)
                    self.parse_text(self.get_text_from_element(child), node)

                bot_node.name = node
                name_found = True

            else:
                self.parse_tag_expression(child, bot_node)

            self.parse_text(self.get_tail_from_element(child), bot_node)

        if name_found is False:
            raise ParserException("Error, name not found", xml_element=expression)
예제 #2
0
    def test_to_xml(self):
        root = TemplateNode()
        node = TemplateBotNode()
        node.name = TemplateWordNode("name")
        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><bot name="name" /></template>', xml_str)
예제 #3
0
    def test_to_xml(self):
        root = TemplateNode()
        node = TemplateBotNode()
        node.name = TemplateWordNode("name")
        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><bot name="name" /></template>', xml_str)
예제 #4
0
파일: test_bot.py 프로젝트: lilnana00/3ddd
    def test_node_no_default_get(self):
        self._client_context.brain.configuration.defaults._default_get = None

        root = TemplateNode()
        node = TemplateBotNode()
        node.name = TemplateWordNode("location")
        root.append(node)

        result = node.resolve(self._client_context)
        self.assertIsNotNone(result)
        self.assertEquals("unknown", result)
예제 #5
0
    def test_node_no_value(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateBotNode()
        self.assertIsNotNone(node)
        node.name = TemplateWordNode("location")
        root.append(node)
        self.assertEqual(len(root.children), 1)

        self.bot.brain.properties.add_property("default-property", "unknown")

        result = node.resolve(self.bot, self.clientid)
        self.assertIsNotNone(result)
        self.assertEqual("unknown", result)
예제 #6
0
    def test_node_no_value(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateBotNode()
        self.assertIsNotNone(node)
        node.name = TemplateWordNode("location")
        root.append(node)
        self.assertEqual(len(root.children), 1)

        self._client_context.brain.properties.add_property("default-property", "unknown")

        result = node.resolve(self._client_context)
        self.assertIsNotNone(result)
        self.assertEqual("unknown", result)
예제 #7
0
    def test_node(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateBotNode()
        self.assertIsNotNone(node)
        node.name = TemplateWordNode("location")
        root.append(node)
        self.assertEqual(len(root.children), 1)

        self.bot.brain.properties.add_property("location", "Scotland")

        result = node.resolve(self.bot, self.clientid)
        self.assertIsNotNone(result)
        self.assertEqual("Scotland", result)
예제 #8
0
    def test_node(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        node = TemplateBotNode()
        self.assertIsNotNone(node)
        node.name = TemplateWordNode("location")
        root.append(node)
        self.assertEqual(len(root.children), 1)

        self._client_context.brain.properties.add_property("location", "Scotland")

        result = node.resolve(self._client_context)
        self.assertIsNotNone(result)
        self.assertEqual("Scotland", result)