summaryrefslogtreecommitdiff
path: root/tests/test_lxml.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonard.richardson@canonical.com>2011-02-20 09:09:59 -0500
committerLeonard Richardson <leonard.richardson@canonical.com>2011-02-20 09:09:59 -0500
commit52ce808c1b43a9efb55e0186647a801b8a7c23a5 (patch)
tree1d5a6252ec26a43cd3754ba905d5fc2c732fb943 /tests/test_lxml.py
parentec444785a35722778ad188a66fef483cc93d7bbb (diff)
Added tests of custom lists of empty-element tags.
Diffstat (limited to 'tests/test_lxml.py')
-rw-r--r--tests/test_lxml.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/test_lxml.py b/tests/test_lxml.py
index 77dd1f1..2f1e98e 100644
--- a/tests/test_lxml.py
+++ b/tests/test_lxml.py
@@ -495,6 +495,12 @@ class TestLXMLBuilderEncodingConversion(SoupTest):
from beautifulsoup.builder.lxml_builder import LXMLTreeBuilderForXML
class TestLXMLXMLBuilder(SoupTest):
+ """Test XML-specific parsing behavior.
+
+ Most of the tests use HTML as an example, since Beautiful Soup is
+ mainly an HTML parser. This test suite is a base for XML-specific
+ tree builders.
+ """
@property
def default_builder(self):
@@ -511,3 +517,22 @@ class TestLXMLXMLBuilder(SoupTest):
def test_self_nonempty_tag_is_not_empty_element(self):
soup = self.soup("<p><ihavecontents>contents</ihavecontents></p>")
self.assertFalse(soup.ihavecontents.is_empty_element)
+
+ def test_designated_empty_element_tags(self):
+ # A constructor argument allows you to say which empty tags
+ # should be presented as empty-element tags.
+ builder = LXMLTreeBuilderForXML(empty_element_tags=['bar'])
+
+ soup = BeautifulSoup(builder=builder, markup="<foo />")
+ self.assertEquals(str(soup), "<foo></foo>")
+
+ soup = BeautifulSoup(builder=builder, markup="<bar></bar>")
+ self.assertEquals(str(soup), "<bar />")
+
+ def test_designated_empty_element_tag_does_not_change_parser_behavior(self):
+ # The designated list of empty-element tags only affects how
+ # empty tags are presented. It does not affect how tags are
+ # parsed--that's the parser's job.
+ builder = LXMLTreeBuilderForXML(empty_element_tags=['bar'])
+ soup = BeautifulSoup(builder=builder, markup="<bar>contents</bar>")
+ self.assertEquals(soup.encode(), "<bar>contents</bar>")