mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	Add some tests for XPath numeric indexing
This commit is contained in:
		
						commit
						791c97a6a8
					
				
					 1 changed files with 17 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -1776,6 +1776,23 @@ class ElementFindTest(unittest.TestCase):
 | 
			
		|||
        # Issue #16922
 | 
			
		||||
        self.assertEqual(ET.XML('<tag><empty /></tag>').findtext('empty'), '')
 | 
			
		||||
 | 
			
		||||
    def test_find_xpath(self):
 | 
			
		||||
        LINEAR_XML = '''
 | 
			
		||||
        <body>
 | 
			
		||||
            <tag class='a'/>
 | 
			
		||||
            <tag class='b'/>
 | 
			
		||||
            <tag class='c'/>
 | 
			
		||||
            <tag class='d'/>
 | 
			
		||||
        </body>'''
 | 
			
		||||
        e = ET.XML(LINEAR_XML)
 | 
			
		||||
 | 
			
		||||
        # Test for numeric indexing and last()
 | 
			
		||||
        self.assertEqual(e.find('./tag[1]').attrib['class'], 'a')
 | 
			
		||||
        self.assertEqual(e.find('./tag[2]').attrib['class'], 'b')
 | 
			
		||||
        self.assertEqual(e.find('./tag[last()]').attrib['class'], 'd')
 | 
			
		||||
        self.assertEqual(e.find('./tag[last()-1]').attrib['class'], 'c')
 | 
			
		||||
        self.assertEqual(e.find('./tag[last()-2]').attrib['class'], 'b')
 | 
			
		||||
 | 
			
		||||
    def test_findall(self):
 | 
			
		||||
        e = ET.XML(SAMPLE_XML)
 | 
			
		||||
        e[2] = ET.XML(SAMPLE_SECTION)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue