From db31fa66e82d097c2378734950bd3066acdae397 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Wed, 21 Aug 2019 18:50:43 -0400 Subject: Copying a Tag preserves information that was originally obtained from the TreeBuilder used to build the original Tag. [bug=1838903] --- bs4/tests/test_tree.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'bs4/tests/test_tree.py') diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index c995c46..7d8da01 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -1490,6 +1490,31 @@ class TestPersistence(SoupTest): self.assertEqual(u"

 

", unicode(copy)) self.assertEqual(encoding, copy.original_encoding) + def test_copy_preserves_builder_information(self): + + tag = self.soup('

').p + + # Simulate a tag obtained from a source file. + tag.sourceline = 10 + tag.sourcepos = 33 + + copied = tag.__copy__() + + # The TreeBuilder object is no longer availble, but information + # obtained from it gets copied over to the new Tag object. + self.assertEqual(tag.sourceline, copied.sourceline) + self.assertEqual(tag.sourcepos, copied.sourcepos) + self.assertEqual( + tag.can_be_empty_element, copied.can_be_empty_element + ) + self.assertEqual( + tag.cdata_list_attributes, copied.cdata_list_attributes + ) + self.assertEqual( + tag.preserve_whitespace_tags, copied.preserve_whitespace_tags + ) + + def test_unicode_pickle(self): # A tree containing Unicode characters can be pickled. html = u"\N{SNOWMAN}" -- cgit v1.2.3