comparison emeraldtree/tests/test_tree.py @ 59:33f5e57f1b97

more xpath tests, 3 of them are skipped because they fail
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 18 May 2010 14:20:34 +0200
parents 9d0db78957e0
children 0c6020f1a2be
comparison
equal deleted inserted replaced
58:9d0db78957e0 59:33f5e57f1b97
128 128
129 result = list(elem.findall(u'{url1}b1')) 129 result = list(elem.findall(u'{url1}b1'))
130 assert len(result) == 1 130 assert len(result) == 1
131 assert result[0] is child_1 131 assert result[0] is child_1
132 132
133 def test_Element_findall_tag_multimatch():
134 c1 = Element(u'c')
135 c2 = Element(u'c')
136 text = u"text"
137 b1 = Element(u'b', children=(c1, text, c2))
138 b2 = Element(u'b')
139 a1 = Element(u'a', children=(b1, b2, ))
140
141 result = list(b1.findall(u'c'))
142 assert len(result) == 2
143 assert result[0] is c1
144 assert result[1] is c2
145
146 result = list(a1.findall(u'c'))
147 assert len(result) == 0 # no 'c' childs
148
149 result = list(a1.findall(u'*/c'))
150 assert len(result) == 2 # but 2 'c' grandchilds
151 assert result[0] is c1
152 assert result[1] is c2
153
154 def test_Element_findall_bracketed_tag():
155 c1 = Element(u'c')
156 c2 = Element(u'c')
157 text = u"text"
158 b1 = Element(u'b', children=(c1, text, c2))
159 b2 = Element(u'b')
160 a1 = Element(u'a', children=(b1, b2, ))
161
162 result = list(b1.findall(u'[c]'))
163 assert len(result) == 1
164 assert result[0] is b1 # b1 has 'c' childs
165
166 result = list(a1.findall(u'*/[c]'))
167 assert len(result) == 1
168 assert result[0] is b1 # b1 has 'c' childs
169
170 def test_Element_findall_dotdot():
171 py.test.skip('broken')
172 c1 = Element(u'c')
173 c2 = Element(u'c')
174 text = u"text"
175 b1 = Element(u'b', children=(c1, text, c2))
176 b2 = Element(u'b')
177 a1 = Element(u'a', children=(b1, b2, ))
178
179 result = list(c1.findall(u'../c'))
180 assert len(result) == 2
181 assert result[0] is c1
182 assert result[1] is c2
183
184 def test_Element_findall_slashslash():
185 py.test.skip('broken')
186 c1 = Element(u'c')
187 c2 = Element(u'c')
188 text = u"text"
189 b1 = Element(u'b', children=(c1, text, c2))
190 b2 = Element(u'b')
191 a1 = Element(u'a', children=(b1, b2, ))
192
193 a1t = ElementTree(element=a1) # we need a tree to use //
194 result = list(a1t.findall(u'//c'))
195 assert len(result) == 2
196 assert result[0] is c1
197 assert result[1] is c2
198
199 def test_Element_findall_dotslashslash():
200 py.test.skip('broken')
201 c1 = Element(u'c')
202 c2 = Element(u'c')
203 text = u"text"
204 b1 = Element(u'b', children=(c1, text, c2))
205 b2 = Element(u'b')
206 a1 = Element(u'a', children=(b1, b2, ))
207
208 result = list(a1.findall(u'.//c'))
209 assert len(result) == 2
210 assert result[0] is c1
211 assert result[1] is c2
212
133 def test_Element_findtext_default(): 213 def test_Element_findtext_default():
134 elem = Element(u'a') 214 elem = Element(u'a')
135 default_text = u'defaulttext' 215 default_text = u'defaulttext'
136 result = elem.findtext(u'doesnotexist', default=default_text) 216 result = elem.findtext(u'doesnotexist', default=default_text)
137 assert result is default_text 217 assert result is default_text