Skip to content

Commit

Permalink
Trac #33093: 5 doctests failing related to external program octave
Browse files Browse the repository at this point in the history
On Ubuntu 20.04 with 9.5.beta9 and `GNU Octave, version 5.2.0`, the
command
{{{
sage -t --optional=sage,octave
src/doc/en/constructions/linear_algebra.rst
src/doc/en/developer/coding_in_other.rst src/sage/interfaces/octave.py
}}}

gives

{{{
Doctesting 3 files.
sage -t --random-seed=53840594329377719172370096027971271567
src/doc/en/constructions/linear_algebra.rst
**********************************************************************
File "src/doc/en/constructions/linear_algebra.rst", line 454, in
doc.en.constructions.linear_algebra
Failed example:
    octave.solve_linear_system(A,b)    # optional - octave
Exception raised:
    Traceback (most recent call last):
      File "/home/slabbe/GitBox/sage/local/lib/python3.8/site-
packages/sage/doctest/forker.py", line 694, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/slabbe/GitBox/sage/local/lib/python3.8/site-
packages/sage/doctest/forker.py", line 1088, in compile_and_execute
        exec(compiled, globs)
      File "<doctest doc.en.constructions.linear_algebra[4]>", line 1,
in <module>
        octave.solve_linear_system(A,b)    # optional - octave
      File "/home/slabbe/GitBox/sage/local/lib/python3.8/site-
packages/sage/interfaces/octave.py", line 518, in solve_linear_system
        return eval(sol)
      File "<string>", line 1
        [-0.333333, 0.666667, 0,
                               ^
    SyntaxError: unexpected EOF while parsing
**********************************************************************
1 item had failures:
   1 of 115 in doc.en.constructions.linear_algebra
    [93 tests, 1 failure, 1.57 s]
sage -t --random-seed=53840594329377719172370096027971271567
src/doc/en/developer/coding_in_other.rst
**********************************************************************
File "src/doc/en/developer/coding_in_other.rst", line 721, in
doc.en.developer.coding_in_other.solve_linear_system
Failed example:
    octave.solve_linear_system(A,b)    # optional - octave
Exception raised:
    Traceback (most recent call last):
      File "/home/slabbe/GitBox/sage/local/lib/python3.8/site-
packages/sage/doctest/forker.py", line 694, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/slabbe/GitBox/sage/local/lib/python3.8/site-
packages/sage/doctest/forker.py", line 1088, in compile_and_execute
        exec(compiled, globs)
      File "<doctest
doc.en.developer.coding_in_other.solve_linear_system[4]>", line 1, in
<module>
        octave.solve_linear_system(A,b)    # optional - octave
      File "/home/slabbe/GitBox/sage/local/lib/python3.8/site-
packages/sage/interfaces/octave.py", line 518, in solve_linear_system
        return eval(sol)
      File "<string>", line 1
        [-0.333333, 0.666667, 0,
                               ^
    SyntaxError: unexpected EOF while parsing
**********************************************************************
1 item had failures:
   1 of   6 in doc.en.developer.coding_in_other.solve_linear_system
    [41 tests, 1 failure, 0.57 s]
sage -t --random-seed=53840594329377719172370096027971271567
src/sage/interfaces/octave.py
**********************************************************************
File "src/sage/interfaces/octave.py", line 158, in
sage.interfaces.octave.Octave
Failed example:
    octave.eval("a = [ 1, 1, 2; 3, 5, 8; 13, 21, 33 ]")    # optional -
octave
Expected:
    'a =\n\n 1 1 2\n 3 5 8\n 13 21 33\n\n'
Got:
    'a =\n\n 1 1 2\n 3 5 8\n 13 21 33\n'
**********************************************************************
File "src/sage/interfaces/octave.py", line 160, in
sage.interfaces.octave.Octave
Failed example:
    octave.eval("b = [ 1; 3; 13]")                         # optional -
octave
Expected:
    'b =\n\n 1\n 3\n 13\n\n'
Got:
    'b =\n\n 1\n 3\n 13\n'
**********************************************************************
File "src/sage/interfaces/octave.py", line 495, in
sage.interfaces.octave.Octave.solve_linear_system
Failed example:
    octave.solve_linear_system(A,b)    # optional - octave (and output
is slightly random in low order bits)
Exception raised:
    Traceback (most recent call last):
      File "/home/slabbe/GitBox/sage/local/lib/python3.8/site-
packages/sage/doctest/forker.py", line 694, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/slabbe/GitBox/sage/local/lib/python3.8/site-
packages/sage/doctest/forker.py", line 1088, in compile_and_execute
        exec(compiled, globs)
      File "<doctest
sage.interfaces.octave.Octave.solve_linear_system[4]>", line 1, in
<module>
        octave.solve_linear_system(A,b)    # optional - octave (and
output is slightly random in low order bits)
      File "/home/slabbe/GitBox/sage/local/lib/python3.8/site-
packages/sage/interfaces/octave.py", line 518, in solve_linear_system
        return eval(sol)
      File "<string>", line 1
        [-0.333333, 0.666667, 0,
                               ^
    SyntaxError: unexpected EOF while parsing
**********************************************************************
2 items had failures:
   2 of   8 in sage.interfaces.octave.Octave
   1 of   6 in sage.interfaces.octave.Octave.solve_linear_system
    [132 tests, 3 failures, 1.06 s]
----------------------------------------------------------------------
sage -t --random-seed=53840594329377719172370096027971271567
src/doc/en/constructions/linear_algebra.rst  # 1 doctest failed
sage -t --random-seed=53840594329377719172370096027971271567
src/doc/en/developer/coding_in_other.rst  # 1 doctest failed
sage -t --random-seed=53840594329377719172370096027971271567
src/sage/interfaces/octave.py  # 3 doctests failed
----------------------------------------------------------------------
}}}

This is with:

{{{
$ octave --version
GNU Octave, version 5.2.0
Copyright (C) 2020 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.

Octave was configured for "x86_64-pc-linux-gnu".

Additional information about Octave is available at
https://www.octave.org.

Please contribute if you find this software useful.
For more information, visit https://www.octave.org/get-involved.html

Read https://www.octave.org/bugs.html to learn how to submit bug
reports.
}}}

A previous ticket about doctest failures with octave is #30636.

URL: https://trac.sagemath.org/33093
Reported by: slabbe
Ticket author(s): John Palmieri
Reviewer(s): Frédéric Chapoton
  • Loading branch information
Release Manager committed Sep 19, 2022
2 parents 509ed92 + cf9b1e6 commit d238396
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/sage/interfaces/octave.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
import pexpect
from sage.misc.verbose import verbose
from sage.misc.instancedoc import instancedoc
from sage.misc.temporary_file import tmp_filename
from sage.cpython.string import bytes_to_str


Expand All @@ -156,13 +157,13 @@ class Octave(Expect):
EXAMPLES::
sage: octave.eval("a = [ 1, 1, 2; 3, 5, 8; 13, 21, 33 ]") # optional - octave
'a =\n\n 1 1 2\n 3 5 8\n 13 21 33\n\n'
'a =\n\n 1 1 2\n 3 5 8\n 13 21 33\n'
sage: octave.eval("b = [ 1; 3; 13]") # optional - octave
'b =\n\n 1\n 3\n 13\n\n'
sage: octave.eval("c=a \\ b") # solves linear equation: a*c = b # optional - octave; random output
'c =\n\n 1\n 7.21645e-16\n -7.21645e-16\n\n'
'b =\n\n 1\n 3\n 13\n'
sage: octave.eval(r"c=a \ b") # solves linear equation: a*c = b # optional - octave; random output
'c =\n\n 1\n 7.21645e-16\n -7.21645e-16\n'
sage: octave.eval("c") # optional - octave; random output
'c =\n\n 1\n 7.21645e-16\n -7.21645e-16\n\n'
'c =\n\n 1\n 7.21645e-16\n -7.21645e-16\n'
TESTS:
Expand All @@ -186,12 +187,14 @@ def __init__(self, maxread=None, script_subdirectory=None, logfile=None,
command = os.getenv('SAGE_OCTAVE_COMMAND') or 'octave-cli'
if server is None:
server = os.getenv('SAGE_OCTAVE_SERVER') or None
# Use a temporary workspace file.
workspace_file = tmp_filename()
Expect.__init__(self,
name='octave',
# We want the prompt sequence to be unique to avoid confusion with syntax error messages containing >>>
prompt=r'octave\:\d+> ',
# We don't want any pagination of output
command=command + " --no-line-editing --silent --eval 'PS2(PS1());more off' --persist",
command=command + f" --no-line-editing --silent --eval 'PS2(PS1());more off; octave_core_file_name (\"{workspace_file}\")' --persist",
maxread=maxread,
server=server,
server_tmpdir=server_tmpdir,
Expand Down Expand Up @@ -510,9 +513,9 @@ def solve_linear_system(self, A, b):
sb = self.sage2octave_matrix_string(b)
self.eval("a = " + sA )
self.eval("b = " + sb )
soln = octave.eval("c = a \\ b")
soln = octave.eval(r"c = a \ b")
soln = soln.replace("\n\n ","[")
soln = soln.replace("\n\n","]")
soln = soln.rstrip() + "]"
soln = soln.replace("\n",",")
sol = soln[3:]
return eval(sol)
Expand Down

0 comments on commit d238396

Please sign in to comment.