comparison emeraldtree/tests/test_HTMLTreeBuilder.py @ 51:847897e5fab8

HTMLTreeBuilder - Make namespace aware, add testcases
author Bastian Blank <bblank@thinkmo.de>
date Sun, 21 Sep 2008 11:01:19 +0200
parents
children
comparison
equal deleted inserted replaced
50:d3767204a325 51:847897e5fab8
1 import py.test
2 from emeraldtree.ElementTree import *
3 from emeraldtree.HTMLTreeBuilder import *
4
5 def serialize(elem, **options):
6 from cStringIO import StringIO
7 file = StringIO()
8 tree = ElementTree(elem)
9 tree.write(file, **options)
10 return file.getvalue()
11
12 def test_HTMLParser_simple1():
13 elem = HTML('<a></a>')
14 assert elem.tag.name == 'a'
15 assert len(elem) == 0
16
17 def test_XMLParser_simple2():
18 elem = HTML('<a><b /></a>')
19 assert elem.tag.name == 'a'
20 assert len(elem) == 1
21 assert elem[0].tag.name == 'b'
22 assert len(elem[0]) == 0
23
24 def test_XMLParser_text1():
25 elem = HTML('<a>b</a>')
26 assert elem.tag.name == 'a'
27 assert isinstance(elem, Element)
28 assert len(elem) == 1
29 assert elem[0] == 'b'
30 assert isinstance(elem[0], unicode)
31
32 def test_XMLParser_text2():
33 elem = HTML('<a>b<c>d</c>d</a>')
34 assert elem.tag.name == 'a'
35 assert len(elem) == 3
36 assert elem[0] == 'b'
37 assert elem[1].tag.name == 'c'
38 assert elem[2] == 'd'
39
40 def test_HTMLParser_ignoreend():
41 elem = HTML('<br>')
42 assert elem.tag.name == 'br'
43 assert len(elem) == 0
44
45 elem = HTML('<br></br>')
46 assert elem.tag.name == 'br'
47 assert len(elem) == 0
48
49