示例#1
0
 def test_is_last(self):
     doc = mock_document()
     root = XmlNode(doc, 'html')
     child_one = XmlNode(doc, 'head').append_to(root)
     child_two = XmlNode(doc, 'body').append_to(root)
     test.assert_false(child_one._is_last())
     test.assert_true(child_two._is_last())
示例#2
0
 def test_render_pretty(self):
     doc = mock_document()
     doc.indent = '..'
     node = XmlNode(doc, 'html')
     node.level = 0
     node.child_nodes.append(XmlNode(doc, 'body'))
     test.assert_equal(node.render(), '\n<html>\n..<body></body>\n</html>')
示例#3
0
 def test_render(self):
     doc = mock_document()
     node = XmlNode(doc, 'html', attrs={'lang': 'en'})
     body = XmlNode(doc, 'body', content='hello world')
     node.child_nodes.append(body)
     test.assert_equal(node.render(),
                       '<html><body>hello world</body></html>')
示例#4
0
 def test_render_pretty(self):
     doc = mock_document()
     doc.indent = '..'
     node = XmlNode(doc, 'html')
     node.level = 0
     node.child_nodes.append(XmlNode(doc, 'body'))
     test.assert_equal(node.render(), '\n<html>\n..<body></body>\n</html>')
示例#5
0
 def test_remove(self):
     doc = mock_document()
     root = XmlNode(doc, 'html')
     child_node = XmlNode(doc, 'head')
     root.child_nodes.append(child_node)
     child_node.parent_node = root
     test.assert_in(child_node, root.child_nodes)
     child_node.remove()
     test.assert_not_in(child_node, root.child_nodes)
示例#6
0
 def test_is_last(self):
     doc = mock_document()
     root = XmlNode(doc, 'html')
     child_one = XmlNode(doc, 'head').append_to(root)
     child_two = XmlNode(doc, 'body').append_to(root)
     test.assert_false(child_one._is_last())
     test.assert_true(child_two._is_last())
示例#7
0
 def test_render_escape(self):
     doc = mock_document()
     node = XmlNode(doc, 'body', content='<div>"hello"</div>')
     test.assert_equal(node.render(),
                       '<body>&lt;div&gt;"hello"&lt;/div&gt;</body>')
     node = XmlNode(doc, 'body', content='<div>"hello"</div>', safe=True)
     test.assert_equal(node.render(), '<body><div>"hello"</div></body>')
示例#8
0
 def test_remove(self):
     doc = mock_document()
     root = XmlNode(doc, 'html')
     child_node = XmlNode(doc, 'head')
     root.child_nodes.append(child_node)
     child_node.parent_node = root
     test.assert_in(child_node, root.child_nodes)
     child_node.remove()
     test.assert_not_in(child_node, root.child_nodes)
示例#9
0
 def test_render_escape(self):
     doc = mock_document()
     node = XmlNode(doc, 'body', content='<div>"hello"</div>')
     test.assert_equal(node.render(), '<body>&lt;div&gt;"hello"&lt;/div&gt;</body>')
     node = XmlNode(doc, 'body', content='<div>"hello"</div>', safe=True)
     test.assert_equal(node.render(), '<body><div>"hello"</div></body>')
示例#10
0
 def test_render(self):
     doc = mock_document()
     node = XmlNode(doc, 'html', attrs={'lang': 'en'})
     body = XmlNode(doc, 'body', content='hello world')
     node.child_nodes.append(body)
     test.assert_equal(node.render(), '<html><body>hello world</body></html>')
示例#11
0
 def test_append_to(self):
     doc = mock_document()
     root = XmlNode(doc, 'html')
     child = XmlNode(doc, 'body')
     child.append_to(root)
     test.assert_equal(root.child_nodes, [child])
示例#12
0
 def test_repr(self):
     node = XmlNode(mock_document(), 'html', attrs={'lang': 'ru'})
     test.assert_equal(repr(node), 'XmlNode(html, lang=ru)')
示例#13
0
 def test_init(self):
     doc = mock_document()
     node = XmlNode(doc, 'html', attrs={'lang': 'en'})
     test.assert_equal(node.tag_name, 'html')
     test.assert_equal(node.attrs, {'lang': 'en'})
示例#14
0
 def test_append_to(self):
     doc = mock_document()
     root = XmlNode(doc, 'html')
     child = XmlNode(doc, 'body')
     child.append_to(root)
     test.assert_equal(root.child_nodes, [child])