diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-10-14 07:32:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-14 07:32:19 (GMT) |
commit | b11c5667f99c4f0018e3394c4d07c519d835671a (patch) | |
tree | ac3b022a3fd36c1016bc7f630c7ed858028522ad /Lib | |
parent | d274afb5e579a5d9d990f68f9af856cf4c918779 (diff) | |
download | cpython-b11c5667f99c4f0018e3394c4d07c519d835671a.zip cpython-b11c5667f99c4f0018e3394c4d07c519d835671a.tar.gz cpython-b11c5667f99c4f0018e3394c4d07c519d835671a.tar.bz2 |
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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_xml_etree.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index ecb910f..61416ba 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -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): |