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

covering_design.py & design_catalog.py: Fix AttributeError #27821

Closed
vinklein mannequin opened this issue May 13, 2019 · 15 comments
Closed

covering_design.py & design_catalog.py: Fix AttributeError #27821

vinklein mannequin opened this issue May 13, 2019 · 15 comments

Comments

@vinklein
Copy link
Mannequin

vinklein mannequin commented May 13, 2019

  1. Fix the following bug.
sage: C = designs.best_known_covering_design_from_LJCR(7, 3, 2)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-a3d9f9e592f1> in <module>()
----> 1 C = designs.best_known_covering_design_from_LJCR(Integer(7), Integer(3), Integer(2))

/home/slabbe/GitBox/sage/local/lib/python2.7/site-packages/sage/combinat/designs/covering_design.pyc in best_known_covering_design_www(v, k, t, verbose)
    525     if verbose:
    526         print("Looking up the bounds at %s" % url)
--> 527     with urlopen(url) as f:
    528         s = bytes_to_str(f.read())
    529     if 'covering not in database' in s:  # not found

AttributeError: addinfourl instance has no attribute '__exit__'

Found by Sebastien Labbé see #26592

The root cause is that the object returned by urlopen doesn't have an __exit__ method in python2 and therefore it can not be used with a with ... as ... syntax.

  1. Fix a doctest error in design_catalog.py:
sage -t --long src/sage/combinat/designs/design_catalog.py
**********************************************************************
File "src/sage/combinat/designs/design_catalog.py", line 23, in sage.combinat.designs.design_catalog
Failed example:
    C                            # optional - internet
Expected:
    (7,3,2)-covering design of size 7
    Lower bound: 7
    Method: lex covering
    Submitted on: 1996-12-01 00:00:00
Got:
    (7, 3, 2)-covering design of size 7
    Lower bound: 7
    Method: lex covering
    Submitted on: 1996-12-01 00:00:00
**********************************************************************

CC: @seblabbe @slel

Component: combinatorial designs

Keywords: thursdaysbdx

Author: Vincent Klein

Branch/Commit: 138870c

Reviewer: Sébastien Labbé

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

@vinklein vinklein mannequin added this to the sage-8.8 milestone May 13, 2019
@vinklein vinklein mannequin changed the title convering_design.py : Fix AttributeError covering_design.py : Fix AttributeError May 13, 2019
@vinklein

This comment has been minimized.

@vinklein

This comment has been minimized.

@seblabbe
Copy link
Contributor

comment:4

Is this a solution:

from six.moves.urllib.request import urlopen

? This is what I used in #25535.

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented May 13, 2019

Branch: u/vklein/27821

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented May 13, 2019

comment:6

Replying to @seblabbe:

Is this a solution:

from six.moves.urllib.request import urlopen

? This is what I used in #25535.

No because it is already used in covering_design.py.
In #25535 you use with ... as with a file objet, this works nicely.


New commits:

1e93e49Trac #27821: Fix AttributeError in ...

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented May 13, 2019

Commit: 1e93e49

@vinklein vinklein mannequin added the s: needs review label May 13, 2019
@seblabbe
Copy link
Contributor

comment:8

As mentionned here, two files were having the same issue. We are almost there.

There is still one small issue:

$ sage -tp --long --optional=sage,optional,external src/sage/combinat/designs/covering_design.py  src/sage/combinat/designs/design_catalog.py

gives

too many failed tests, not using stored timings
Running doctests with ID 2019-05-13-17-17-32-23591643.
Git branch: 27821
Using --optional=4ti2,bliss,cbc,ccache,cmake,cryptominisat,dot2tex,e_antic,external,glucose,latte_int,lidia,lrslib,memlimit,mpir,ninja_build,normaliz,notedown,pandoc_attributes,pycosat,pynormaliz,python2,qhull,rst2ipynb,sage,topcom
External software to be detected: cplex,ffmpeg,graphviz,gurobi,imagemagick,internet,latex,macaulay2,magma,maple,mathematica,matlab,octave,pandoc,scilab
Doctesting 2 files using 8 threads.
sage -t --long src/sage/combinat/designs/design_catalog.py
**********************************************************************
File "src/sage/combinat/designs/design_catalog.py", line 23, in sage.combinat.designs.design_catalog
Failed example:
    C                            # optional - internet
Expected:
    (7,3,2)-covering design of size 7
    Lower bound: 7
    Method: lex covering
    Submitted on: 1996-12-01 00:00:00
Got:
    (7, 3, 2)-covering design of size 7
    Lower bound: 7
    Method: lex covering
    Submitted on: 1996-12-01 00:00:00
**********************************************************************
1 item had failures:
   1 of   5 in sage.combinat.designs.design_catalog
    [4 tests, 1 failure, 0.73 s]
sage -t --long src/sage/combinat/designs/covering_design.py
    [49 tests, 0.73 s]
----------------------------------------------------------------------
sage -t --long src/sage/combinat/designs/design_catalog.py  # 1 doctest failed
----------------------------------------------------------------------
Total time for all tests: 0.8 seconds
    cpu time: 0.1 seconds
    cumulative wall time: 1.5 seconds
External software detected for doctesting: internet

@vinklein

This comment has been minimized.

@vinklein vinklein mannequin changed the title covering_design.py : Fix AttributeError covering_design.py & design_catalog.py: Fix AttributeError May 13, 2019
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 13, 2019

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

138870cTrac #27821: Fix a doctest in design_catalog.py

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 13, 2019

Changed commit from 1e93e49 to 138870c

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented May 13, 2019

comment:11

The other doctest bug of design_catalog.py has been fixed.

@vinklein vinklein mannequin added s: needs review and removed s: needs work labels May 13, 2019
@seblabbe
Copy link
Contributor

comment:12

It works! Thank you.

@seblabbe
Copy link
Contributor

Changed keywords from none to thursdaysbdx

@seblabbe
Copy link
Contributor

Reviewer: Sébastien Labbé

@vbraun
Copy link
Member

vbraun commented May 21, 2019

Changed branch from u/vklein/27821 to 138870c

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

2 participants