当前位置: 首页>>代码示例>>Python>>正文


Python RootTreeNode.new_child方法代码示例

本文整理汇总了Python中skcode.etree.RootTreeNode.new_child方法的典型用法代码示例。如果您正苦于以下问题:Python RootTreeNode.new_child方法的具体用法?Python RootTreeNode.new_child怎么用?Python RootTreeNode.new_child使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在skcode.etree.RootTreeNode的用法示例。


在下文中一共展示了RootTreeNode.new_child方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_debug_print_ast_with_erroneous_parent

# 需要导入模块: from skcode.etree import RootTreeNode [as 别名]
# 或者: from skcode.etree.RootTreeNode import new_child [as 别名]
    def test_debug_print_ast_with_erroneous_parent(self):
        """ Test if the ``debug_print_ast`` work as expected when an erroneous aprent is found. """
        # RootTreeNode
        #  - level 1 child 1
        #   - level 2 child 1
        #     - level 3 child 1
        #  - level 1 child 2
        root_tree_node = RootTreeNode()
        l1_tree_node = root_tree_node.new_child('level_1_child_1', DummyTreeNode, attrs={'foo': 'bar'})
        root_tree_node.new_child('level_1_child_2', DummyTreeNode)
        l2_tree_node = l1_tree_node.new_child('level_2_child_1', DummyTreeNode)
        l3_tree_node = l2_tree_node.new_child('level_3_child_1', DummyTreeNode, content='Hello world!')

        # Add some oops
        l3_tree_node.parent = root_tree_node

        output_returned = []

        def _print_to_str(*args):
            output_returned.append(' '.join(args))
        debug_print_ast(root_tree_node, print_fnct=_print_to_str)

        expected_output = [
            "RootTreeNode(name=\"None\", attrs={}, content='', len(children)=2) ",
            "    DummyTreeNode(name=\"level_1_child_1\", attrs={'foo': 'bar'}, content='', len(children)=1) ",
            "        DummyTreeNode(name=\"level_2_child_1\", attrs={}, content='', len(children)=1) ",
            "            DummyTreeNode(name=\"level_3_child_1\", attrs={}, content='Hello world!', len(children)=0) !! Parent mismatch !!",
            "    DummyTreeNode(name=\"level_1_child_2\", attrs={}, content='', len(children)=0) "
        ]
        self.maxDiff = None
        self.assertEqual(expected_output, output_returned)
开发者ID:TamiaLab,项目名称:PySkCode,代码行数:33,代码来源:tests_etree.py

示例2: test_render_to_html_with_error_suppressed

# 需要导入模块: from skcode.etree import RootTreeNode [as 别名]
# 或者: from skcode.etree.RootTreeNode import new_child [as 别名]
 def test_render_to_html_with_error_suppressed(self):
     """ Test the ``render_to_html`` function with erroneous node (error suppressed) """
     root_tree_node = RootTreeNode()
     tree_node_l1 = root_tree_node.new_child('level1', get_test_node('level1-1'),
                                             source_open_tag='[level1-1]',
                                             source_close_tag='[/level1-1]', error_message='foo')
     tree_node_l1.error_message = 'foo'
     root_tree_node.new_child('level1', get_test_node('level1-2'))
     tree_node_l2 = tree_node_l1.new_child('level2', get_test_node('level2-1'))
     tree_node_l1.new_child('level2', get_test_node('level2-2'))
     root_tree_node.new_child('level1', get_test_node('level1-3'))
     tree_node_l2.new_child('level3', get_test_node('level3-1'))
     tree_node_l3 = tree_node_l2.new_child('level3', get_test_node('level3-2'),
                                           source_open_tag='[level3-2]',
                                           source_close_tag='[/level3-2]', error_message='bar')
     tree_node_l3.error_message = 'bar'
     tree_node_l1.new_child('level2', get_test_node('level2-3'))
     output = render_to_html(root_tree_node,
                             html_error_template=SUPPRESS_ERROR_HTML_TEMPLATE,
                             some_custom_kwarg='foobar')
     expected_output = '<!-- foo --> [level1-1]\n' \
                       '[HTML+level2-1]' \
                       '[HTML+level3-1][/HTML]' \
                       '<!-- bar --> [level3-2]\n<!-- bar --> [/level3-2]' \
                       '[/HTML]' \
                       '[HTML+level2-2][/HTML]' \
                       '[HTML+level2-3][/HTML]\n' \
                       '<!-- foo --> [/level1-1]' \
                       '[HTML+level1-2][/HTML]' \
                       '[HTML+level1-3][/HTML]'
     self.assertEqual(expected_output, output)
开发者ID:TamiaLab,项目名称:PySkCode,代码行数:33,代码来源:tests_render.py

示例3: test_get_attribute_value_second_try

# 需要导入模块: from skcode.etree import RootTreeNode [as 别名]
# 或者: from skcode.etree.RootTreeNode import new_child [as 别名]
 def test_get_attribute_value_second_try(self):
     """ Test the ``get_attribute_value`` helper method """
     document_tree = RootTreeNode()
     tree_node = document_tree.new_child('node', DummyTreeNode, attrs={'at1': '', 'at2': 'bar', 'at3': 'baz'})
     self.assertEqual('bar', tree_node.get_attribute_value('at1', 'at2', 'at3'))
     tree_node = document_tree.new_child('node', DummyTreeNode, attrs={'at3': 'baz'})
     self.assertEqual('baz', tree_node.get_attribute_value('at1', 'at2', 'at3'))
开发者ID:TamiaLab,项目名称:PySkCode,代码行数:9,代码来源:tests_etree.py

示例4: test_render_to_html_with_error

# 需要导入模块: from skcode.etree import RootTreeNode [as 别名]
# 或者: from skcode.etree.RootTreeNode import new_child [as 别名]
 def test_render_to_html_with_error(self):
     """ Test the ``render_to_html`` function with erroneous node """
     root_tree_node = RootTreeNode()
     tree_node_l1 = root_tree_node.new_child('level1', get_test_node('level1-1'),
                                             source_open_tag='[level1-1]',
                                             source_close_tag='[/level1-1]', error_message='foo')
     tree_node_l1.error_message = 'foo'
     root_tree_node.new_child('level1', get_test_node('level1-2'))
     tree_node_l2 = tree_node_l1.new_child('level2', get_test_node('level2-1'))
     tree_node_l1.new_child('level2', get_test_node('level2-2'))
     root_tree_node.new_child('level1', get_test_node('level1-3'))
     tree_node_l2.new_child('level3', get_test_node('level3-1'))
     tree_node_l3 = tree_node_l2.new_child('level3', get_test_node('level3-2'),
                                           source_open_tag='[level3-2]',
                                           source_close_tag='[/level3-2]', error_message='bar')
     tree_node_l3.error_message = 'bar'
     tree_node_l1.new_child('level2', get_test_node('level2-3'))
     output = render_to_html(root_tree_node,
                             html_error_template='<error={error_message}>{source}</error>',
                             some_custom_kwarg='foobar')
     expected_output = '<error=foo>[level1-1]</error>\n' \
                       '[HTML+level2-1]' \
                       '[HTML+level3-1][/HTML]' \
                       '<error=bar>[level3-2]</error>\n<error=bar>[/level3-2]</error>' \
                       '[/HTML]' \
                       '[HTML+level2-2][/HTML]' \
                       '[HTML+level2-3][/HTML]\n' \
                       '<error=foo>[/level1-1]</error>' \
                       '[HTML+level1-2][/HTML]' \
                       '[HTML+level1-3][/HTML]'
     self.assertEqual(expected_output, output)
开发者ID:TamiaLab,项目名称:PySkCode,代码行数:33,代码来源:tests_render.py

示例5: test_has_errors_true

# 需要导入模块: from skcode.etree import RootTreeNode [as 别名]
# 或者: from skcode.etree.RootTreeNode import new_child [as 别名]
 def test_has_errors_true(self):
     """ Test the ``has_errors`` helper. """
     document_tree = RootTreeNode()
     document_tree.new_child('node', DummyTreeNode)
     l1_tree_node = document_tree.new_child('test_l1', OtherDummyTreeNode)
     l1_tree_node.new_child('node', DummyTreeNode)
     l2_tree_node = l1_tree_node.new_child('test_l2', OtherDummyTreeNode, error_message='foobar')
     l2_tree_node.new_child('node', DummyTreeNode)
     self.assertTrue(document_tree.has_errors())
开发者ID:TamiaLab,项目名称:PySkCode,代码行数:11,代码来源:tests_etree.py

示例6: test_has_errors_false

# 需要导入模块: from skcode.etree import RootTreeNode [as 别名]
# 或者: from skcode.etree.RootTreeNode import new_child [as 别名]
 def test_has_errors_false(self):
     """ Test the ``has_errors`` helper. """
     document_tree = RootTreeNode()
     document_tree.new_child('node', DummyTreeNode)
     l1_tree_node = document_tree.new_child('test_l1', OtherDummyTreeNode)
     l1_tree_node.new_child('node', DummyTreeNode)
     l2_tree_node = l1_tree_node.new_child('test_l2', OtherDummyTreeNode)
     l2_tree_node.new_child('node', DummyTreeNode)
     self.assertFalse(document_tree.has_errors())
开发者ID:TamiaLab,项目名称:PySkCode,代码行数:11,代码来源:tests_etree.py

示例7: test_sanitize_node_erroneous_language_name

# 需要导入模块: from skcode.etree import RootTreeNode [as 别名]
# 或者: from skcode.etree.RootTreeNode import new_child [as 别名]
 def test_sanitize_node_erroneous_language_name(self):
     """ Test the ``sanitize_node`` method with erroneous language name. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('code', CodeBlockTreeNode, attrs={})
     tree_node.sanitize_node([])
     self.assertEqual('', tree_node.error_message)
     tree_node = root_tree_node.new_child('code', CodeBlockTreeNode, attrs={'code': 'foobar'})
     tree_node.sanitize_node([])
     self.assertEqual('Unknown language', tree_node.error_message)
开发者ID:TamiaLab,项目名称:PySkCode,代码行数:11,代码来源:tests_codeblocks.py

示例8: test_sanitize_node

# 需要导入模块: from skcode.etree import RootTreeNode [as 别名]
# 或者: from skcode.etree.RootTreeNode import new_child [as 别名]
 def test_sanitize_node(self):
     """ Test if the ``sanitize_node`` method mark the node as erroneous when title is missing """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('color', ColorTextTreeNode, attrs={'color': 'blue'})
     tree_node.sanitize_node([])
     self.assertEqual('', tree_node.error_message)
     tree_node = root_tree_node.new_child('color', ColorTextTreeNode, attrs={'color': ''})
     tree_node.sanitize_node([])
     self.assertEqual('Missing color value', tree_node.error_message)
开发者ID:TamiaLab,项目名称:PySkCode,代码行数:11,代码来源:tests_textcolors.py

示例9: test_sanitize_node

# 需要导入模块: from skcode.etree import RootTreeNode [as 别名]
# 或者: from skcode.etree.RootTreeNode import new_child [as 别名]
 def test_sanitize_node(self):
     """ Test if the ``sanitize_node`` method mark the node as erroneous when title is missing """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('email', EmailLinkTreeNode, attrs={})
     tree_node.sanitize_node([])
     self.assertEqual('Missing or erroneous target email address', tree_node.error_message)
     tree_node = root_tree_node.new_child('email', EmailLinkTreeNode, attrs={'email': '[email protected]'})
     tree_node.sanitize_node([])
     self.assertEqual('', tree_node.error_message)
开发者ID:TamiaLab,项目名称:PySkCode,代码行数:11,代码来源:tests_links.py

示例10: test_make_paragraphs_erroneous_nodes

# 需要导入模块: from skcode.etree import RootTreeNode [as 别名]
# 或者: from skcode.etree.RootTreeNode import new_child [as 别名]
 def test_make_paragraphs_erroneous_nodes(self):
     """ Test the ``make_paragraphs`` paragraph utility. """
     root_tree_node = RootTreeNode()
     a = root_tree_node.new_child(None, TextTreeNode, content='Text 1')
     b = root_tree_node.new_child(None, TextTreeNode, content='', error_message='Foobar')
     c = root_tree_node.new_child(None, NewlineTreeNode)
     make_paragraphs(root_tree_node)
     self.assertEqual(len(root_tree_node.children), 1)
     self.assertIsInstance(root_tree_node.children[0], ParagraphTreeNode)
     self.assertEqual([a, b, c], root_tree_node.children[0].children)
开发者ID:TamiaLab,项目名称:PySkCode,代码行数:12,代码来源:tests_paragraphs.py

示例11: test_sanitize_node

# 需要导入模块: from skcode.etree import RootTreeNode [as 别名]
# 或者: from skcode.etree.RootTreeNode import new_child [as 别名]
 def test_sanitize_node(self):
     """ Test if the ``sanitize_node`` method mark the node as erroneous when title is missing """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('youtube', YoutubeTreeNode,
                                          content='https://www.youtube.com/watch?v=dQw4w9WgXcQ')
     tree_node.sanitize_node([])
     self.assertEqual('', tree_node.error_message)
     tree_node = root_tree_node.new_child('youtube', YoutubeTreeNode, content='')
     tree_node.sanitize_node([])
     self.assertEqual('Missing or erroneous video URL', tree_node.error_message)
开发者ID:TamiaLab,项目名称:PySkCode,代码行数:12,代码来源:tests_medias.py

示例12: test_search_in_tree

# 需要导入模块: from skcode.etree import RootTreeNode [as 别名]
# 或者: from skcode.etree.RootTreeNode import new_child [as 别名]
 def test_search_in_tree(self):
     """ Test the ``search_in_tree`` helper. """
     document_tree = RootTreeNode()
     node1 = document_tree.new_child('node', DummyTreeNode)
     l1_tree_node = document_tree.new_child('test_l1', OtherDummyTreeNode)
     node2 = l1_tree_node.new_child('node', DummyTreeNode)
     l2_tree_node = l1_tree_node.new_child('test_l2', OtherDummyTreeNode)
     node3 = l2_tree_node.new_child('node', DummyTreeNode)
     nodes = list(document_tree.search_in_tree(DummyTreeNode))
     self.assertEqual([node1, node2, node3], nodes)
开发者ID:TamiaLab,项目名称:PySkCode,代码行数:12,代码来源:tests_etree.py

示例13: test_make_paragraphs_custom_class

# 需要导入模块: from skcode.etree import RootTreeNode [as 别名]
# 或者: from skcode.etree.RootTreeNode import new_child [as 别名]
 def test_make_paragraphs_custom_class(self):
     """ Test the ``make_paragraphs`` paragraph utility. """
     root_tree_node = RootTreeNode()
     a = root_tree_node.new_child(None, TextTreeNode, content='Text 1')
     b = root_tree_node.new_child(None, NewlineTreeNode)
     c = root_tree_node.new_child(None, TextTreeNode, content='Text 1')
     d = root_tree_node.new_child(None, NewlineTreeNode)
     make_paragraphs(root_tree_node, paragraph_node_cls=CustomParagraphTreeNode)
     self.assertEqual(len(root_tree_node.children), 1)
     self.assertIsInstance(root_tree_node.children[0], CustomParagraphTreeNode)
     self.assertEqual([a, b, c, d], root_tree_node.children[0].children)
开发者ID:TamiaLab,项目名称:PySkCode,代码行数:13,代码来源:tests_paragraphs.py

示例14: test_make_paragraphs_trailing_newline

# 需要导入模块: from skcode.etree import RootTreeNode [as 别名]
# 或者: from skcode.etree.RootTreeNode import new_child [as 别名]
 def test_make_paragraphs_trailing_newline(self):
     """ Test the ``make_paragraphs`` paragraph utility. """
     root_tree_node = RootTreeNode()
     z = root_tree_node.new_child(None, NewlineTreeNode)
     a = root_tree_node.new_child(None, TextTreeNode, content='Text 1')
     b = root_tree_node.new_child(None, NewlineTreeNode)
     make_paragraphs(root_tree_node)
     self.assertEqual(len(root_tree_node.children), 2)
     self.assertEqual(root_tree_node.children[0], z)
     self.assertIsInstance(root_tree_node.children[1], ParagraphTreeNode)
     self.assertEqual([a, b], root_tree_node.children[1].children)
开发者ID:TamiaLab,项目名称:PySkCode,代码行数:13,代码来源:tests_paragraphs.py

示例15: test_pre_process_node

# 需要导入模块: from skcode.etree import RootTreeNode [as 别名]
# 或者: from skcode.etree.RootTreeNode import new_child [as 别名]
 def test_pre_process_node(self):
     """ Test the ``pre_process_node`` method. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('figure', FigureDeclarationTreeNode)
     tree_node.pre_process_node()
     self.assertEqual('', tree_node.error_message)
     self.assertEqual({'figure-1'}, root_tree_node.known_ids)
     tree_node = root_tree_node.new_child('figure', FigureDeclarationTreeNode, attrs={'id': 'figure-1'})
     tree_node.pre_process_node()
     self.assertEqual('ID already used previously', tree_node.error_message)
     self.assertEqual({'figure-1'}, root_tree_node.known_ids)
开发者ID:TamiaLab,项目名称:PySkCode,代码行数:13,代码来源:tests_figures.py


注:本文中的skcode.etree.RootTreeNode.new_child方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。