MCPcopy Create free account
hub / github.com/clips/pattern / testFindByIndex

Method testFindByIndex

pattern/web/soup/BeautifulSoupTests.py:100–112  ·  view source on GitHub ↗

For when you have the tag and you want to know where it is.

(self)

Source from the content-addressed store, hash-verified

98 self.assertEqual(matching[0].name, 'a')
99
100 def testFindByIndex(self):
101 """For when you have the tag and you want to know where it is."""
102 tag = self.soup.find('a', id="a")
103 self.assertEqual(self.soup.index(tag), 3)
104
105 # It works for NavigableStrings as well.
106 s = tag.string
107 self.assertEqual(tag.index(s), 0)
108
109 # If the tag isn't present, a ValueError is raised.
110 soup2 = BeautifulSoup("<b></b>")
111 tag2 = soup2.find('b')
112 self.assertRaises(ValueError, self.soup.index, tag2)
113
114 def testConflictingFindArguments(self):
115 """The 'text' argument takes precedence."""

Callers

nothing calls this directly

Calls 3

BeautifulSoupClass · 0.90
findMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected