Skip to content

Commit 190cc4e

Browse files
fix .// xpath queries
Previously, when iter() encountered a non-Element child (like a text string), it would yield it unconditionally, even if the caller was searching for a specific tag (e.g., .//c). ``` def test_Element_findall_dotslashslash(): c1 = Element('c') c2 = Element('c') text = "text" b1 = Element('b', children=(c1, text, c2)) b2 = Element('b') a1 = Element('a', children=(b1, b2, )) result = list(a1.findall('.//c')) > assert len(result) == 2 E AssertionError: assert 3 == 2 E + where 3 = len([<Element 'c' at 1056c4450>, 'text', <Element 'c' at 1056c4810>]) src/emeraldtree/tests/test_tree.py:208: AssertionError ``` The fix ensures that non-Element children are only yielded if no tag filter is specified (tag is None).
1 parent db127d7 commit 190cc4e

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/emeraldtree/tests/test_tree.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ def test_Element_findall_dotdot():
184184
assert result[1] is c2
185185

186186
def test_Element_findall_slashslash():
187-
pytest.skip('broken')
188187
c1 = Element('c')
189188
c2 = Element('c')
190189
text = "text"
@@ -199,7 +198,6 @@ def test_Element_findall_slashslash():
199198
assert result[1] is c2
200199

201200
def test_Element_findall_dotslashslash():
202-
pytest.skip('broken')
203201
c1 = Element('c')
204202
c2 = Element('c')
205203
text = "text"

src/emeraldtree/tree.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ def iter(self, tag=None):
355355
for e in e.iter(tag):
356356
yield e
357357
else:
358-
yield e
358+
if tag is None:
359+
yield e
359360

360361
##
361362
# Creates a text iterator. The iterator loops over this element

0 commit comments

Comments
 (0)