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

[MRG] replace utils.TempDirectory with run tmp #1502

Merged
merged 8 commits into from
May 13, 2021
Merged
37 changes: 14 additions & 23 deletions tests/test_cmd_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -1588,27 +1588,18 @@ def test_import_export_2(c):
assert imported.minhash == compare.minhash


def test_import_mash_csv_to_sig():
def test_import_mash_csv_to_sig(runtmp):
# test copied over from 'sourmash import_csv'.
with utils.TempDirectory() as location:
testdata1 = utils.get_test_data('short.fa.msh.dump')
testdata2 = utils.get_test_data('short.fa')

status, out, err = utils.runscript('sourmash', ['sig', 'import',
'--csv',
testdata1,
'-o', 'xxx.sig'],
in_directory=location)

status, out, err = utils.runscript('sourmash',
['compute', '-k', '31',
'-n', '970', testdata2],
in_directory=location)

status, out, err = utils.runscript('sourmash',
['search', '-k', '31',
'short.fa.sig', 'xxx.sig'],
in_directory=location)
print(status, out, err)
assert '1 matches:' in out
assert '100.0% short.fa' in out
testdata1 = utils.get_test_data('short.fa.msh.dump')
testdata2 = utils.get_test_data('short.fa')

runtmp.sourmash('sig', 'import', '--csv', testdata1, '-o', 'xxx.sig')

runtmp.sourmash('compute', '-k', '31', '-n', '970', testdata2)

runtmp.sourmash('search', '-k', '31', 'short.fa.sig', 'xxx.sig')

print("RUNTEMP", runtmp)

assert '1 matches:' in runtmp.last_result.out
assert '100.0% short.fa' in runtmp.last_result.out
39 changes: 18 additions & 21 deletions tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def test_linear_index_search_abund_subj_flat():
assert "'search_abund' requires subject signatures with abundance information" in str(exc.value)


def test_linear_index_save():
def test_linear_index_save(runtmp):
sig2 = utils.get_test_data('2.fa.sig')
sig47 = utils.get_test_data('47.fa.sig')
sig63 = utils.get_test_data('63.fa.sig')
Expand All @@ -424,24 +424,23 @@ def test_linear_index_save():
linear.insert(ss47)
linear.insert(ss63)

with utils.TempDirectory() as location:
filename = os.path.join(location, 'foo')
linear.save(filename)
filename = runtmp.output('foo')
linear.save(filename)

si = set(sourmash.load_file_as_signatures(filename))
si = set(sourmash.load_file_as_signatures(filename))

x = {ss2, ss47, ss63}

print(len(si))
print(len(x))

print(si)
print(x)
print('si: ', si)
print('x: ', x)

assert si == x, si


def test_linear_index_load():
def test_linear_index_load(runtmp):
sig2 = utils.get_test_data('2.fa.sig')
sig47 = utils.get_test_data('47.fa.sig')
sig63 = utils.get_test_data('63.fa.sig')
Expand All @@ -450,21 +449,20 @@ def test_linear_index_load():
ss47 = sourmash.load_one_signature(sig47)
ss63 = sourmash.load_one_signature(sig63)

with utils.TempDirectory() as location:
from sourmash import save_signatures

filename = os.path.join(location, 'foo')
with open(filename, 'wt') as fp:
sourmash.save_signatures([ss2, ss47, ss63], fp)
from sourmash import save_signatures

filename = runtmp.output('foo')
with open(filename, 'wt') as fp:
sourmash.save_signatures([ss2, ss47, ss63], fp)

linear = LinearIndex.load(filename)
linear = LinearIndex.load(filename)

x = {ss2, ss47, ss63}
assert set(linear.signatures()) == x, linear.signatures
assert linear.location == filename


def test_linear_index_save_load():
def test_linear_index_save_load(runtmp):
sig2 = utils.get_test_data('2.fa.sig')
sig47 = utils.get_test_data('47.fa.sig')
sig63 = utils.get_test_data('63.fa.sig')
Expand All @@ -477,11 +475,10 @@ def test_linear_index_save_load():
linear.insert(ss2)
linear.insert(ss47)
linear.insert(ss63)

with utils.TempDirectory() as location:
filename = os.path.join(location, 'foo')
linear.save(filename)
linear2 = LinearIndex.load(filename)

filename = runtmp.output('foo')
linear.save(filename)
linear2 = LinearIndex.load(filename)

# now, search for sig2
sr = linear2.search(ss2, threshold=1.0)
Expand Down