本文整理汇总了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)
示例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)
示例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'))
示例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)
示例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())
示例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())
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)