From 0df054db08ef3286482694ee0c9aa85b5313dfd2 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sun, 14 Jul 2019 17:09:58 -0400 Subject: Give the Formatter class more control over formatting decisions. --- bs4/tests/test_tree.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'bs4/tests/test_tree.py') diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index f7c5e2f..ffbc29e 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -24,8 +24,8 @@ from bs4.element import ( CData, Comment, Declaration, - MinimalHTMLFormatter, Doctype, + HTMLFormatter, NavigableString, SoupStrainer, Tag, @@ -1533,7 +1533,7 @@ class TestSubstitutions(SoupTest): # callable is called on every string. self.assertEqual( decoded, - self.document_for(u"BAR
")) + self.document_for(u"BAR
")) def test_formatter_is_run_on_attribute_values(self): markup = u'e' @@ -1687,10 +1687,10 @@ class TestEncoding(SoupTest): class TestFormatter(SoupTest): def test_sort_attributes(self): - class UnsortedFormatter(MinimalHTMLFormatter): - def sort_attributes(self, attributes): - self.called_with = attributes - for k, v in sorted(attributes.items()): + class UnsortedFormatter(HTMLFormatter): + def attributes(self, tag): + self.called_with = tag + for k, v in sorted(tag.attrs.items()): if k == 'ignore': continue yield k,v @@ -1699,9 +1699,9 @@ class TestFormatter(SoupTest): formatter = UnsortedFormatter() decoded = soup.decode(formatter=formatter) - # sort_attributes() was called with all three attributes. It removed one and - # sorted the other two. - self.assertEquals(formatter.called_with, dict(cval="1", aval="2", ignore="ignored")) + # sort_attributes() was called on the

tag. It filtered out one + # attribute and sorted the other two. + self.assertEquals(formatter.called_with, soup.p) self.assertEquals(u'

', decoded) -- cgit v1.2.3