Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doctests to accept exception messages reworded in python 3.10 #32520

Closed
mkoeppe opened this issue Sep 16, 2021 · 23 comments
Closed

Fix doctests to accept exception messages reworded in python 3.10 #32520

mkoeppe opened this issue Sep 16, 2021 · 23 comments

Comments

@mkoeppe
Copy link
Member

mkoeppe commented Sep 16, 2021

Tests with #30767 showed the following types of doctest failures from the more detailed exception messages provided by Python 3.10.

We fix them by widening the patterns.

sage -t --long --random-seed=0 src/sage/geometry/polyhedron/base.py
**********************************************************************
File "src/sage/geometry/polyhedron/base.py", line 214, in sage.geometry.polyhedron.base.Polyhedron_base.__init__
Failed example:
    p = Polyhedron_field(parent, Vrep, 'nonsense',  # py3
                         Vrep_minimal=True, Hrep_minimal=True, pref_rep='Vrep')
Expected:
    Traceback (most recent call last):
    ...
    TypeError: _init_Hrepresentation() takes 3 positional arguments but 9 were given
Got:
    <BLANKLINE>
    Traceback (most recent call last):
...
    TypeError: Polyhedron_field._init_Hrepresentation() takes 3 positional arguments but 9 were given
File "src/sage/plot/graphics.py", line 1262, in sage.plot.graphics.Graphics.plot
Failed example:
    S.plot(hey="hou")
Expected:
    Traceback (most recent call last):
    ...
    TypeError: plot() got an unexpected keyword argument 'hey'
Got:
    <BLANKLINE>
    Traceback (most recent call last):
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10.0rc1/lib/python3.10/site-packages/sage/doctest/forker.py", line 704, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10.0rc1/lib/python3.10/site-packages/sage/doctest/forker.py", line 1098, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.plot.graphics.Graphics.plot[3]>", line 1, in <module>
        S.plot(hey="hou")
    TypeError: Graphics.plot() got an unexpected keyword argument 'hey'
sage -t --long --random-seed=0 src/sage/functions/other.py
**********************************************************************
File "src/sage/functions/other.py", line 2131, in sage.functions.other.Function_cases.__call__
Failed example:
    cases()
Expected:
    Traceback (most recent call last):
    ...
    TypeError: __call__() missing 1 required positional argument: 'l'
Got:
    <BLANKLINE>
    Traceback (most recent call last):
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10.0rc1/lib/python3.10/site-packages/sage/doctest/forker.py", line 704, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10.0rc1/lib/python3.10/site-packages/sage/doctest/forker.py", line 1098, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.functions.other.Function_cases.__call__[1]>", line 1, in <module>
        cases()
    TypeError: Function_cases.__call__() missing 1 required positional argument: 'l'
Expected:
    Traceback (most recent call last):
    ...
    TypeError: float() argument must be a string or a number...
Got:
    TypeError: float() argument must be a string or a real number, not 'list'
sage -t --long --random-seed=0 src/sage/misc/lazy_attribute.pyx
**********************************************************************
File "src/sage/misc/lazy_attribute.pyx", line 363, in sage.misc.lazy_attribute.lazy_attribute
Failed example:
    a.x = 4
Expected:
    Traceback (most recent call last):
    ...
    AttributeError: can...t set attribute
Got:
    <BLANKLINE>
    Traceback (most recent call last):
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10.0rc1/lib/python3.10/site-packages/sage/doctest/forker.py", line 704, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10.0rc1/lib/python3.10/site-packages/sage/doctest/forker.py", line 1098, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.lazy_attribute.lazy_attribute[35]>", line 1, in <module>
        a.x = Integer(4)
    AttributeError: can't set attribute 'x'
sage -t --long --random-seed=0 src/sage/repl/preparse.py
**********************************************************************
File "src/sage/repl/preparse.py", line 118, in sage.repl.preparse
Failed example:
    eval('4.__add__(3)')
Expected:
    Traceback (most recent call last):
    ...
    SyntaxError: invalid syntax
Got:
    <BLANKLINE>
    Traceback (most recent call last):
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10.0rc1/lib/python3.10/site-packages/sage/doctest/forker.py", line 704, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10.0rc1/lib/python3.10/site-packages/sage/doctest/forker.py", line 1098, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.repl.preparse[24]>", line 1, in <module>
        eval('4.__add__(3)')
      File "<string>", line 1
        4.__add__(3)
         ^
    SyntaxError: invalid decimal literal
sage -t --long --random-seed=0 src/sage/combinat/ncsf_qsym/tutorial.py
**********************************************************************
File "src/sage/combinat/ncsf_qsym/tutorial.py", line 132, in sage.combinat.ncsf_qsym.tutorial
Failed example:
    M[]
Expected:
    Traceback (most recent call last):
    ...
    SyntaxError: invalid syntax
Got:
    <BLANKLINE>
    Traceback (most recent call last):
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10.0rc1/lib/python3.10/site-packages/sage/doctest/forker.py", line 704, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10.0rc1/lib/python3.10/site-packages/sage/doctest/forker.py", line 1096, in compile_and_execute
        compiled = compiler(example)
      File "/Users/mkoeppe/s/sage/sage-rebasing/local/var/lib/sage/venv-python3.10.0rc1/lib/python3.10/site-packages/sage/doctest/forker.py", line 671, in compiler
        code = compile(example.source, filename, "single",
      File "<doctest sage.combinat.ncsf_qsym.tutorial[27]>", line 1
        M[]
        ^
    SyntaxError: invalid syntax. Perhaps you forgot a comma?

CC: @fchapoton @kiwifb @kliem

Component: refactoring

Author: Matthias Koeppe

Branch/Commit: 68d07f8

Reviewer: Jonathan Kliem

Issue created by migration from https://trac.sagemath.org/ticket/32520

@mkoeppe mkoeppe added this to the sage-9.5 milestone Sep 16, 2021
@mkoeppe

This comment has been minimized.

@mkoeppe
Copy link
Member Author

mkoeppe commented Sep 16, 2021

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 16, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

247a077git grep -l 'TypeError: .*() got an unexpected' | xargs sed -i.bak 's/TypeError: \(.*\)() got an unexpected/TypeError: ...\1() got an unexpected/'

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 16, 2021

Commit: 247a077

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 16, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

82d9329git grep -l 'TypeError: .*() missing' | xargs sed -i.bak 's/TypeError: \(.*\)() missing/TypeError: ...\1() missing/'
e80b828git grep -l 'TypeError: float() argument must be.*' | xargs sed -i.bak 's/TypeError: float() argument must be.*/TypeError: float() argument must be a string or a... number.../'
98a1ceegit grep -l 'AttributeError: can.* set attribute.*' | xargs sed -i.bak 's/AttributeError: can.* set attribute.*/AttributeError: can...t set attribute.../'
8511141git grep -l 'SyntaxError: invalid.*' | xargs sed -i.bak 's/SyntaxError: invalid.*/SyntaxError: invalid .../'

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 16, 2021

Changed commit from 247a077 to 8511141

@mkoeppe
Copy link
Member Author

mkoeppe commented Sep 16, 2021

Author: Matthias Koeppe

@mkoeppe

This comment has been minimized.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 16, 2021

Changed commit from 8511141 to 65c586b

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 16, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

65c586bFix 2 more doctests to accept exception messages reworded in python 3.10

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 16, 2021

Changed commit from 65c586b to 288bc84

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 16, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

668c41cfix syntax error in doctest
288bc84Merge branch 'public/32521' of git://trac.sagemath.org/sage into t/32520/fix_doctests_to_accept_exception_messages_reworded_in_python_3_10

@mkoeppe
Copy link
Member Author

mkoeppe commented Sep 16, 2021

Dependencies: #32520

@slel
Copy link
Member

slel commented Sep 19, 2021

comment:11

Did you mean to add a different ticket as a dependency?

@mkoeppe
Copy link
Member Author

mkoeppe commented Sep 19, 2021

Changed dependencies from #32520 to #32521

@mkoeppe
Copy link
Member Author

mkoeppe commented Sep 19, 2021

comment:12

Thanks

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 28, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

68d07f8Merge tag '9.5.beta2' into t/32520/fix_doctests_to_accept_exception_messages_reworded_in_python_3_10

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 28, 2021

Changed commit from 288bc84 to 68d07f8

@mkoeppe
Copy link
Member Author

mkoeppe commented Sep 28, 2021

Changed dependencies from #32521 to none

@kliem
Copy link
Contributor

kliem commented Sep 29, 2021

Reviewer: Jonathan Kliem

@kliem
Copy link
Contributor

kliem commented Sep 29, 2021

comment:16

LGTM.

@mkoeppe
Copy link
Member Author

mkoeppe commented Sep 29, 2021

comment:17

Thanks!

@vbraun
Copy link
Member

vbraun commented Oct 9, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants