2012-09-13 15:27:34 +00:00
|
|
|
"""Tests to ensure that the html.parser tree builder generates good
|
|
|
|
trees."""
|
|
|
|
|
2016-08-23 06:01:41 +00:00
|
|
|
from pdb import set_trace
|
|
|
|
import pickle
|
2012-09-13 15:27:34 +00:00
|
|
|
from bs4.testing import SoupTest, HTMLTreeBuilderSmokeTest
|
|
|
|
from bs4.builder import HTMLParserTreeBuilder
|
|
|
|
|
|
|
|
class HTMLParserTreeBuilderSmokeTest(SoupTest, HTMLTreeBuilderSmokeTest):
|
|
|
|
|
|
|
|
@property
|
|
|
|
def default_builder(self):
|
|
|
|
return HTMLParserTreeBuilder()
|
|
|
|
|
|
|
|
def test_namespaced_system_doctype(self):
|
|
|
|
# html.parser can't handle namespaced doctypes, so skip this one.
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_namespaced_public_doctype(self):
|
|
|
|
# html.parser can't handle namespaced doctypes, so skip this one.
|
|
|
|
pass
|
2016-08-23 06:01:41 +00:00
|
|
|
|
|
|
|
def test_builder_is_pickled(self):
|
|
|
|
"""Unlike most tree builders, HTMLParserTreeBuilder and will
|
|
|
|
be restored after pickling.
|
|
|
|
"""
|
|
|
|
tree = self.soup("<a><b>foo</a>")
|
|
|
|
dumped = pickle.dumps(tree, 2)
|
|
|
|
loaded = pickle.loads(dumped)
|
|
|
|
self.assertTrue(isinstance(loaded.builder, type(tree.builder)))
|
|
|
|
|
2018-05-01 14:42:00 +00:00
|
|
|
def test_redundant_empty_element_closing_tags(self):
|
|
|
|
self.assertSoupEquals('<br></br><br></br><br></br>', "<br/><br/><br/>")
|
|
|
|
self.assertSoupEquals('</br></br></br>', "")
|