summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_html5lib.py6
-rw-r--r--tests/test_lxml.py13
-rw-r--r--tests/test_tree.py10
3 files changed, 17 insertions, 12 deletions
diff --git a/tests/test_html5lib.py b/tests/test_html5lib.py
index 3045b02..336f9a5 100644
--- a/tests/test_html5lib.py
+++ b/tests/test_html5lib.py
@@ -40,6 +40,12 @@ class TestHTML5Builder(TestLXMLBuilder):
"<tbody><tr><td>Bar</td></tr></tbody>"
"<tfoot><tr><td>Baz</td></tr></tfoot></table>")
+ def test_literal_in_textarea(self):
+ markup = '<textarea>Junk like <b> tags and <&<&amp;</textarea>'
+ soup = self.soup(markup)
+ self.assertEquals(
+ soup.textarea.contents, ["Junk like <b> tags and <&<&"])
+
def test_collapsed_whitespace(self):
"""Whitespace is preserved even in tags that don't require it."""
self.assertSoupEquals("<p> </p>")
diff --git a/tests/test_lxml.py b/tests/test_lxml.py
index 7e15dcf..8670806 100644
--- a/tests/test_lxml.py
+++ b/tests/test_lxml.py
@@ -126,12 +126,11 @@ class TestLXMLBuilder(SoupTest):
def test_literal_in_textarea(self):
# Anything inside a <textarea> is supposed to be treated as
- # the literal value of the field, (XXX citation needed).
- #
- # But, both lxml and html5lib do their best to parse the
- # contents of a <textarea> as HTML.
+ # the literal value of the field, (XXX citation
+ # needed). html5lib does this correctly. But, lxml does its
+ # best to parse the contents of a <textarea> as HTML.
text = '<textarea>Junk like <b> tags and <&<&amp;</textarea>'
- soup = BeautifulSoup(text)
+ soup = self.soup(text)
self.assertEquals(len(soup.textarea.contents), 2)
self.assertEquals(soup.textarea.contents[0], u"Junk like ")
self.assertEquals(soup.textarea.contents[1].name, 'b')
@@ -141,7 +140,7 @@ class TestLXMLBuilder(SoupTest):
# The contents of a <script> tag are treated as a literal string,
# even if that string contains HTML.
javascript = 'if (i < 2) { alert("<b>foo</b>"); }'
- soup = BeautifulSoup('<script>%s</script>' % javascript)
+ soup = self.soup('<script>%s</script>' % javascript)
self.assertEquals(soup.script.string, javascript)
def test_naked_ampersands(self):
@@ -300,7 +299,7 @@ class TestLXMLBuilder(SoupTest):
def test_entities_converted_on_the_way_out(self):
text = "<p>&lt;&lt;sacr&eacute;&#32;bleu!&gt;&gt;</p>"
expected = u"&lt;&lt;sacr\N{LATIN SMALL LETTER E WITH ACUTE} bleu!&gt;&gt;".encode("utf-8")
- soup = BeautifulSoup(text)
+ soup = self.soup(text)
str = soup.p.string
#self.assertEquals(str.encode("utf-8"), expected)
diff --git a/tests/test_tree.py b/tests/test_tree.py
index 02efead..233cb3c 100644
--- a/tests/test_tree.py
+++ b/tests/test_tree.py
@@ -524,7 +524,7 @@ class TestTreeModification(SoupTest):
def test_new_tag_creation(self):
builder = BeautifulSoup.default_builder()
- soup = BeautifulSoup("", builder=builder)
+ soup = self.soup("", builder=builder)
a = Tag(soup, builder, 'a')
ol = Tag(soup, builder, 'ol')
a['href'] = 'http://foo.com/'
@@ -553,7 +553,7 @@ class TestTreeModification(SoupTest):
def test_replace_tag_with_itself(self):
text = "<a><b></b><c>Foo<d></d></c></a><a><e></e></a>"
- soup = BeautifulSoup(text)
+ soup = self.soup(text)
c = soup.c
soup.c.replaceWith(c)
self.assertEquals(soup.decode(), self.document_for(text))
@@ -592,7 +592,7 @@ class TestTreeModification(SoupTest):
def test_insert_tag(self):
builder = self.default_builder
- soup = BeautifulSoup(
+ soup = self.soup(
"<a><b>Find</b><c>lady!</c><d></d></a>", builder=builder)
magic_tag = Tag(soup, builder, 'magictag')
magic_tag.insert(0, "the")
@@ -636,7 +636,7 @@ class TestTreeModification(SoupTest):
self.assertEquals(no.nextSibling, " business")
def test_nested_tag_replace_with(self):
- soup = BeautifulSoup(
+ soup = self.soup(
"""<a>We<b>reserve<c>the</c><d>right</d></b></a><e>to<f>refuse</f><g>service</g></e>""")
# Replace the entire <b> tag and its contents ("reserve the
@@ -853,7 +853,7 @@ class TestSubstitutions(SoupTest):
# meta tag got filtered out by the strainer. This test makes
# sure that doesn't happen.
strainer = SoupStrainer('pre')
- soup = BeautifulSoup(markup, parseOnlyThese=strainer)
+ soup = self.soup(markup, parseOnlyThese=strainer)
self.assertEquals(soup.contents[0].name, 'pre')