From f5a7641d58754df92d0567291c79c7ebd29c2005 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sun, 13 Feb 2011 19:48:00 -0500 Subject: Got a variety of doctype tests working. --- tests/test_lxml.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/tests/test_lxml.py b/tests/test_lxml.py index 9f002cb..d3dbe49 100644 --- a/tests/test_lxml.py +++ b/tests/test_lxml.py @@ -201,33 +201,35 @@ class TestLXMLBuilder(SoupTest): markup = "foobar" self.assertSoupEquals(markup, "") - def test_namespaced_system_doctype(self): - doctype_str = '' + def _test_doctype(self, doctype_fragment): + """Run a battery of assertions on a given doctype string.""" + doctype_str = '' % doctype_fragment markup = doctype_str + '

foo

' soup = BeautifulSoup(markup) doctype = soup.contents[0] self.assertEquals(doctype.__class__, Doctype) - self.assertEquals(doctype, 'xsl:stylesheet SYSTEM "htmlent.dtd"') + self.assertEquals(doctype, doctype_fragment) self.assertEquals(str(soup)[:len(doctype_str)], doctype_str) - self.assertEquals(soup.p.contents[0], 'foo') - def test_namespaced_public_doctype(self): - doctype_str = '' - markup = doctype_str + '

foo

' - soup = BeautifulSoup(markup) - doctype = soup.contents[0] - self.assertEquals(doctype.__class__, Doctype) - self.assertEquals(doctype, 'xsl:stylesheet PUBLIC "htmlent.dtd"') - self.assertEquals(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.assertEquals(soup.p.contents[0], 'foo') - # Tests below this line need work. + def test_doctype(self): + # Test a normal HTML doctype you'll commonly see in a real document. + self._test_doctype( + 'html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"') + def test_namespaced_system_doctype(self): + # Test a namespaced doctype with a system id. + self._test_doctype('xsl:stylesheet SYSTEM "htmlent.dtd"') + + def test_namespaced_system_doctype(self): + # Test a namespaced doctype with a public id. + self._test_doctype('xsl:stylesheet PUBLIC "htmlent.dtd"') + + # Tests below this line need work. - def test_doctype(self): - doctype_str = ' - markup = doctype_str + '

foo

' - self.assertSoupEquals(xml) def test_entities_converted_on_the_way_out(self): text = "

<<sacré bleu!>>

" -- cgit v1.2.3