Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac #33213: replace SAGE_TMP in object persistence doctests.
Browse files Browse the repository at this point in the history
  • Loading branch information
orlitzky authored and mkoeppe committed Feb 19, 2022
1 parent f96b7f9 commit e0b9f1e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/sage/misc/persist.pyx
Expand Up @@ -235,37 +235,43 @@ def save(obj, filename, compress=True, **kwargs):
EXAMPLES::
sage: import tempfile
sage: d = tempfile.TemporaryDirectory()
sage: a = matrix(2, [1,2,3,-5/2])
sage: objfile = os.path.join(SAGE_TMP, 'test.sobj')
sage: objfile_short = os.path.join(SAGE_TMP, 'test')
sage: objfile = os.path.join(d.name, 'test.sobj')
sage: objfile_short = os.path.join(d.name, 'test')
sage: save(a, objfile)
sage: load(objfile_short)
[ 1 2]
[ 3 -5/2]
sage: E = EllipticCurve([-1,0])
sage: P = plot(E)
sage: save(P, objfile_short) # saves the plot to "test.sobj"
sage: save(P, filename=os.path.join(SAGE_TMP, "sage.png"), xmin=-2)
sage: save(P, os.path.join(SAGE_TMP, "filename.with.some.wrong.ext"))
sage: save(P, filename=os.path.join(d.name, "sage.png"), xmin=-2)
sage: save(P, os.path.join(d.name, "filename.with.some.wrong.ext"))
Traceback (most recent call last):
...
ValueError: allowed file extensions for images are '.eps', '.pdf', '.pgf', '.png', '.ps', '.sobj', '.svg'!
sage: print(load(objfile))
Graphics object consisting of 2 graphics primitives
sage: save("A python string", os.path.join(SAGE_TMP, 'test'))
sage: save("A python string", os.path.join(d.name, 'test'))
sage: load(objfile)
'A python string'
sage: load(objfile_short)
'A python string'
sage: d.cleanup()
TESTS:
Check that :trac:`11577` is fixed::
sage: filename = os.path.join(SAGE_TMP, "foo.bar") # filename containing a dot
sage: import tempfile
sage: d = tempfile.TemporaryDirectory()
sage: filename = os.path.join(d.name, "foo.bar") # filename containing a dot
sage: save((1,1),filename) # saves tuple to "foo.bar.sobj"
sage: load(filename)
(1, 1)
sage: d.cleanup()
"""

if not os.path.splitext(filename)[1] or not hasattr(obj, 'save'):
Expand Down

0 comments on commit e0b9f1e

Please sign in to comment.