diff options
Diffstat (limited to 'bs4/testing.py')
-rw-r--r-- | bs4/testing.py | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/bs4/testing.py b/bs4/testing.py index 9f12e8d..a162778 100644 --- a/bs4/testing.py +++ b/bs4/testing.py @@ -250,18 +250,21 @@ class HTMLTreeBuilderSmokeTest(object): doctype = soup.contents[0] self.assertEqual(doctype.__class__, Doctype) self.assertEqual(doctype, doctype_fragment) - self.assertEqual(str(soup)[:len(doctype_str)], doctype_str) + self.assertEqual( + soup.encode("utf8")[:len(doctype_str)], + doctype_str + ) # Make sure that the doctype was correctly associated with the # parse tree and that the rest of the document parsed. self.assertEqual(soup.p.contents[0], 'foo') - def _document_with_doctype(self, doctype_fragment): + def _document_with_doctype(self, doctype_fragment, doctype_string="DOCTYPE"): """Generate and parse a document with the given doctype.""" - doctype = '<!DOCTYPE %s>' % doctype_fragment + doctype = '<!%s %s>' % (doctype_string, doctype_fragment) markup = doctype + '\n<p>foo</p>' soup = self.soup(markup) - return doctype, soup + return doctype.encode("utf8"), soup def test_normal_doctypes(self): """Make sure normal, everyday HTML doctypes are handled correctly.""" @@ -274,6 +277,27 @@ class HTMLTreeBuilderSmokeTest(object): doctype = soup.contents[0] self.assertEqual("", doctype.strip()) + def test_mixed_case_doctype(self): + # A lowercase or mixed-case doctype becomes a Doctype. + for doctype_fragment in ("doctype", "DocType"): + doctype_str, soup = self._document_with_doctype( + "html", doctype_fragment + ) + + # Make sure a Doctype object was created and that the DOCTYPE + # is uppercase. + doctype = soup.contents[0] + self.assertEqual(doctype.__class__, Doctype) + self.assertEqual(doctype, "html") + self.assertEqual( + soup.encode("utf8")[:len(doctype_str)], + b"<!DOCTYPE html>" + ) + + # Make sure that the doctype was correctly associated with the + # parse tree and that the rest of the document parsed. + self.assertEqual(soup.p.contents[0], 'foo') + def test_public_doctype_with_url(self): doctype = 'html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"' self.assertDoctypeHandled(doctype) @@ -828,7 +852,7 @@ class XMLTreeBuilderSmokeTest(object): soup = self.soup(markup) self.assertEqual( soup.encode("utf-8"), markup) - + def test_nested_namespaces(self): doc = b"""<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |