summaryrefslogtreecommitdiff
path: root/bs4/tests/test_tree.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2019-07-14 17:09:58 -0400
committerLeonard Richardson <leonardr@segfault.org>2019-07-14 17:09:58 -0400
commit0df054db08ef3286482694ee0c9aa85b5313dfd2 (patch)
treed1b38991f1148abccb0862484d87d760654cd18f /bs4/tests/test_tree.py
parent519afbe269b671e15a1f1d2aecfe4fc579b61efc (diff)
Give the Formatter class more control over formatting decisions.
Diffstat (limited to 'bs4/tests/test_tree.py')
-rw-r--r--bs4/tests/test_tree.py18
1 files changed, 9 insertions, 9 deletions
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"<b><FOO></b><b>BAR</b><br>"))
+ self.document_for(u"<b><FOO></b><b>BAR</b><br/>"))
def test_formatter_is_run_on_attribute_values(self):
markup = u'<a href="http://a.com?a=b&c=é">e</a>'
@@ -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 <p> tag. It filtered out one
+ # attribute and sorted the other two.
+ self.assertEquals(formatter.called_with, soup.p)
self.assertEquals(u'<p aval="2" cval="1"></p>', decoded)