summaryrefslogtreecommitdiff
path: root/Lib/test/test_xml_etree.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-10-14 00:55:49 -0700
committerGitHub <noreply@github.com>2018-10-14 00:55:49 -0700
commitb1c800303e8458e00428ae66351ad492a503a46f (patch)
treeac97472162be1d061af51e6651436cb72a06af15 /Lib/test/test_xml_etree.py
parent77e0abe228564a5be23284bd8e963c11952eb55b (diff)
downloadcpython-git-b1c800303e8458e00428ae66351ad492a503a46f.tar.gz
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. (cherry picked from commit b11c5667f99c4f0018e3394c4d07c519d835671a) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test/test_xml_etree.py')
-rw-r--r--Lib/test/test_xml_etree.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 088a04e98b..75c9c25a8b 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):