From c63a26a693c14234592b0f92da184a40aa9a2c6b Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Mon, 27 Mar 2023 16:01:43 -0400 Subject: Make it possible to pickle a deeply nested BeautifulSoup object. --- bs4/tests/test_lxml.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'bs4/tests/test_lxml.py') 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("some markup") 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) -- cgit v1.2.3