Skip to content

Commit

Permalink
Trac #28760: py3: internet str vs bytes doctests failures
Browse files Browse the repository at this point in the history
{{{
sage -t --optional=sage,optional,external src/sage/coding/databases.py
}}}

gives

{{{
----------------------------------------------------------------------
sage -t src/sage/coding/databases.py  # 2 doctests failed
----------------------------------------------------------------------
}}}

with errors of that kind:

{{{
sage -t src/sage/coding/databases.py
**********************************************************************
File "src/sage/coding/databases.py", line 137, in
sage.coding.databases.best_linear_code_in_codetables_dot_de
Failed example:
    L = codes.databases.best_linear_code_in_codetables_dot_de(72, 36,
GF(2))    # optional - internet
Exception raised:
    Traceback (most recent call last):
      File "/home/slabbe/GitBox/sage/local/lib/python3.7/site-
packages/sage/doctest/forker.py", line 681, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/slabbe/GitBox/sage/local/lib/python3.7/site-
packages/sage/doctest/forker.py", line 1123, in compile_and_execute
        exec(compiled, globs)
      File "<doctest
sage.coding.databases.best_linear_code_in_codetables_dot_de[0]>", line
1, in <module>
        L =
codes.databases.best_linear_code_in_codetables_dot_de(Integer(72),
Integer(36), GF(Integer(2)))    # optional - internet
      File "/home/slabbe/GitBox/sage/local/lib/python3.7/site-
packages/sage/coding/databases.py", line 174, in
best_linear_code_in_codetables_dot_de
        i = s.find("<PRE>")
    TypeError: argument should be integer or bytes-like object, not
'str'
**********************************************************************
}}}

URL: https://trac.sagemath.org/28760
Reported by: slabbe
Ticket author(s): Frédéric Chapoton
Reviewer(s): Sébastien Labbé
  • Loading branch information
Release Manager committed Nov 28, 2019
2 parents 5dcc268 + 1b000e1 commit 1dd5565
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/sage/coding/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def best_linear_code_in_codetables_dot_de(n, k, F, verbose=False):
- David Joyner (2008-03)
"""
from six.moves.urllib.request import urlopen
from sage.cpython.string import bytes_to_str
q = F.order()
if not q in [2, 3, 4, 5, 7, 8, 9]:
raise ValueError("q (=%s) must be in [2,3,4,5,7,8,9]" % q)
Expand All @@ -167,16 +168,16 @@ def best_linear_code_in_codetables_dot_de(n, k, F, verbose=False):
url = "http://www.codetables.de/" + "BKLC/BKLC.php" + param
if verbose:
print("Looking up the bounds at %s" % url)
f = urlopen(url)
s = f.read()
f.close()
with urlopen(url) as f:
s = f.read()

s = bytes_to_str(s)
i = s.find("<PRE>")
j = s.find("</PRE>")
if i == -1 or j == -1:
raise IOError("Error parsing data (missing pre tags).")
text = s[i+5:j].strip()
return text
return s[i+5:j].strip()


def self_orthogonal_binary_codes(n, k, b=2, parent=None, BC=None, equal=False,
in_test=None):
Expand Down

0 comments on commit 1dd5565

Please sign in to comment.