def test_invalid_type_input_comments(self): """Test bad input into the comments API.""" flags = sv.DEBUG with self.assertRaises(TypeError): sv.comments('div', "not a tag", flags=flags)
def test_comment(self): """Test comment.""" html = '<div><!-- comments -->text</div>' soup = self.soup(html, 'html.parser') with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. warnings.simplefilter("always") sv.comments(soup) self.assertTrue(len(w) == 1) self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
def test_invalid_type_input(self): """Test bad input into the API.""" with self.assertRaises(TypeError): sv.match('div', "not a tag") with self.assertRaises(TypeError): sv.select('div', "not a tag") with self.assertRaises(TypeError): sv.filter('div', "not a tag") with self.assertRaises(TypeError): sv.comments('div', "not a tag")
def test_comments(self): """Test comments.""" markup = """ <!-- before header --> <html> <head> </head> <body> <!-- comment --> <p id="1"><code id="2"></code><img id="3" src="./image.png"/></p> <pre id="4"></pre> <p><span id="5" class="some-class"></span><span id="some-id"></span></p> <pre id="6" class='ignore'> <!-- don't ignore --> </pre> </body> </html> """ soup = bs4.BeautifulSoup(markup, 'html5lib') comments = [util.ustr(c).strip() for c in sv.comments(soup)] self.assertEqual(sorted(comments), sorted(['before header', 'comment', "don't ignore"])) comments = [util.ustr(c).strip() for c in sv.icomments(soup, limit=2)] self.assertEqual(sorted(comments), sorted(['before header', 'comment'])) # Check that comments on compiled object work just like `sv.comments` pattern = sv.compile('', None, 0) comments = [util.ustr(c).strip() for c in pattern.comments(soup)] self.assertEqual(sorted(comments), sorted(['before header', 'comment', "don't ignore"])) comments = [ util.ustr(c).strip() for c in pattern.icomments(soup, limit=2) ] self.assertEqual(sorted(comments), sorted(['before header', 'comment']))
def test_comments(self): """Test comments.""" markup = """ <!-- before header --> <html> <head> </head> <body> <!-- comment --> <p id="1"><code id="2"></code><img id="3" src="./image.png"/></p> <pre id="4"></pre> <p><span id="5" class="some-class"></span><span id="some-id"></span></p> <pre id="6" class='ignore'> <!-- don't ignore --> </pre> </body> </html> """ soup = self.soup(markup, 'html5lib') comments = [sv_util.ustr(c).strip() for c in sv.comments(soup)] self.assertEqual(sorted(comments), sorted(['before header', 'comment', "don't ignore"]))