"""Tree builder compatibility suite. If you create a tree builder class, also create a test suite that subclasses this one. This test suite will parse various bits of well-formed HTML with your tree builder. Not every tree builder will handle bad HTML in the same way, but every builder should be able to handle _good_ HTML in the same way. """ import unittest from beautifulsoup import BeautifulSoup from beautifulsoup.element import SoupStrainer from test_soup import SoupTest class CompatibilityTest(SoupTest): def __init__(self, builder): self.builder = builder _testMethodName = "test" def test(self): self.test_bare_string() self.test_tag_nesting() self.test_self_closing() self.test_soupstrainer() def test_bare_string(self): self.assertSoupEquals("A bare string") def test_tag_nesting(self): self.assertSoupEquals("Inside a B tag") self.assertSoupEquals("
A nested tag
") def test_self_closing(self): self.assertSoupEquals("A tag", "A tag") def test_soupstrainer(self): strainer = SoupStrainer("b") soup = BeautifulSoup("A bold statement", parseOnlyThese=strainer) self.assertEquals(soup.decode(), "bold") soup = BeautifulSoup("A bold statement", parseOnlyThese=strainer) self.assertEquals(soup.decode(), "bold")