def test_annotate_node_with_attribute_matching_dash_value(self): # This scenario is taken from the example in the W3C selectors documentation: # https://www.w3.org/TR/css3-selectors/#attribute-representation # Usually, a 'dash match' is used for language subcodes. attribute = parse_selector('[href|="en"]', 'attribute') node = P('<div></div>') node = annotate_attribute(node, attribute) self.assertGreater(len(node.attr('href')), 2) self.assertTrue(node.attr('href').startswith('en'))
def test_annotate_node_with_attribute_with_substring(self): attribute = parse_selector('[href*="url.com"]', 'attribute') node = P('<div></div>') node = annotate_attribute(node, attribute) self.assertGreater(len(node.attr('href')), 7) self.assertTrue("url.com" in node.attr('href')) self.assertFalse( node.attr('href').endswith("url.com") or node.attr('href').startswith("url.com"))
def test_annotate_node_with_attribute_with_substring(self): attribute = parse_selector('[href*="url.com"]', 'attribute') node = P('<div></div>') node = annotate_attribute(node, attribute) self.assertGreater(len(node.attr('href')), 7) self.assertTrue("url.com" in node.attr('href')) self.assertFalse( node.attr('href').endswith("url.com") or node.attr('href').startswith("url.com") )
def test_annotate_node_with_attribute_including_value(self): attribute = parse_selector('[href~="url.com"]', 'attribute') node = P('<div></div>') node = annotate_attribute(node, attribute) self.assertGreater(len(node.attr('href')), 7) self.assertTrue(re.search(r"(^|\b)url\.com(\b|$)", node.attr('href')))
def test_annotate_node_with_attribute_that_ends_with_value(self): attribute = parse_selector('[href$="url.com"]', 'attribute') node = P('<div></div>') node = annotate_attribute(node, attribute) self.assertGreater(len(node.attr('href')), 7) self.assertTrue(node.attr('href').endswith("url.com"))
def test_annotate_node_with_attribute_that_starts_with_value(self): attribute = parse_selector('[href^="http://url.com"]', 'attribute') node = P('<div></div>') node = annotate_attribute(node, attribute) self.assertGreater(len(node.attr('href')), 14) self.assertTrue(node.attr('href').startswith("http://url.com"))
def test_annotate_node_with_attribute(self): attribute = parse_selector('[href="http://url.com"]', 'attribute') node = P('<div></div>') node = annotate_attribute(node, attribute) self.assertEqual(node.attr('href'), "http://url.com")