diff options
author | Leonard Richardson <leonardr@segfault.org> | 2023-03-27 16:01:43 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2023-03-27 16:01:43 -0400 |
commit | c63a26a693c14234592b0f92da184a40aa9a2c6b (patch) | |
tree | 18ac38b27c480a6ff40b0cff95025ada913efe1e /bs4/tests/test_lxml.py | |
parent | 469bd30fd1d981ea3e2af0d0827956532b41b277 (diff) |
Make it possible to pickle a deeply nested BeautifulSoup object.
Diffstat (limited to 'bs4/tests/test_lxml.py')
-rw-r--r-- | bs4/tests/test_lxml.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/bs4/tests/test_lxml.py b/bs4/tests/test_lxml.py index c7bf45d..5065b6f 100644 --- a/bs4/tests/test_lxml.py +++ b/bs4/tests/test_lxml.py @@ -189,13 +189,15 @@ class TestLXMLXMLTreeBuilder(SoupTest, XMLTreeBuilderSmokeTest): assert soup.find('prefix:tag3').name == 'tag3' assert soup.subtag.find('prefix:tag3').name == 'tag3' - def test_pickle_removes_builder(self): - # The lxml TreeBuilder is not picklable, so it won't be - # preserved in a pickle/unpickle operation. - + def test_pickle_restores_builder(self): + # The lxml TreeBuilder is not picklable, so when unpickling + # a document created with it, a new TreeBuilder of the + # appropriate class is created. soup = self.soup("<a>some markup</a>") assert isinstance(soup.builder, self.default_builder) pickled = pickle.dumps(soup) unpickled = pickle.loads(pickled) + assert "some markup" == unpickled.a.string - assert unpickled.builder is None + assert unpickled.builder != soup.builder + assert isinstance(unpickled.builder, self.default_builder) |