summaryrefslogtreecommitdiff
path: root/bs4/tests
diff options
context:
space:
mode:
Diffstat (limited to 'bs4/tests')
-rw-r--r--bs4/tests/test_tree.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py
index a14928e..f7c5e2f 100644
--- a/bs4/tests/test_tree.py
+++ b/bs4/tests/test_tree.py
@@ -24,6 +24,7 @@ from bs4.element import (
CData,
Comment,
Declaration,
+ MinimalHTMLFormatter,
Doctype,
NavigableString,
SoupStrainer,
@@ -1683,6 +1684,27 @@ class TestEncoding(SoupTest):
else:
self.assertEqual(b'<b>\\u2603</b>', repr(soup))
+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()):
+ if k == 'ignore':
+ continue
+ yield k,v
+
+ soup = self.soup('<p cval="1" aval="2" ignore="ignored"></p>')
+ 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"))
+ self.assertEquals(u'<p aval="2" cval="1"></p>', decoded)
+
+
class TestNavigableStringSubclasses(SoupTest):
def test_cdata(self):