Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | """Tests to ensure that the html.parser tree builder generates good |
| 2 | trees.""" |
| 3 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 4 | import pickle |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5 | from bs4.testing import SoupTest, HTMLTreeBuilderSmokeTest |
| 6 | from bs4.builder import HTMLParserTreeBuilder |
| 7 | |
| 8 | class HTMLParserTreeBuilderSmokeTest(SoupTest, HTMLTreeBuilderSmokeTest): |
| 9 | |
| 10 | @property |
| 11 | def default_builder(self): |
| 12 | return HTMLParserTreeBuilder() |
| 13 | |
| 14 | def test_namespaced_system_doctype(self): |
| 15 | # html.parser can't handle namespaced doctypes, so skip this one. |
| 16 | pass |
| 17 | |
| 18 | def test_namespaced_public_doctype(self): |
| 19 | # html.parser can't handle namespaced doctypes, so skip this one. |
| 20 | pass |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 21 | |
| 22 | def test_builder_is_pickled(self): |
| 23 | """Unlike most tree builders, HTMLParserTreeBuilder and will |
| 24 | be restored after pickling. |
| 25 | """ |
| 26 | tree = self.soup("<a><b>foo</a>") |
| 27 | dumped = pickle.dumps(tree, 2) |
| 28 | loaded = pickle.loads(dumped) |
| 29 | self.assertTrue(isinstance(loaded.builder, type(tree.builder))) |
| 30 | |
| 31 | |