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

Commit cf9b1e6

Browse files
committed
trac 33093: fixes for octave interface
- fix failing doctests - do not create file 'octave-workspace' in the current directory
1 parent 08202bc commit cf9b1e6

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/sage/interfaces/octave.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
import pexpect
147147
from sage.misc.verbose import verbose
148148
from sage.misc.instancedoc import instancedoc
149+
from sage.misc.temporary_file import tmp_filename
149150
from sage.cpython.string import bytes_to_str
150151

151152

@@ -156,13 +157,13 @@ class Octave(Expect):
156157
EXAMPLES::
157158
158159
sage: octave.eval("a = [ 1, 1, 2; 3, 5, 8; 13, 21, 33 ]") # optional - octave
159-
'a =\n\n 1 1 2\n 3 5 8\n 13 21 33\n\n'
160+
'a =\n\n 1 1 2\n 3 5 8\n 13 21 33\n'
160161
sage: octave.eval("b = [ 1; 3; 13]") # optional - octave
161-
'b =\n\n 1\n 3\n 13\n\n'
162-
sage: octave.eval("c=a \\ b") # solves linear equation: a*c = b # optional - octave; random output
163-
'c =\n\n 1\n 7.21645e-16\n -7.21645e-16\n\n'
162+
'b =\n\n 1\n 3\n 13\n'
163+
sage: octave.eval(r"c=a \ b") # solves linear equation: a*c = b # optional - octave; random output
164+
'c =\n\n 1\n 7.21645e-16\n -7.21645e-16\n'
164165
sage: octave.eval("c") # optional - octave; random output
165-
'c =\n\n 1\n 7.21645e-16\n -7.21645e-16\n\n'
166+
'c =\n\n 1\n 7.21645e-16\n -7.21645e-16\n'
166167
167168
TESTS:
168169
@@ -186,12 +187,14 @@ def __init__(self, maxread=None, script_subdirectory=None, logfile=None,
186187
command = os.getenv('SAGE_OCTAVE_COMMAND') or 'octave-cli'
187188
if server is None:
188189
server = os.getenv('SAGE_OCTAVE_SERVER') or None
190+
# Use a temporary workspace file.
191+
workspace_file = tmp_filename()
189192
Expect.__init__(self,
190193
name='octave',
191194
# We want the prompt sequence to be unique to avoid confusion with syntax error messages containing >>>
192195
prompt=r'octave\:\d+> ',
193196
# We don't want any pagination of output
194-
command=command + " --no-line-editing --silent --eval 'PS2(PS1());more off' --persist",
197+
command=command + f" --no-line-editing --silent --eval 'PS2(PS1());more off; octave_core_file_name (\"{workspace_file}\")' --persist",
195198
maxread=maxread,
196199
server=server,
197200
server_tmpdir=server_tmpdir,
@@ -510,9 +513,9 @@ def solve_linear_system(self, A, b):
510513
sb = self.sage2octave_matrix_string(b)
511514
self.eval("a = " + sA )
512515
self.eval("b = " + sb )
513-
soln = octave.eval("c = a \\ b")
516+
soln = octave.eval(r"c = a \ b")
514517
soln = soln.replace("\n\n ","[")
515-
soln = soln.replace("\n\n","]")
518+
soln = soln.rstrip() + "]"
516519
soln = soln.replace("\n",",")
517520
sol = soln[3:]
518521
return eval(sol)

0 commit comments

Comments
 (0)