From 7201eecc09b51df5a0fb704670aa66bcc9d8e635 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sun, 14 Feb 2021 15:34:04 -0500 Subject: The 'html5' formatter now treats attributes whose values are the empty string as HTML boolean attributes. Previously (and in other formatters), an attribute value must be set as None to be treated as a boolean attribute. In a future release, I plan to also give this behavior to the 'html' formatter. Patch by Isaac Muse. [bug=1915424] --- bs4/tests/test_tree.py | 39 --------------------------------------- 1 file changed, 39 deletions(-) (limited to 'bs4/tests/test_tree.py') diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index 9267a8f..d1ca5ea 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -1846,45 +1846,6 @@ class TestEncoding(SoupTest): else: self.assertEqual(b'\\u2603', repr(soup)) -class TestFormatter(SoupTest): - - def test_default_attributes(self): - # Test the default behavior of Formatter.attributes(). - formatter = Formatter() - tag = Tag(name="tag") - tag['b'] = 1 - tag['a'] = 2 - - # Attributes come out sorted by name. In Python 3, attributes - # normally come out of a dictionary in the order they were - # added. - self.assertEquals([('a', 2), ('b', 1)], formatter.attributes(tag)) - - # This works even if Tag.attrs is None, though this shouldn't - # normally happen. - tag.attrs = None - self.assertEquals([], formatter.attributes(tag)) - - def test_sort_attributes(self): - # Test the ability to override Formatter.attributes() to, - # e.g., disable the normal sorting of attributes. - class UnsortedFormatter(Formatter): - def attributes(self, tag): - self.called_with = tag - for k, v in sorted(tag.attrs.items()): - if k == 'ignore': - continue - yield k,v - - soup = self.soup('

') - formatter = UnsortedFormatter() - decoded = soup.decode(formatter=formatter) - - # 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) - class TestNavigableStringSubclasses(SoupTest): -- cgit v1.2.3