def test_skip_tags_matched_by_ignore_matcher(self): tree = ElementTree.fromstring('''\ <html> <body> <div> <h1>str1</h1> </div> </body> </html> ''') finder = ElementFinder() tag_matcher = TagElementMatcher(tags=['h1']) finder.add_element_matcher(tag_matcher) finder.add_ignore_element_matcher(TagElementMatcher(tags=['div'])) results = finder.findElements(tree) # check that no tags were matched by the tag_matcher self.assertEquals(0, len(results[tag_matcher]))
def test_skip_tags_matched_by_non_tag_ignore_matcher(self): tree = ElementTree.fromstring('''\ <html> <body> <h1 skip="yes">str1</h1> </body> </html> ''') class Matcher(ElementMatcher): def doesMatch(self, element): return element.get('skip') == 'yes' finder = ElementFinder() matcher = TagElementMatcher(tags=['h1']) finder.add_element_matcher(matcher) ignore_matcher = Matcher() finder.add_ignore_element_matcher(ignore_matcher) results = finder.findElements(tree) # check that no tags were matched by the tag_matcher self.assertEquals(0, len(results[matcher]))