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

Bug: save_signatures with a file opened in binary mode fails #746

Merged
merged 4 commits into from
Oct 22, 2019

Conversation

luizirber
Copy link
Member

@luizirber luizirber commented Oct 19, 2019

(Yes, it's one of those days)

This will fail in Python 3:

with open(output, "wb") as fp:
    sourmash.save_signatures([query], fp)

because there is a call to unicode(s) and unicode() doesn't exist in Python 3 anymore:

Traceback (most recent call last):
  File "src/sourmash/sourmash/signature_json.py", line 279, in write_records_to_json
    fp.write(s)
TypeError: a bytes-like object is required, not 'str'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "unassigned.py", line 54, in <module>
    sourmash.save_signatures([query], fp)
  File "/home/chick/Envs/2019-10-17-unassigned_hashes-gY7Uf7Ke/src/sourmash/sourmash/signature.py", line 262, in save_signatures
    return signature_json.save_signatures_json(siglist, fp)  File "/home/chick/Envs/2019-10-17-unassigned_hashes-gY7Uf7Ke/src/sourmash/sourmash/signature_json.py", line 298, in save_signatures_json    s = write_records_to_json(records, fp, indent, sort_keys)
  File "/home/chick/Envs/2019-10-17-unassigned_hashes-gY7Uf7Ke/src/sourmash/sourmash/signature_json.py", line 281, in write_records_to_json
    fp.write(unicode(s))
NameError: name 'unicode' is not defined

This PR adds a test to trigger the bug, and a fix that works in Py 3/2.

Checklist

  • Is it mergeable?
  • make test Did it pass the tests?
  • make coverage Is the new code covered?
  • Did it change the command-line interface? Only additions are allowed
    without a major version increment. Changing file formats also requires a
    major version number increment.
  • Was a spellchecker run on the source code and documentation after
    changes were made?

@codecov
Copy link

codecov bot commented Oct 19, 2019

Codecov Report

Merging #746 into master will increase coverage by 0.13%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #746      +/-   ##
==========================================
+ Coverage   88.28%   88.42%   +0.13%     
==========================================
  Files          30       30              
  Lines        4782     4786       +4     
  Branches       46       46              
==========================================
+ Hits         4222     4232      +10     
+ Misses        557      551       -6     
  Partials        3        3
Impacted Files Coverage Δ
sourmash/signature_json.py 97.19% <100%> (+1.19%) ⬆️
sourmash/sbt_storage.py 85.39% <0%> (-0.98%) ⬇️
sourmash/sbt.py 85.53% <0%> (+0.31%) ⬆️
sourmash/lca/command_index.py 90.7% <0%> (+0.44%) ⬆️
sourmash/lca/lca_utils.py 96.01% <0%> (+0.79%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 476c704...22a3e53. Read the comment docs.

@ctb
Copy link
Contributor

ctb commented Oct 22, 2019

LGTM! Let's merge when the tests on the updated merge pass.

@luizirber luizirber merged commit 21f4894 into master Oct 22, 2019
@luizirber luizirber deleted the bug_binary_save_sig branch October 22, 2019 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants