From c9aef4f30b233ee3b1b5a6822751cf33b0fb05ed Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Wed, 21 Aug 2019 18:36:32 -0400 Subject: Fixed a crash when pretty-printing tags that were not created during initial parsing. [bug=1838903] --- bs4/tests/test_tree.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'bs4/tests/test_tree.py') diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index e655dcc..c995c46 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -741,6 +741,30 @@ class TestPreviousSibling(SiblingTest): self.assertEqual(start.find_previous_sibling(text="nonesuch"), None) +class TestTag(SoupTest): + + # Test various methods of Tag. + + def test__should_pretty_print(self): + # Test the rules about when a tag should be pretty-printed. + tag = self.soup("").new_tag("a_tag") + + # No list of whitespace-preserving tags -> pretty-print + tag._preserve_whitespace_tags = None + self.assertEquals(True, tag._should_pretty_print(0)) + + # List exists but tag is not on the list -> pretty-print + tag.preserve_whitespace_tags = ["some_other_tag"] + self.assertEquals(True, tag._should_pretty_print(1)) + + # Indent level is None -> don't pretty-print + self.assertEquals(False, tag._should_pretty_print(None)) + + # Tag is on the whitespace-preserving list -> don't pretty-print + tag.preserve_whitespace_tags = ["some_other_tag", "a_tag"] + self.assertEquals(False, tag._should_pretty_print(1)) + + class TestTagCreation(SoupTest): """Test the ability to create new tags.""" def test_new_tag(self): -- cgit v1.2.3