You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.6 KiB
48 lines
1.6 KiB
6 years ago
|
"""Tests to ensure that the html.parser tree builder generates good
|
||
|
trees."""
|
||
|
|
||
|
from pdb import set_trace
|
||
|
import pickle
|
||
|
from bs4.testing import SoupTest, HTMLTreeBuilderSmokeTest
|
||
|
from bs4.builder import HTMLParserTreeBuilder
|
||
5 years ago
|
from bs4.builder._htmlparser import BeautifulSoupHTMLParser
|
||
6 years ago
|
|
||
|
class HTMLParserTreeBuilderSmokeTest(SoupTest, HTMLTreeBuilderSmokeTest):
|
||
|
|
||
5 years ago
|
default_builder = HTMLParserTreeBuilder
|
||
6 years ago
|
|
||
|
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
|
||
|
|
||
|
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)))
|
||
|
|
||
|
def test_redundant_empty_element_closing_tags(self):
|
||
|
self.assertSoupEquals('<br></br><br></br><br></br>', "<br/><br/><br/>")
|
||
|
self.assertSoupEquals('</br></br></br>', "")
|
||
5 years ago
|
|
||
|
def test_empty_element(self):
|
||
|
# This verifies that any buffered data present when the parser
|
||
|
# finishes working is handled.
|
||
|
self.assertSoupEquals("foo &# bar", "foo &# bar")
|
||
|
|
||
|
|
||
|
class TestHTMLParserSubclass(SoupTest):
|
||
|
def test_error(self):
|
||
|
"""Verify that our HTMLParser subclass implements error() in a way
|
||
|
that doesn't cause a crash.
|
||
|
"""
|
||
|
parser = BeautifulSoupHTMLParser()
|
||
|
parser.error("don't crash")
|