def _test_doctype(self, doctype_fragment):
"""Run a battery of assertions on a given doctype string."""
doctype_str = '<!DOCTYPE %s>' % doctype_fragment
markup = doctype_str + '<p>foo</p>'
soup = self.soup(markup)
doctype = soup.contents[0]
self.assertEqual(doctype.__class__, Doctype)
self.assertEqual(doctype, doctype_fragment)
self.assertEqual(str(soup)[: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')
评论列表
文章目录