/
test_api.py
88 lines (57 loc) · 2.42 KB
/
test_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import pytest
import sourmash
import sourmash_tst_utils as utils
@utils.in_tempdir
def test_sourmash_signature_api(c):
e = sourmash.MinHash(n=1, ksize=20)
sig = sourmash.SourmashSignature(e)
with open(c.output('xxx.sig'), 'wt') as fp:
sourmash.save_signatures([sig], fp)
sig_x1 = sourmash.load_one_signature(c.output('xxx.sig'))
sig_x2 = list(sourmash.load_file_as_signatures(c.output('xxx.sig')))[0]
assert sig_x1 == sig
assert sig_x2 == sig
@utils.in_tempdir
def test_load_index_0_no_file(c):
with pytest.raises(ValueError) as exc:
idx = sourmash.load_file_as_index(c.output('does-not-exist'))
assert 'Error while reading signatures from ' in str(exc.value)
def test_load_index_1():
testfile = utils.get_test_data('prot/protein.sbt.zip')
idx = sourmash.load_file_as_index(testfile)
sigs = list(idx.signatures())
assert len(sigs) == 2
def test_load_index_2():
testfile = utils.get_test_data('prot/protein.lca.json.gz')
idx = sourmash.load_file_as_index(testfile)
sigs = list(idx.signatures())
assert len(sigs) == 2
def test_load_index_3():
testfile = utils.get_test_data('prot/protein/')
idx = sourmash.load_file_as_index(testfile)
sigs = list(idx.signatures())
assert len(sigs) == 2
def test_load_index_4():
testfile = utils.get_test_data('prot/all.zip')
idx = sourmash.load_file_as_index(testfile)
sigs = list(idx.signatures())
assert len(sigs) == 8
def test_load_index_4_b():
testfile = utils.get_test_data('prot/protein.zip')
idx = sourmash.load_file_as_index(testfile)
sigs = list(idx.signatures())
assert len(sigs) == 2
def test_load_fasta_as_signature():
# try loading a fasta file - should fail with informative exception
testfile = utils.get_test_data('short.fa')
with pytest.raises(Exception) as exc:
idx = sourmash.load_file_as_index(testfile)
print(exc.value)
assert f"Error while reading signatures from '{testfile}' - got sequences instead! Is this a FASTA/FASTQ file?" in str(exc.value)
def test_load_and_search_sbt_api():
treefile = utils.get_test_data('prot/protein.sbt.zip')
queryfile = utils.get_test_data('prot/protein/GCA_001593925.1_ASM159392v1_protein.faa.gz.sig')
tree = sourmash.load_sbt_index(treefile)
query = sourmash.load_one_signature(queryfile)
results = list(sourmash.search_sbt_index(tree, query, 0))
assert len(results) == 2