From ec444785a35722778ad188a66fef483cc93d7bbb Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sun, 20 Feb 2011 08:41:38 -0500 Subject: Added an empty-element tag test. --- beautifulsoup/builder/__init__.py | 2 +- beautifulsoup/builder/lxml_builder.py | 6 +++--- tests/test_html5lib.py | 3 +++ tests/test_lxml.py | 12 ++++++++++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/beautifulsoup/builder/__init__.py b/beautifulsoup/builder/__init__.py index 37e9c8a..deaa613 100644 --- a/beautifulsoup/builder/__init__.py +++ b/beautifulsoup/builder/__init__.py @@ -116,7 +116,7 @@ class SAXTreeBuilder(TreeBuilder): class HTMLTreeBuilder(TreeBuilder): """This TreeBuilder knows facts about HTML. - Such as which tags are self-closing tags. + Such as which tags are empty-element tags. """ assume_html = True diff --git a/beautifulsoup/builder/lxml_builder.py b/beautifulsoup/builder/lxml_builder.py index 0cc9e51..e431a62 100644 --- a/beautifulsoup/builder/lxml_builder.py +++ b/beautifulsoup/builder/lxml_builder.py @@ -13,9 +13,9 @@ class LXMLTreeBuilderForXML(TreeBuilder): # will be instantiated with default arguments. return etree.XMLParser - def __init__(self, parser=None, self_closing_tags=None): - if self_closing_tags is not None: - self.self_closing_tags = set(self_closing_tags) + def __init__(self, parser=None, empty_element_tags=None): + if empty_element_tags is not None: + self.empty_element_tags = set(empty_element_tags) if parser is None: # Use the default parser. parser = self.default_parser diff --git a/tests/test_html5lib.py b/tests/test_html5lib.py index 336f9a5..021c603 100644 --- a/tests/test_html5lib.py +++ b/tests/test_html5lib.py @@ -91,6 +91,9 @@ class TestHTML5BuilderInvalidMarkup(TestLXMLBuilderInvalidMarkup): ('
' '
')) + def test_empty_element_tag_with_contents(self): + self.assertSoupEquals("
foo
", "
foo
") + def test_doctype_in_body(self): markup = "

onetwo

" self.assertSoupEquals(markup, "

onetwo

") diff --git a/tests/test_lxml.py b/tests/test_lxml.py index 602fe05..77dd1f1 100644 --- a/tests/test_lxml.py +++ b/tests/test_lxml.py @@ -33,14 +33,19 @@ class TestLXMLBuilder(SoupTest): "", "") - def test_self_closing(self): - # HTML's self-closing tags are recognized as such. + def test_empty_element(self): + # HTML's empty-element tags are recognized as such. self.assertSoupEquals( "

A tag

", "

A tag

") self.assertSoupEquals( "

Foo
bar

", "

Foo
bar

") + def test_empty_tag_thats_not_an_empty_element_tag(self): + # A tag that is empty but not an HTML empty-element tag + # is not presented as an empty-element tag. + self.assertSoupEquals("

", "

") + def test_comment(self): # Comments are represented as Comment objects. markup = "

foobaz

" @@ -351,6 +356,9 @@ class TestLXMLBuilderInvalidMarkup(SoupTest): '
', '
') + def test_empty_element_tag_with_contents(self): + self.assertSoupEquals("
foo
", "
foo") + def test_doctype_in_body(self): markup = "

onetwo

" self.assertSoupEquals(markup) -- cgit v1.2.3