Skip to content

Commit

Permalink
down to 32 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Nov 23, 2023
1 parent 5366fd8 commit e5656f8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 deletions.
6 changes: 4 additions & 2 deletions src/sourmash/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ def plot(args):
D_filename = args.distances

notify(f'loading comparison matrix from {D_filename}...')
D = numpy.load(open(D_filename, 'rb'))
with open(D_filename, 'rb') as f:
D = numpy.load(f)
# not sure how to change this to use f-strings
notify('...got {} x {} matrix.', *D.shape)

Expand All @@ -274,7 +275,8 @@ def plot(args):
labelfilename = D_filename + '.labels.txt'

notify(f'loading labels from {labelfilename}')
labeltext = [ x.strip() for x in open(labelfilename) ]
with open(labelfilename) as f:
labeltext = [ x.strip() for x in f ]

if len(labeltext) != D.shape[0]:
error('{} labels != matrix size, exiting', len(labeltext))
Expand Down
4 changes: 2 additions & 2 deletions src/sourmash/save_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def _error_on_fastaq(filename, **kwargs):
success = False
try:
with screed.open(filename) as it:
_ = next(iter(it))
_ = next(it)

success = True
except:
Expand Down Expand Up @@ -288,7 +288,7 @@ def _get_signatures_from_rust(siglist):
# Rust supports multiple. For now, go through serializing
# and deserializing the signature! See issue #1167 for more.
json_str = sourmash.save_signatures(siglist)
for ss in sourmash.load_signatures(json_str):
for ss in sourmash.signature.load_signatures(json_str):
yield ss


Expand Down
3 changes: 2 additions & 1 deletion tests/test_lca.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import csv
import pytest
import glob
from pathlib import Path

import sourmash_tst_utils as utils
import sourmash
Expand Down Expand Up @@ -1830,7 +1831,7 @@ def test_single_summarize_to_output_check_filename(runtmp):
print(runtmp.last_result.out)
print(runtmp.last_result.err)

outdata = open(runtmp.output('output.txt'), 'rt').read()
outdata = Path(runtmp.output('output.txt')).read_text()

assert 'loaded 1 signatures from 1 files total.' in runtmp.last_result.err
assert 'count,superkingdom,phylum,class,order,family,genus,species,strain,filename,sig_name,sig_md5,total_counts\n' in outdata
Expand Down
8 changes: 4 additions & 4 deletions tests/test_picklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_load_empty_picklist_allow():
def test_dup_md5_picked(runtmp):
# load a sig, duplicate, and see if a picklist gets the right one
sig47 = utils.get_test_data('47.fa.sig')
ss = sourmash.load_signatures(sig47)
ss = sourmash.load_file_as_signatures(sig47)
sig = list(ss)[0]

# save a manifest with one entry
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_dup_md5_picked_mf_to_picklist(runtmp):
# load a sig, duplicate, and see if a picklist gets the right one
# uses an in memory picklist
sig47 = utils.get_test_data('47.fa.sig')
ss = sourmash.load_signatures(sig47)
ss = sourmash.load_file_as_signatures(sig47)
sig = list(ss)[0]

# save a manifest with one entry
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_dup_md5_picked_mf_to_picklist_sqlite(runtmp):
# load a sig, duplicate, and see if a picklist gets the right one
# use a sqlite db with its own to_picklist behavior.
sig47 = utils.get_test_data('47.fa.sig')
ss = sourmash.load_signatures(sig47)
ss = sourmash.load_file_as_signatures(sig47)
sig = list(ss)[0]

# save a manifest with one entry
Expand All @@ -126,4 +126,4 @@ def test_dup_md5_picked_mf_to_picklist_sqlite(runtmp):
ml3 = ml2.select(picklist=pl)
print('picked:', len(ml3))

assert len(pl.pickset) == len(ml3)
assert len(pl.pickset) == len(ml3)
48 changes: 26 additions & 22 deletions tests/test_sourmash.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import pytest
import zipfile
import random
import warnings
from pathlib import Path

import numpy

import sourmash_tst_utils as utils
Expand Down Expand Up @@ -1658,8 +1661,7 @@ def test_do_sourmash_sbt_search_output(runtmp):

runtmp.sourmash('search', 'short.fa.sig', 'zzz', '-o', 'foo')

outfile = open(runtmp.output('foo'))
output = outfile.read()
output = Path(runtmp.output('foo')).read_text()
print(output)
assert 'e26a306d26512' in output
assert '914591cd1130aa915' in output
Expand Down Expand Up @@ -1733,8 +1735,7 @@ def test_do_sourmash_sbt_move_and_search_output(runtmp):
'zzz.sbt.json', '-o', 'foo'],
in_directory=newpath)

outfile = open(os.path.join(newpath, 'foo'))
output = outfile.read()
output = Path(os.path.join(newpath, 'foo')).read_text()
print(output)
assert '914591cd1130aa91' in output
assert 'e26a306d2651' in output
Expand Down Expand Up @@ -2090,11 +2091,11 @@ def test_search_gzip(runtmp):

runtmp.sourmash('sketch','dna','-p','k=31,num=500', testdata1, testdata2)

data = open(runtmp.output('short.fa.sig'), 'rb').read()
data = Path(runtmp.output('short.fa.sig')).read_bytes()
with gzip.open(runtmp.output('zzz.gz'), 'wb') as fp:
fp.write(data)

data = open(runtmp.output('short2.fa.sig'), 'rb').read()
data = Path(runtmp.output('short2.fa.sig')).read_bytes()
with gzip.open(runtmp.output('yyy.gz'), 'wb') as fp:
fp.write(data)

Expand Down Expand Up @@ -3199,10 +3200,11 @@ def test_compare_with_abundance_1(runtmp):
s1 = signature.SourmashSignature(E1, filename='e1', name='e1')
s2 = signature.SourmashSignature(E2, filename='e2', name='e2')

signature.save_signatures([s1],
open(runtmp.output('e1.sig'), 'w'))
signature.save_signatures([s2],
open(runtmp.output('e2.sig'), 'w'))
with open(runtmp.output('e1.sig'), 'w') as f:
signature.save_signatures([s1], f)

with open(runtmp.output('e2.sig'), 'w') as f:
signature.save_signatures([s2], f)

runtmp.sourmash('search', 'e1.sig', 'e2.sig', '-k', '5')

Expand All @@ -3224,10 +3226,11 @@ def test_compare_with_abundance_2(runtmp):
s1 = signature.SourmashSignature(E1, filename='e1', name='e1')
s2 = signature.SourmashSignature(E2, filename='e2', name='e2')

signature.save_signatures([s1],
open(runtmp.output('e1.sig'), 'w'))
signature.save_signatures([s2],
open(runtmp.output('e2.sig'), 'w'))
with open(runtmp.output('e1.sig'), 'w') as f:
signature.save_signatures([s1], f)

with open(runtmp.output('e2.sig'), 'w') as f:
signature.save_signatures([s2], f)

runtmp.sourmash('search', 'e1.sig', 'e2.sig', '-k', '5')

Expand All @@ -3250,10 +3253,11 @@ def test_compare_with_abundance_3(runtmp):
s1 = signature.SourmashSignature(E1, filename='e1', name='e1')
s2 = signature.SourmashSignature(E2, filename='e2', name='e2')

signature.save_signatures([s1],
open(runtmp.output('e1.sig'), 'w'))
signature.save_signatures([s2],
open(runtmp.output('e2.sig'), 'w'))
with open(runtmp.output('e1.sig'), 'w') as f:
signature.save_signatures([s1], f)

with open(runtmp.output('e2.sig'), 'w') as f:
signature.save_signatures([s2], f)

runtmp.sourmash('search', 'e1.sig', 'e2.sig', '-k', '5')

Expand Down Expand Up @@ -5346,7 +5350,7 @@ def test_sbt_categorize(runtmp):
# yields 521/1000 ==> ~0.5
assert 'for genome-s10+s11, found: 0.50 genome-s10' in runtmp.last_result.err

out_csv = open(runtmp.output('out.csv')).read()
out_csv = Path(runtmp.output('out.csv')).read_text()
print(out_csv)
assert '4.sig,genome-s10+s11,genome-s10,0.504' in out_csv

Expand Down Expand Up @@ -5399,7 +5403,7 @@ def test_sbt_categorize_ignore_abundance_3(runtmp):

assert 'for 1-1, found: 0.88 1-1' in runtmp.last_result.err

out_csv4 = open(runtmp.output('out4.csv')).read()
out_csv4 = Path(runtmp.output('out4.csv')).read_text()
assert 'reads-s10x10-s11.sig,1-1,1-1,0.87699' in out_csv4


Expand Down Expand Up @@ -5787,7 +5791,7 @@ def test_do_sourmash_index_zipfile_append(c):
# should be no overlap
assert not set(first_half).intersection(set(second_half))

with pytest.warns(None) as record:
with warnings.catch_warnings(record=True) as record:
c.run_sourmash('index', '-k', '31', 'zzz.sbt.zip',
*first_half)
# UserWarning is raised when there are duplicated entries in the zipfile
Expand All @@ -5800,7 +5804,7 @@ def test_do_sourmash_index_zipfile_append(c):
assert c.last_result.status == 0
assert 'Finished saving SBT index, available at' in c.last_result.err

with pytest.warns(None) as record:
with warnings.catch_warnings(record=True) as record:
c.run_sourmash('index', "--append", '-k', '31', 'zzz.sbt.zip',
*second_half)
# UserWarning is raised when there are duplicated entries in the zipfile
Expand Down

0 comments on commit e5656f8

Please sign in to comment.