comparison emeraldtree/tests/test_ElementTree.py @ 32:7b5ed8600569

Testcases for ElementTree - Add testcases for find and findall
author Bastian Blank <bblank@thinkmo.de>
date Tue, 08 Jul 2008 15:05:25 +0200
parents 96e02876b1a2
children 6e38bcef6030
comparison
equal deleted inserted replaced
31:1b94f5f045de 32:7b5ed8600569
84 84
85 def test_Element_remove(): 85 def test_Element_remove():
86 pass 86 pass
87 87
88 def test_Element_find(): 88 def test_Element_find():
89 elem_1 = Element('b1') 89 child_1 = Element('b1')
90 elem_2 = Element('b2') 90 child_2 = Element('b2')
91 elem = Element('a', children=[elem_1, elem_2]) 91 elem = Element('a', children=[child_1, child_2])
92 92
93 result = elem.find('b1') 93 result = elem.find('b1')
94 assert result is elem_1 94 assert result is child_1
95 95
96 result = elem.find('b2') 96 result = elem.find('b2')
97 assert result is elem_2 97 assert result is child_2
98
99 child_1 = Element(QName('b1', 'url1'))
100 child_2 = Element(QName('{url2}b2'))
101 elem = Element('a', children=[child_1, child_2])
102
103 result = elem.find('{url1}b1')
104 assert result is child_1
98 105
99 def test_Element_findtext(): 106 def test_Element_findtext():
100 pass 107 pass
101 108
102 def test_Element_findall(): 109 def test_Element_findall():
103 pass 110 child_1 = Element('b1')
111 child_2 = Element('b2')
112 child_3 = "text"
113 elem = Element('a', children=[child_1, child_2, child_3])
114
115 result = list(elem.findall('b1'))
116 assert len(result) == 1
117 assert result[0] is child_1
118
119 result = list(elem.findall('b2'))
120 assert len(result) == 1
121 assert result[0] is child_2
122
123 result = list(elem.findall('*'))
124 assert len(result) == 3
125 assert result[0] is child_1
126 assert result[1] is child_2
127 assert result[2] is child_3
128
129 child_1 = Element(QName('b1', 'url1'))
130 child_2 = Element(QName('{url2}b2'))
131 elem = Element('a', children=[child_1, child_2])
132
133 result = list(elem.findall('{url1}b1'))
134 assert len(result) == 1
135 assert result[0] is child_1
104 136
105 def test_Element_clear(): 137 def test_Element_clear():
106 pass 138 pass
107 139
108 def test_Element_get(): 140 def test_Element_get():
182 214
183 def test_QName___cmp__(): 215 def test_QName___cmp__():
184 qname1 = QName('a') 216 qname1 = QName('a')
185 qname2 = QName('a') 217 qname2 = QName('a')
186 218
187 assert cmp(qname1, qname2) == 0 219 assert qname1 == qname2
220 assert qname1 == 'a'
221 assert 'a' == qname1
222
223 qname1 = QName('a', 'b')
224 qname2 = QName('{b}a')
225
226 assert qname1 == qname2
227 assert qname1 == '{b}a'
228 assert '{b}a' == qname1
188 229
189 def test_XMLParser_simple1(): 230 def test_XMLParser_simple1():
190 elem = XML('<a />') 231 elem = XML('<a />')
191 assert elem.tag == 'a' 232 assert elem.tag == 'a'
192 assert len(elem) == 0 233 assert len(elem) == 0