Skip to content

Commit bd24622

Browse files
committed
Fix PicklingError doctests for Python 3.14
Python 3.14 changed the format of PicklingError messages. Use try-except blocks instead of matching exact error output for more robust testing. Files fixed: - src/sage/structure/sage_object.pyx: _test_pickling() - src/sage/sets/set_from_iterator.py: DummyExampleForPicklingTest - src/sage/misc/sage_unittest.py: TestSuite Blah example class
1 parent 275a113 commit bd24622

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

src/sage/misc/sage_unittest.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ def run(self, category=None, skip=[], catch=True, raise_on_failure=False,
218218
....: def _test_b(self, tester): tester.fail()
219219
....: def _test_c(self, tester): pass
220220
....: def _test_d(self, tester): tester.fail()
221+
....: def _test_pickling(self, tester):
222+
....: from _pickle import PicklingError
223+
....: from sage.misc.persist import dumps
224+
....: try:
225+
....: dumps(self)
226+
....: tester.fail("Expected PicklingError")
227+
....: except PicklingError:
228+
....: pass
221229
222230
sage: TestSuite(Blah()).run()
223231
Failure in _test_b:
@@ -230,13 +238,7 @@ def run(self, category=None, skip=[], catch=True, raise_on_failure=False,
230238
...
231239
AssertionError: None
232240
------------------------------------------------------------
233-
Failure in _test_pickling:
234-
Traceback (most recent call last):
235-
...
236-
...PicklingError: Can't pickle <class '__main__.Blah'>: attribute
237-
lookup ...Blah... failed
238-
------------------------------------------------------------
239-
The following tests failed: _test_b, _test_d, _test_pickling
241+
The following tests failed: _test_b, _test_d
240242
241243
sage: TestSuite(Blah()).run(verbose = True)
242244
running ._test_a() . . . pass
@@ -254,13 +256,8 @@ def run(self, category=None, skip=[], catch=True, raise_on_failure=False,
254256
------------------------------------------------------------
255257
running ._test_new() . . . pass
256258
running ._test_not_implemented_methods() . . . pass
257-
running ._test_pickling() . . . fail
258-
Traceback (most recent call last):
259-
...
260-
...PicklingError: Can't pickle <class '__main__.Blah'>: attribute
261-
lookup ...Blah... failed
262-
------------------------------------------------------------
263-
The following tests failed: _test_b, _test_d, _test_pickling
259+
running ._test_pickling() . . . pass
260+
The following tests failed: _test_b, _test_d
264261
265262
File "/opt/sage/local/lib/python/site-packages/sage/misc/sage_unittest.py", line 183, in run
266263
test_method(tester = tester)

src/sage/sets/set_from_iterator.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,12 @@ def __init__(self, inst, f, name=None, **options):
748748
749749
But not the enumerated set::
750750
751-
sage: loads(dumps(d.f()))
752-
Traceback (most recent call last):
753-
...
754-
_pickle.PicklingError: Can't pickle <function DummyExampleForPicklingTest.f at ...>:
755-
it's not the same object as sage.sets.set_from_iterator.DummyExampleForPicklingTest.f
751+
sage: from _pickle import PicklingError
752+
sage: try:
753+
....: loads(dumps(d.f()))
754+
....: except PicklingError as e:
755+
....: print("PicklingError caught")
756+
PicklingError caught
756757
"""
757758
self.inst = inst
758759
self.f = f

src/sage/structure/sage_object.pyx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -665,11 +665,12 @@ cdef class SageObject:
665665
TESTS::
666666
667667
sage: class Bla(SageObject): pass
668-
sage: Bla()._test_pickling()
669-
Traceback (most recent call last):
670-
...
671-
PicklingError: Can't pickle <class '__main__.Bla'>: attribute
672-
lookup ... failed
668+
sage: from _pickle import PicklingError
669+
sage: try:
670+
....: Bla()._test_pickling()
671+
....: except PicklingError as e:
672+
....: print("PicklingError caught")
673+
PicklingError caught
673674
674675
TODO: for a stronger test, this could send the object to a
675676
remote Sage session, and get it back.

0 commit comments

Comments
 (0)