MCPcopy Index your code
hub / github.com/python/cpython / test_find_simple

Method test_find_simple

Lib/test/test_xml_etree.py:3356–3377  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3354
3355class ElementFindTest(unittest.TestCase):
3356 def test_find_simple(self):
3357 e = ET.XML(SAMPLE_XML)
3358 self.assertEqual(e.find('tag').tag, 'tag')
3359 self.assertEqual(e.find('section/tag').tag, 'tag')
3360 self.assertEqual(e.find('./tag').tag, 'tag')
3361
3362 e[2] = ET.XML(SAMPLE_SECTION)
3363 self.assertEqual(e.find('section/nexttag').tag, 'nexttag')
3364
3365 self.assertEqual(e.findtext('./tag'), 'text')
3366 self.assertEqual(e.findtext('section/tag'), 'subtext')
3367
3368 # section/nexttag is found but has no text
3369 self.assertEqual(e.findtext('section/nexttag'), '')
3370 self.assertEqual(e.findtext('section/nexttag', 'default'), '')
3371
3372 # tog doesn't exist and 'default' kicks in
3373 self.assertIsNone(e.findtext('tog'))
3374 self.assertEqual(e.findtext('tog', 'default'), 'default')
3375
3376 # Issue #16922
3377 self.assertEqual(ET.XML('<tag><empty /></tag>').findtext('empty'), '')
3378
3379 def test_find_xpath(self):
3380 LINEAR_XML = ''&#x27;

Callers

nothing calls this directly

Calls 4

assertIsNoneMethod · 0.80
assertEqualMethod · 0.45
findMethod · 0.45
findtextMethod · 0.45

Tested by

no test coverage detected