diff emeraldtree/tests/test_tree.py @ 60:0c6020f1a2be

more xpath tests, 1 is skipped because it is unsupported
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 18 May 2010 14:51:19 +0200
parents 33f5e57f1b97
children 6c0a8bd9aa9a
line wrap: on
line diff
--- a/emeraldtree/tests/test_tree.py	Tue May 18 14:20:34 2010 +0200
+++ b/emeraldtree/tests/test_tree.py	Tue May 18 14:51:19 2010 +0200
@@ -210,6 +210,36 @@
     assert result[0] is c1
     assert result[1] is c2
 
+def test_Element_findall_attribute():
+    c1 = Element(u'c')
+    c2 = Element(u'c', testattr='testvalue')
+    text = u"text"
+    b1 = Element(u'b', children=(c1, text, c2))
+    b2 = Element(u'b')
+    a1 = Element(u'a', children=(b1, b2, ))
+
+    result = list(b1.findall(u"c[@testattr='testvalue']"))
+    # note: does not work without c, like b1.findall(u"[@testattr='testvalue']") - should it?
+    assert len(result) == 1
+    assert result[0] is c2
+
+def test_Element_findall_position():
+    py.test.skip('not supported')
+    c1 = Element(u'c')
+    c2 = Element(u'c')
+    text = u"text"
+    b1 = Element(u'b', children=(c1, text, c2))
+    b2 = Element(u'b')
+    a1 = Element(u'a', children=(b1, b2, ))
+
+    result = list(b1.findall(u'c[1]')) # note: index is 1-based, [1] (not [0]) is first
+    assert len(result) == 1
+    assert result[0] is c1
+
+    result = list(b1.findall(u'c[2]'))
+    assert len(result) == 1
+    assert result[0] is c2
+
 def test_Element_findtext_default():
     elem = Element(u'a')
     default_text = u'defaulttext'