Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
self.assert_selector(
markup,
"html:dir(ltr)",
['0'],
flags=util.HTML
)
# Input is root
for parser in ('html.parser', 'lxml', 'html5lib'):
markup = """<input dir="auto" type="text" id="1">"""
soup = bs4.BeautifulSoup(markup, parser)
fragment = soup.input.extract()
self.assertTrue(sv.match(":root:dir(ltr)", fragment, flags=sv.DEBUG))
<p id="1"><code id="2"></code><img src="./image.png" id="3"></p>
<pre id="4"></pre>
<p><span class="some-class" id="5"></span><span id="some-id"></span></p>
<pre class="ignore" id="6">
</pre>
"""
soup = self.soup(markup, 'html.parser')
nodes = sv.select('span[id]', soup)
self.assertTrue(sv.match('span#\\35', nodes[0]))
self.assertFalse(sv.match('span#\\35', nodes[1]))
<p id="1"><code id="2"></code><img src="./image.png" id="3"></p>
<pre id="4"></pre>
<p><span class="some-class" id="5"></span><span id="some-id"></span></p>
<pre class="ignore" id="6">
</pre>
"""
soup = bs4.BeautifulSoup(markup, 'html5lib')
nodes = sv.select('span[id]', soup)
self.assertTrue(sv.match('span#\\35', nodes[0]))
self.assertFalse(sv.match('span#\\35', nodes[1]))
def test_invalid_type_input_match(self):
"""Test bad input into the match API."""
flags = sv.DEBUG
with self.assertRaises(TypeError):
sv.match('div', "not a tag", flags=flags)
<p id="1"><code id="2"></code><img src="./image.png" id="3"></p>
<pre id="4"></pre>
<p><span class="some-class" id="5"></span><span id="some-id"></span></p>
<pre class="ignore" id="6">
</pre>
"""
soup = bs4.BeautifulSoup(markup, 'html5lib')
nodes = sv.select('span[id]', soup)
self.assertTrue(sv.match('span#\\35', nodes[0]))
self.assertFalse(sv.match('span#\\35', nodes[1]))