Skip to content

Commit 36286c8

Browse files
author
Release Manager
committed
Trac #33837: sage.{numerical,calculus,probability}: Remove use of SAGE_TMP in doctests
(split out from #33213) URL: https://trac.sagemath.org/33837 Reported by: mkoeppe Ticket author(s): Michael Orlitzky Reviewer(s): Matthias Koeppe
2 parents 028e704 + 386562c commit 36286c8

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

src/sage/calculus/calculus.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,9 @@ def laplace(ex, t, s, algorithm='maxima'):
16201620
91/8*e^(4*t) + 629/8*e^(-4*t)
16211621
sage: p1 = plot(xt,0,1/2,rgbcolor=(1,0,0))
16221622
sage: p2 = plot(yt,0,1/2,rgbcolor=(0,1,0))
1623-
sage: (p1+p2).save(os.path.join(SAGE_TMP, "de_plot.png"))
1623+
sage: import tempfile
1624+
sage: with tempfile.NamedTemporaryFile(suffix=".png") as f:
1625+
....: (p1+p2).save(f.name)
16241626
16251627
Another example::
16261628

src/sage/calculus/ode.pyx

+16-12
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ class ode_solver(object):
236236
sage: T.function=f_1
237237
sage: T.jacobian=j_1
238238
sage: T.ode_solve(y_0=[1,0],t_span=[0,100],params=[10.0],num_points=1000)
239-
sage: outfile = os.path.join(SAGE_TMP, 'sage.png')
240-
sage: T.plot_solution(filename=outfile)
239+
sage: import tempfile
240+
sage: with tempfile.NamedTemporaryFile(suffix=".png") as f:
241+
....: T.plot_solution(filename=f.name)
241242
242243
The solver line is equivalent to::
243244
@@ -261,9 +262,10 @@ class ode_solver(object):
261262
262263
By default T.plot_solution() plots the y_0, to plot general y_i use::
263264
264-
sage: T.plot_solution(i=0, filename=outfile)
265-
sage: T.plot_solution(i=1, filename=outfile)
266-
sage: T.plot_solution(i=2, filename=outfile)
265+
sage: with tempfile.NamedTemporaryFile(suffix=".png") as f:
266+
....: T.plot_solution(i=0, filename=f.name)
267+
....: T.plot_solution(i=1, filename=f.name)
268+
....: T.plot_solution(i=2, filename=f.name)
267269
268270
The method interpolate_solution will return a spline interpolation
269271
through the points found by the solver. By default y_0 is
@@ -321,13 +323,15 @@ class ode_solver(object):
321323
following (WARNING: the following is *not* automatically
322324
doctested)::
323325
324-
sage: T = ode_solver() # not tested
325-
sage: T.algorithm = "bsimp" # not tested
326-
sage: vander = van_der_pol() # not tested
327-
sage: T.function=vander # not tested
328-
sage: T.ode_solve(y_0 = [1,0], t_span=[0,2000], num_points=1000) # not tested
329-
sage: T.plot_solution(i=0, filename=os.path.join(SAGE_TMP, 'test.png')) # not tested
330-
326+
sage: T = ode_solver() # not tested
327+
sage: T.algorithm = "bsimp" # not tested
328+
sage: vander = van_der_pol() # not tested
329+
sage: T.function=vander # not tested
330+
sage: T.ode_solve(y_0 = [1,0], t_span=[0,2000], # not tested
331+
....: num_points=1000) # not tested
332+
sage: from tempfile import NamedTemporaryFile # not tested
333+
sage: with NamedTemporaryFile(suffix=".png") as f: # not tested
334+
....: T.plot_solution(i=0, filename=f.name) # not tested
331335
332336
"""
333337
def __init__(self,function=None,jacobian=None,h = 1e-2,error_abs=1e-10,error_rel=1e-10, a=False,a_dydt=False,scale_abs=False,algorithm="rkf45",y_0=None,t_span=None,params = []):

src/sage/numerical/backends/generic_backend.pyx

+7-2
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,9 @@ cdef class GenericBackend:
948948
2
949949
sage: p.add_linear_constraint([(0, 1], (1, 2)], None, 3) # optional - Nonexistent_LP_solver
950950
sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver
951-
sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp")) # optional - Nonexistent_LP_solver
951+
sage: from tempfile import NamedTemporaryFile # optional - Nonexistent_LP_solver
952+
sage: with NamedTemporaryFile(suffix=".lp") as f: # optional - Nonexistent_LP_solver
953+
....: p.write_lp(f.name)
952954
"""
953955
raise NotImplementedError()
954956

@@ -968,7 +970,10 @@ cdef class GenericBackend:
968970
2
969971
sage: p.add_linear_constraint([(0, 1), (1, 2)], None, 3) # optional - Nonexistent_LP_solver
970972
sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver
971-
sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp")) # optional - Nonexistent_LP_solver
973+
sage: from tempfile import NamedTemporaryFile # optional - Nonexistent_LP_solver
974+
sage: with NamedTemporaryFile(suffix=".lp") as f: # optional - Nonexistent_LP_solver
975+
....: p.write_lp(f.name)
976+
972977
"""
973978
raise NotImplementedError()
974979

src/sage/probability/probability_distribution.pyx

+4-6
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,14 @@ cdef class ProbabilityDistribution:
164164
165165
EXAMPLES:
166166
167-
This saves the histogram plot to
168-
``my_general_distribution_plot.png`` in the temporary
169-
directory ``SAGE_TMP``::
167+
This saves the histogram plot to a temporary file::
170168
171169
sage: from sage.probability.probability_distribution import GeneralDiscreteDistribution
172-
sage: import os
170+
sage: import tempfile
173171
sage: P = [0.3, 0.4, 0.3]
174172
sage: X = GeneralDiscreteDistribution(P)
175-
sage: file = os.path.join(SAGE_TMP, "my_general_distribution_plot")
176-
sage: X.generate_histogram_plot(file)
173+
sage: with tempfile.NamedTemporaryFile() as f:
174+
....: X.generate_histogram_plot(f.name)
177175
"""
178176
import pylab
179177
l = [float(self.get_random_element()) for _ in range(num_samples)]

0 commit comments

Comments
 (0)