mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-34941: Fix searching Element subclasses. (GH-9766)
Methods find(), findtext() and findall() of xml.etree.ElementTree.Element were not able to find chldren which are instances of Element subclasses.
This commit is contained in:
parent
d274afb5e5
commit
b11c5667f9
3 changed files with 31 additions and 12 deletions
|
@ -2160,6 +2160,21 @@ class ElementTreeTypeTest(unittest.TestCase):
|
|||
mye = MyElement('joe')
|
||||
self.assertEqual(mye.newmethod(), 'joe')
|
||||
|
||||
def test_Element_subclass_find(self):
|
||||
class MyElement(ET.Element):
|
||||
pass
|
||||
|
||||
e = ET.Element('foo')
|
||||
e.text = 'text'
|
||||
sub = MyElement('bar')
|
||||
sub.text = 'subtext'
|
||||
e.append(sub)
|
||||
self.assertEqual(e.findtext('bar'), 'subtext')
|
||||
self.assertEqual(e.find('bar').tag, 'bar')
|
||||
found = list(e.findall('bar'))
|
||||
self.assertEqual(len(found), 1, found)
|
||||
self.assertEqual(found[0].tag, 'bar')
|
||||
|
||||
|
||||
class ElementFindTest(unittest.TestCase):
|
||||
def test_find_simple(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue