diff options
author | Leonard Richardson <leonardr@segfault.org> | 2019-08-21 18:50:43 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2019-08-21 18:50:43 -0400 |
commit | db31fa66e82d097c2378734950bd3066acdae397 (patch) | |
tree | 30dea5594b68bcece6a0a80d3d6a634b806e7621 /bs4/tests/test_tree.py | |
parent | b9ed3796e2569fc56fabc114a5bf978558943cb6 (diff) |
Copying a Tag preserves information that was originally obtained from
the TreeBuilder used to build the original Tag. [bug=1838903]
Diffstat (limited to 'bs4/tests/test_tree.py')
-rw-r--r-- | bs4/tests/test_tree.py | 25 |
1 files changed, 25 insertions, 0 deletions
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"<p> </p>", unicode(copy)) self.assertEqual(encoding, copy.original_encoding) + def test_copy_preserves_builder_information(self): + + tag = self.soup('<p></p>').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"<b>\N{SNOWMAN}</b>" |