# -*- coding: utf-8 -*- """Unit tests for Beautiful Soup. These tests make sure the Beautiful Soup works as it should. If you find a bug in Beautiful Soup, the best way to express it is as a test case like this that fails.""" import re import unittest from beautifulsoup import * from beautifulsoup.element import CData, Comment, Declaration, SoupStrainer, Tag from beautifulsoup.dammit import UnicodeDammit from beautifulsoup.builder.html5lib_builder import HTML5TreeBuilder def additional_tests(): return unittest.TestLoader().loadTestsFromName(__name__) class SoupTest(unittest.TestCase): default_builder = HTML5TreeBuilder() def assertSoupEquals(self, toParse, rep=None, builder=None, encoding=None): """Parse the given text and make sure its string rep is the other given text.""" if rep == None: rep = toParse obj = BeautifulSoup(toParse, builder=self.default_builder) if encoding is None: rep2 = obj.decode() else: rep2 = obj.encode(encoding) self.assertEqual(rep2, rep) class FollowThatTag(SoupTest): "Tests the various ways of fetching tags from a soup." def setUp(self): ml = """ 1 2 3 4 4""" self.soup = BeautifulStoneSoup(ml) def testParents(self): soup = BeautifulSoup('