diff options
author | Leonard Richardson <leonardr@segfault.org> | 2023-03-24 16:19:29 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2023-03-24 16:19:29 -0400 |
commit | 54b0a2e35c575bcb525c38374e53ea68d53b5e6d (patch) | |
tree | f88af97287d21b4c3c8ba44d16483fec6cdfc924 /bs4/tests | |
parent | 8944fe70574914cabfc9e6fb6eb048d71be39fb1 (diff) |
Implement nonrecursive versions of copy and deepcopy using the new _event_strem generator.
Diffstat (limited to 'bs4/tests')
-rw-r--r-- | bs4/tests/test_pageelement.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/bs4/tests/test_pageelement.py b/bs4/tests/test_pageelement.py index d98c577..4567935 100644 --- a/bs4/tests/test_pageelement.py +++ b/bs4/tests/test_pageelement.py @@ -283,6 +283,21 @@ class TestPersistence(SoupTest): copied = copy.deepcopy(self.tree) assert copied.decode() == self.tree.decode() + def test_copy_deeply_nested_document(self): + # This test verifies that copy and deepcopy don't involve any + # recursive function calls. If they did, this test would + # overflow the Python interpreter stack. + limit = sys.getrecursionlimit() + 1 + markup = "<span>" * limit + + soup = self.soup(markup) + + copied = copy.copy(soup) + assert soup.encode() == copied.encode() + + copied = copy.deepcopy(soup) + assert soup.encode() == copied.encode() + def test_copy_preserves_encoding(self): soup = BeautifulSoup(b'<p> </p>', 'html.parser') encoding = soup.original_encoding |