summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2013-05-20 09:19:16 -0400
committerLeonard Richardson <leonardr@segfault.org>2013-05-20 09:19:16 -0400
commitdae9722244850754533647c77f418f626ba05124 (patch)
tree4b0c5b4f5a508e433911bd3c7cb628417ba32b31
parent202d6407adc5ce81e461b9a85e5930b53f717901 (diff)
Fixed test failures when lxml is not installed.
-rw-r--r--bs4/testing.py12
-rw-r--r--bs4/tests/test_lxml.py3
-rw-r--r--bs4/tests/test_tree.py12
3 files changed, 14 insertions, 13 deletions
diff --git a/bs4/testing.py b/bs4/testing.py
index ed71d3b..383f36a 100644
--- a/bs4/testing.py
+++ b/bs4/testing.py
@@ -464,6 +464,18 @@ class XMLTreeBuilderSmokeTest(object):
self.assertEqual(
soup.encode("utf-8"), markup)
+ def test_formatter_processes_script_tag_for_xml_documents(self):
+ doc = """
+ <script type="text/javascript">
+ </script>
+"""
+ soup = BeautifulSoup(doc, "xml")
+ # lxml would have stripped this while parsing, but we can add
+ # it later.
+ soup.script.string = 'console.log("< < hey > > ");'
+ encoded = soup.encode()
+ self.assertTrue(b"&lt; &lt; hey &gt; &gt;" in encoded)
+
def test_popping_namespaced_tag(self):
markup = '<rss xmlns:dc="foo"><dc:creator>b</dc:creator><dc:date>2012-07-02T20:33:42Z</dc:date><dc:rights>c</dc:rights><image>d</image></rss>'
soup = self.soup(markup)
diff --git a/bs4/tests/test_lxml.py b/bs4/tests/test_lxml.py
index 39e4bd4..80458de 100644
--- a/bs4/tests/test_lxml.py
+++ b/bs4/tests/test_lxml.py
@@ -10,6 +10,7 @@ try:
LXML_VERSION = lxml.etree.LXML_VERSION
except ImportError, e:
LXML_PRESENT = False
+ LXML_VERSION = (0,)
from bs4 import (
BeautifulSoup,
@@ -47,7 +48,7 @@ class LXMLTreeBuilderSmokeTest(SoupTest, HTMLTreeBuilderSmokeTest):
# test if an old version of lxml is installed.
@skipIf(
- LXML_VERSION < (2,3,5,0),
+ not LXML_PRESENT or 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("<!DOCTYPE>")
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py
index f60485b..4f12d20 100644
--- a/bs4/tests/test_tree.py
+++ b/bs4/tests/test_tree.py
@@ -1344,18 +1344,6 @@ class TestSubstitutions(SoupTest):
encoded = BeautifulSoup(doc).encode()
self.assertTrue(b"< < hey > >" in encoded)
- def test_formatter_processes_script_tag_for_xml_documents(self):
- doc = """
- <script type="text/javascript">
- </script>
-"""
- soup = BeautifulSoup(doc, "xml")
- # lxml would have stripped this while parsing, but we can add
- # it later.
- soup.script.string = 'console.log("< < hey > > ");'
- encoded = soup.encode()
- self.assertTrue(b"&lt; &lt; hey &gt; &gt;" in encoded)
-
def test_prettify_leaves_preformatted_text_alone(self):
soup = self.soup("<div> foo <pre> \tbar\n \n </pre> baz ")
# Everything outside the <pre> tag is reformatted, but everything