Beispiel #1
0
 def test_parseOnlyThese_renamed_to_parse_only(self):
     with warnings.catch_warnings(record=True) as w:
         soup = self.soup("<a><b></b></a>", parseOnlyThese=SoupStrainer("b"))
     msg = str(w[0].message)
     self.assertTrue("parseOnlyThese" in msg)
     self.assertTrue("parse_only" in msg)
     self.assertEqual(b"<b></b>", soup.encode())
Beispiel #2
0
    def test_soupstrainer(self):
        # The html5lib tree builder does not support SoupStrainers.
        strainer = SoupStrainer("b")
        markup = "<p>A <b>bold</b> statement.</p>"
        with warnings.catch_warnings(record=True) as w:
            soup = self.soup(markup, parse_only=strainer)
        self.assertEqual(soup.decode(), self.document_for(markup))

        self.assertTrue("the html5lib tree builder doesn't support parse_only"
                        in str(w[0].message))
Beispiel #3
0
 def test_soupstrainer(self):
     """Parsers should be able to work with SoupStrainers."""
     strainer = SoupStrainer("b")
     soup = self.soup("A <b>bold</b> <meta/> <i>statement</i>",
                      parse_only=strainer)
     self.assertEqual(soup.decode(), "<b>bold</b>")
Beispiel #4
0
 def test_parse_with_soupstrainer(self):
     markup = "No<b>Yes</b><a>No<b>Yes <c>Yes</c></b>"
     strainer = SoupStrainer("b")
     soup = self.soup(markup, parse_only=strainer)
     self.assertEqual(soup.encode(), b"<b>Yes</b><b>Yes <c>Yes</c></b>")