Skip to content

Commit

Permalink
[MRG] replace utils.TempDirectory with run tmp (#1502)
Browse files Browse the repository at this point in the history
* replaced utils.TempDirectory with run tmp

* added runner context run.tmp

* updated test_import_mash_csv_to_sig with runtmp fixture

* replaced "runner context" w runtmp

* updated runner context and working

* added runtmp to test_linear_index_save, wrking

* added runtmp to test_linear_index_save_load, wrkng

Co-authored-by: C. Titus Brown <titus@idyll.org>
  • Loading branch information
hehouts and ctb committed May 13, 2021
1 parent 3b8793c commit 4c48f39
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 44 deletions.
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

0 comments on commit 4c48f39

Please sign in to comment.