From 269157a8f40dfdac082f39befd69f170263d2ce1 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Tue, 7 May 2013 08:19:02 -0400 Subject: Now that lxml's segfault on invalid doctype has been fixed, fix a corresponding problem on the Beautiful Soup end that was previously invisible. [bug=984936] --- bs4/tests/test_lxml.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'bs4/tests/test_lxml.py') diff --git a/bs4/tests/test_lxml.py b/bs4/tests/test_lxml.py index 39e26bf..693ec25 100644 --- a/bs4/tests/test_lxml.py +++ b/bs4/tests/test_lxml.py @@ -6,6 +6,14 @@ import warnings try: from bs4.builder import LXMLTreeBuilder, LXMLTreeBuilderForXML LXML_PRESENT = True + import lxml.etree + LXML_VERSION = [] + for i in lxml.etree.__version__.split('.'): + try: + part = int(i) + except TypeError: + part = 0 + LXML_VERSION.append(part) except ImportError, e: LXML_PRESENT = False @@ -41,6 +49,17 @@ class LXMLTreeBuilderSmokeTest(SoupTest, HTMLTreeBuilderSmokeTest): self.assertSoupEquals( "

foo�bar

", "

foobar

") + # In lxml < 2.3.5, an empty doctype causes a segfault. Skip this + # test if an old version of lxml is installed. + + @skipIf( + LXML_VERSION < [2,3,5], + "Skipping doctype test for old version of lxml to avoid segfault.") + def test_empty_doctype(self): + soup = self.soup("") + doctype = soup.contents[0] + self.assertEqual("", doctype.strip()) + def test_beautifulstonesoup_is_xml_parser(self): # Make sure that the deprecated BSS class uses an xml builder # if one is installed. -- cgit v1.2.3 From e31151091c3dd44d0f39ba234df261f362199ae5 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Tue, 7 May 2013 08:36:07 -0400 Subject: Improved detection of lxml version number. --- bs4/tests/test_lxml.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'bs4/tests/test_lxml.py') diff --git a/bs4/tests/test_lxml.py b/bs4/tests/test_lxml.py index 693ec25..f32fc2b 100644 --- a/bs4/tests/test_lxml.py +++ b/bs4/tests/test_lxml.py @@ -7,13 +7,7 @@ try: from bs4.builder import LXMLTreeBuilder, LXMLTreeBuilderForXML LXML_PRESENT = True import lxml.etree - LXML_VERSION = [] - for i in lxml.etree.__version__.split('.'): - try: - part = int(i) - except TypeError: - part = 0 - LXML_VERSION.append(part) + LXML_VERSION = lxml.etree.LXML_VERSION except ImportError, e: LXML_PRESENT = False @@ -53,7 +47,7 @@ class LXMLTreeBuilderSmokeTest(SoupTest, HTMLTreeBuilderSmokeTest): # test if an old version of lxml is installed. @skipIf( - LXML_VERSION < [2,3,5], + LXML_VERSION < (2,3,5,0), "Skipping doctype test for old version of lxml to avoid segfault.") def test_empty_doctype(self): soup = self.soup("") -- cgit v1.2.3