You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tests/AdvancedHTMLParserTests/test_XPath.py
+39-2Lines changed: 39 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -393,9 +393,9 @@ def test_xpathLast(self):
393
393
assertlastSpaninresults , 'Got a mismatch of results from xpath vs non-xpath. Node ( %s ) was found via non-xpath, but not in the xpath set!'%(repr(lastSpan), )
394
394
395
395
396
-
deftest_parseOptimizations1(self):
396
+
deftest_xpathParseOptimizations1(self):
397
397
'''
398
-
test_parseOptimizations1 - Test that we properly optimize xpath strings with values that can be calculated at parse time
398
+
test_xpathParseOptimizations1 - Test that we properly optimize xpath strings with values that can be calculated at parse time
assertvalueisTrue , 'Expected the calculated BodyElementValue to be <bool> True. Got: <%s> %s'%( type(value).__name__, repr(value))
411
411
412
412
413
+
414
+
deftest_xpathContains(self):
415
+
'''
416
+
test_xpathContains - Test the "contains" function
417
+
'''
418
+
419
+
puddingNameSpans=self.parser.getElementsByXPathExpression('//span[ @name = "itemName" and contains( text(), "Pudding" ) ]')
420
+
421
+
assertlen(puddingNameSpans) ==1 , 'Expected to get one span[name="itemName"] where inner text contains "Pudding", but got %d. %s'%( len(puddingNameSpans), repr(puddingNameSpans) )
422
+
423
+
puddingSpan=puddingNameSpans[0]
424
+
assert'Pudding Cups'inpuddingSpan.innerText , 'Expected "Pudding Cups" to be in the inner text of the matched pudding item, but it was not. Inner text was: %s'%( repr(puddingSpan.innerText), )
425
+
426
+
427
+
itemsContainingLetterE=self.parser.getElementsByXPathExpression('''//span[(@name = "itemName") and contains( normalize-space(), "e" )]/ancestor::div[@name="items"]''')
428
+
assertlen(itemsContainingLetterE) ==3 , 'Expected to find 3 items which contained lower case "e" , but found %d ! %s'%( len(itemsContainingLetterE), repr(itemsContainingLetterE) )
429
+
430
+
431
+
item1Found=False
432
+
item2Found=False
433
+
item3Found=False
434
+
435
+
foritemEminitemsContainingLetterE:
436
+
437
+
ifitemEm.id=='item1':
438
+
item1Found=True
439
+
elifitemEm.id=='item2':
440
+
item2Found=True
441
+
elifitemEm.id=='item3':
442
+
item3Found=True
443
+
444
+
assertitem1FoundisTrue , 'Expected to find div id="item1" but did not!'
445
+
assertitem2FoundisTrue , 'Expected to find div id="item2" but did not!'
446
+
assertitem3FoundisTrue , 'Expected to find div id="item3" but did not!'
0 commit comments