diff --git a/src/sage/calculus/calculus.py b/src/sage/calculus/calculus.py index 686f2a8fb8e..b5da55c9778 100644 --- a/src/sage/calculus/calculus.py +++ b/src/sage/calculus/calculus.py @@ -1620,7 +1620,9 @@ def laplace(ex, t, s, algorithm='maxima'): 91/8*e^(4*t) + 629/8*e^(-4*t) sage: p1 = plot(xt,0,1/2,rgbcolor=(1,0,0)) sage: p2 = plot(yt,0,1/2,rgbcolor=(0,1,0)) - sage: (p1+p2).save(os.path.join(SAGE_TMP, "de_plot.png")) + sage: import tempfile + sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: + ....: (p1+p2).save(f.name) Another example:: diff --git a/src/sage/calculus/ode.pyx b/src/sage/calculus/ode.pyx index cc1b544e1ae..ebcd27141a6 100644 --- a/src/sage/calculus/ode.pyx +++ b/src/sage/calculus/ode.pyx @@ -236,8 +236,9 @@ class ode_solver(object): sage: T.function=f_1 sage: T.jacobian=j_1 sage: T.ode_solve(y_0=[1,0],t_span=[0,100],params=[10.0],num_points=1000) - sage: outfile = os.path.join(SAGE_TMP, 'sage.png') - sage: T.plot_solution(filename=outfile) + sage: import tempfile + sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: + ....: T.plot_solution(filename=f.name) The solver line is equivalent to:: @@ -261,9 +262,10 @@ class ode_solver(object): By default T.plot_solution() plots the y_0, to plot general y_i use:: - sage: T.plot_solution(i=0, filename=outfile) - sage: T.plot_solution(i=1, filename=outfile) - sage: T.plot_solution(i=2, filename=outfile) + sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: + ....: T.plot_solution(i=0, filename=f.name) + ....: T.plot_solution(i=1, filename=f.name) + ....: T.plot_solution(i=2, filename=f.name) The method interpolate_solution will return a spline interpolation through the points found by the solver. By default y_0 is @@ -321,13 +323,15 @@ class ode_solver(object): following (WARNING: the following is *not* automatically doctested):: - sage: T = ode_solver() # not tested - sage: T.algorithm = "bsimp" # not tested - sage: vander = van_der_pol() # not tested - sage: T.function=vander # not tested - sage: T.ode_solve(y_0 = [1,0], t_span=[0,2000], num_points=1000) # not tested - sage: T.plot_solution(i=0, filename=os.path.join(SAGE_TMP, 'test.png')) # not tested - + sage: T = ode_solver() # not tested + sage: T.algorithm = "bsimp" # not tested + sage: vander = van_der_pol() # not tested + sage: T.function=vander # not tested + sage: T.ode_solve(y_0 = [1,0], t_span=[0,2000], # not tested + ....: num_points=1000) # not tested + sage: from tempfile import NamedTemporaryFile # not tested + sage: with NamedTemporaryFile(suffix=".png") as f: # not tested + ....: T.plot_solution(i=0, filename=f.name) # not tested """ 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 = []): diff --git a/src/sage/numerical/backends/generic_backend.pyx b/src/sage/numerical/backends/generic_backend.pyx index 5e0adb0a915..94d0e0e9d9d 100644 --- a/src/sage/numerical/backends/generic_backend.pyx +++ b/src/sage/numerical/backends/generic_backend.pyx @@ -948,7 +948,9 @@ cdef class GenericBackend: 2 sage: p.add_linear_constraint([(0, 1], (1, 2)], None, 3) # optional - Nonexistent_LP_solver sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver - sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp")) # optional - Nonexistent_LP_solver + sage: from tempfile import NamedTemporaryFile # optional - Nonexistent_LP_solver + sage: with NamedTemporaryFile(suffix=".lp") as f: # optional - Nonexistent_LP_solver + ....: p.write_lp(f.name) """ raise NotImplementedError() @@ -968,7 +970,10 @@ cdef class GenericBackend: 2 sage: p.add_linear_constraint([(0, 1), (1, 2)], None, 3) # optional - Nonexistent_LP_solver sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver - sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp")) # optional - Nonexistent_LP_solver + sage: from tempfile import NamedTemporaryFile # optional - Nonexistent_LP_solver + sage: with NamedTemporaryFile(suffix=".lp") as f: # optional - Nonexistent_LP_solver + ....: p.write_lp(f.name) + """ raise NotImplementedError() diff --git a/src/sage/probability/probability_distribution.pyx b/src/sage/probability/probability_distribution.pyx index 84e684f8de6..22fcc0c0090 100644 --- a/src/sage/probability/probability_distribution.pyx +++ b/src/sage/probability/probability_distribution.pyx @@ -164,16 +164,14 @@ cdef class ProbabilityDistribution: EXAMPLES: - This saves the histogram plot to - ``my_general_distribution_plot.png`` in the temporary - directory ``SAGE_TMP``:: + This saves the histogram plot to a temporary file:: sage: from sage.probability.probability_distribution import GeneralDiscreteDistribution - sage: import os + sage: import tempfile sage: P = [0.3, 0.4, 0.3] sage: X = GeneralDiscreteDistribution(P) - sage: file = os.path.join(SAGE_TMP, "my_general_distribution_plot") - sage: X.generate_histogram_plot(file) + sage: with tempfile.NamedTemporaryFile() as f: + ....: X.generate_histogram_plot(f.name) """ import pylab l = [float(self.get_random_element()) for _ in range(num_samples)]