Skip to content

Commit 71aaaa3

Browse files
author
Will Trimble
committed
style cleanup
1 parent be059f2 commit 71aaaa3

2 files changed

Lines changed: 76 additions & 66 deletions

File tree

tests/test_api.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_500():
1919
assert False
2020
except SystemExit:
2121
pass
22-
22+
2323
def test_private():
2424
URI = API_URL + '/matrix/organism?id=mgm4454266.3' # mgm4454266.3 is private
2525
try:
@@ -37,14 +37,14 @@ def test_badkey():
3737
pass
3838

3939
def test_heartbeat():
40-
URI0 = API_URL + "heartbeat"
40+
URI0 = API_URL + "heartbeat"
4141
obj = obj_from_url(URI0)
42-
SERVICES = [ obj["requests"][1]["parameters"]["required"]["service"][1][i][0] for i in range(len( obj["requests"][1]["parameters"]["required"]["service"][1]))]
42+
SERVICES = [obj["requests"][1]["parameters"]["required"]["service"][1][i][0] for i in range(len(obj["requests"][1]["parameters"]["required"]["service"][1]))]
4343
for service in SERVICES:
4444
URI = API_URL + "heartbeat/" + service
4545
obj_detail = obj_from_url(URI)
4646
assert obj_detail["status"] == 1, "Failed heartbeat on " + service
47-
return 1
47+
return 1
4848

4949
def test_async_matrix3():
5050
URI = API_URL + '1/matrix/organism?id=mgm4653781.3&id=mgm4653783.3&id=mgm4653789.3&id=mgm4662211.3&id=mgm4662212.3&id=mgm4662235.3&id=mgm4662210.3&group_level=phylum&source=RDP&hit_type=single&result_type=abundance&evalue=1&identity=60&length=15&taxid=0&asynchronous=1' # takes too long??
@@ -59,34 +59,44 @@ def test_matrix_01():
5959
obj = obj_from_url(URI)
6060
o = open("1.txt", "w")
6161
o.write(str(obj))
62+
os.remove("1.txt")
6263
def test_matrix_02():
6364
URI = API_URL + '/matrix/organism?id=mgm4440282.3&group_level=phylum&source=RDP&hit_type=single&result_type=abundance&evalue=1&identity=60&length=15&taxid=0'
6465
obj = obj_from_url(URI)
6566
o = open("2.txt", "w")
6667
o.write(str(obj))
68+
os.remove("2.txt")
69+
6770
def test_matrix_03():
6871
URI = API_URL + '/matrix/organism?id=mgm4440283.3&group_level=phylum&source=RDP&hit_type=single&result_type=abundance&evalue=1&identity=60&length=15&taxid=0'
6972
obj = obj_from_url(URI)
7073
o = open("3.txt", "w")
7174
o.write(str(obj))
75+
os.remove("3.txt")
76+
7277
def test_matrix_04():
7378
URI = API_URL + '/matrix/organism?id=mgm4440284.3&group_level=phylum&source=RDP&hit_type=single&result_type=abundance&evalue=1&identity=60&length=15&taxid=0'
7479
obj = obj_from_url(URI)
7580
o = open("4.txt", "w")
7681
o.write(str(obj))
77-
82+
7883
def test_large_01():
7984
URI = API_URL + '/matrix/organism?group_level=phylum&source=RDP&hit_type=single&result_type=abundance&evalue=1&identity=60&length=15&taxid=0&id=mgm4510219.3'
8085
obj = obj_from_url(URI)
8186
o = open("5.txt", "w")
8287
o.write(str(obj))
88+
os.remove("5.txt")
89+
8390
def test_large_02():
8491
URI = API_URL + '/matrix/organism?group_level=phylum&source=RefSeq&hit_type=single&result_type=abundance&evalue=1&identity=60&length=15&taxid=0&id=mgm4510219.3'
8592
obj = obj_from_url(URI)
8693
o = open("6.txt", "w")
8794
o.write(str(obj))
95+
os.remove("6.txt")
96+
8897
def test_large_03():
8998
URI = API_URL + '/matrix/organism?group_level=phylum&source=SEED&hit_type=single&result_type=abundance&evalue=1&identity=60&length=15&taxid=0&id=mgm4510219.3'
9099
obj = obj_from_url(URI)
91100
o = open("7.txt", "w")
92101
o.write(str(obj))
102+
os.remove("7.txt")

tests/test_mgrtools.py

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env python
22
from __future__ import print_function
33

4-
import pytest
5-
4+
import sys
5+
import os
6+
from os.path import dirname, abspath
67
from subprocess import Popen, PIPE
78
import subprocess
8-
import sys, os
9-
from os.path import dirname, abspath
9+
import pytest
1010

1111
DATADIR = dirname(abspath(__file__)) + "/data/"
1212

@@ -21,10 +21,10 @@ def runme(command, workingdir=".", fail_ok=False):
2121
# oldout, olderr = sys.stdout, sys.stderr
2222
# sys.stdout = StringIO()
2323
# sys.stderr = StringIO()
24-
os.chdir(workingdir)
24+
os.chdir(workingdir)
2525

26-
try:
27-
p=subprocess.Popen(command, stdout=PIPE, stderr=PIPE, shell=True)
26+
try:
27+
p = subprocess.Popen(command, stdout=PIPE, stderr=PIPE, shell=True)
2828
except SystemExit as err:
2929
p = err.code
3030
out, err = p.communicate()
@@ -37,7 +37,7 @@ def runme(command, workingdir=".", fail_ok=False):
3737

3838
# Now undo all the renamed streams
3939
# sys.stdout, sys.stderr = oldout, olderr
40-
os.chdir(cwd)
40+
os.chdir(cwd)
4141
return status, out, err
4242

4343

@@ -52,7 +52,8 @@ def test_mginbox_help():
5252
# stat, out, err = runme('mg-upload2shock.py -h')
5353
# assert b'DESCRIPTION' in out
5454

55-
binscripts = ['mg-abundant-functions.py',
55+
binscripts = [
56+
'mg-abundant-functions.py',
5657
'mg-abundant-taxa.py',
5758
'mg-biom-merge.py',
5859
'mg-biom-view.py',
@@ -87,33 +88,33 @@ def test_mginbox_help():
8788
@pytest.mark.known_failing
8889
def test_binscripts_help():
8990
for binscript in binscripts:
90-
print("Invoking " + binscript+" -h")
91-
stat, out, err = runme(binscript + " -h")
92-
assert b'DESCRIPTION' in out
91+
print("Invoking " + binscript+" -h")
92+
stat, out, err = runme(binscript + " -h")
93+
assert b'DESCRIPTION' in out
9394

9495
def test_jsonviewer():
9596
s = '''echo '{"a": {"b": {"c": [1, 2, 3, 4, 5]}}, "x": ["y", "z"], "foo": "bar"}' | jsonviewer.py'''
96-
stat, out, err = runme(s)
97+
stat, out, err = runme(s)
9798
s2 = '''echo '{"a": {"b": {"c": [1, 2, 3, 4, 5]}}, "x": ["y", "z"], "foo": "bar"}' | jsonviewer.py --value 'a.b.c' --json'''
98-
stat, out, err = runme(s2)
99+
stat, out, err = runme(s2)
99100

100101
def test_mg_abundant_functions():
101102
s = '''mg-abundant-functions.py --id mgm4662210.3 --level level3 --source Subsystems --top 20 --evalue 8'''
102-
stat, out, err = runme(s)
103+
stat, out, err = runme(s)
103104

104105
def test_mg_abundant_taxa():
105106
s = '''mg-abundant-taxa.py --id mgm4662210.3 --level genus --source RefSeq --top 20 --evalue 8'''
106-
stat, out, err = runme(s)
107+
stat, out, err = runme(s)
107108

108109
@pytest.mark.huge
109110
def test_mg_compare_taxa():
110111
s = '''mg-compare-taxa.py --ids mgm4441679.3,mgm4441680.3,mgm4441681.3,mgm4441682.3 --level class --source RefSeq --format text | mg-changing-annotation.py --input - --format text --groups '{"group1":["mgm4441679.3","mgm4441680.3"],"group2":["mgm4441681.3","mgm4441682.3"]}' --top 5 --stat_test Kruskal-Wallis'''
111-
stat, out, err = runme(s)
112+
stat, out, err = runme(s)
112113

113114
@pytest.mark.huge
114115
def test_mg_compare_alpha_diversity():
115-
s= '''mg-compare-alpha-diversity.py --ids mgm4441679.3,mgm4441680.3,mgm4441681.3,mgm4441682.3 --level class --source RefSeq'''
116-
stat, out, err = runme(s)
116+
s = '''mg-compare-alpha-diversity.py --ids mgm4441679.3,mgm4441680.3,mgm4441681.3,mgm4441682.3 --level class --source RefSeq'''
117+
stat, out, err = runme(s)
117118

118119
def test_annotation():
119120
stat, out, err = runme('annotation_table.py')
@@ -124,97 +125,96 @@ def test_abundance():
124125
assert b'Archaea' in out
125126

126127
def test_mg_compare_functions():
127-
s='''mg-compare-functions.py --ids mgm4441679.3,mgm4441680.3,mgm4441681.3,mgm4441682.3 --level level2 --source KO --format text --evalue 8'''
128-
s='''mg-compare-functions.py --ids mgm4662210.3,mgm4662211.3,mgm4662212.3,mgm4662235.3 --level level2 --source KO --format text --evalue 8'''
129-
stat, out, err = runme(s)
128+
s = '''mg-compare-functions.py --ids mgm4662210.3,mgm4662211.3,mgm4662212.3,mgm4662235.3 --level level2 --source KO --format text --evalue 8'''
129+
stat, out, err = runme(s)
130130

131131
def test_mg_display_statistics():
132-
s='''mg-display-statistics.py --id mgm4441680.3 --stat sequence'''
133-
stat, out, err = runme(s)
134-
132+
s = '''mg-display-statistics.py --id mgm4441680.3 --stat sequence'''
133+
stat, out, err = runme(s)
134+
135135
def test_mg_download():
136-
s='''mg-download.py --metagenome mgm4441680.3 --list'''
137-
stat, out, err = runme(s)
136+
s = '''mg-download.py --metagenome mgm4441680.3 --list'''
137+
stat, out, err = runme(s)
138138

139139
#def test_mg_extract_sequences():
140-
# s='''mg-extract-sequences.py --function protease --biome marine'''
141-
# stat, out, err = runme(s)
140+
# s = '''mg-extract-sequences.py --function protease --biome marine'''
141+
# stat, out, err = runme(s)
142142

143143
def test_mg_get_sequences_for_function():
144-
s='''mg-get-sequences-for-function.py --id mgm4441680.3 --name "Central carbohydrate metabolism" --level level2 --source Subsystems --evalue 10'''
145-
stat, out, err = runme(s)
144+
s = '''mg-get-sequences-for-function.py --id mgm4441680.3 --name "Central carbohydrate metabolism" --level level2 --source Subsystems --evalue 10'''
145+
stat, out, err = runme(s)
146146
assert stat == 0
147147

148148
def test_mg_get_sequences_for_taxon():
149-
s='''mg-get-sequences-for-taxon.py --id mgm4441680.3 --name Lachnospiraceae --level family --source RefSeq --evalue 8'''
150-
stat, out, err = runme(s)
149+
s = '''mg-get-sequences-for-taxon.py --id mgm4441680.3 --name Lachnospiraceae --level family --source RefSeq --evalue 8'''
150+
stat, out, err = runme(s)
151151
assert stat == 0
152152

153153
def test_mg_query_matrix():
154-
s='''mg-query.py 'http://api.mg-rast.org/matrix/function?id=mgm4447943.3' '''
155-
stat, out, err = runme(s)
154+
s = '''mg-query.py 'http://api.mg-rast.org/matrix/function?id=mgm4447943.3' '''
155+
stat, out, err = runme(s)
156156
assert stat == 0
157157
assert b'acter' in out
158158

159159
@pytest.mark.known_failing
160160
def test_mg_query_darkmatter():
161-
s='''mg-query.py 'http://api.mg-rast.org/darkmatter/mgm4447943.3' '''
162-
stat, out, err = runme(s)
161+
s = '''mg-query.py 'http://api.mg-rast.org/darkmatter/mgm4447943.3' '''
162+
stat, out, err = runme(s)
163163
assert stat == 0
164164

165165
def test_mg_get_similarity_for_taxon():
166-
s='''mg-get-similarity-for-function.py --id mgm4441680.3 --name Central\ carbohydrate\ metabolism --level level2 --source Subsystems --evalue 10'''
167-
stat, out, err = runme(s)
166+
s = '''mg-get-similarity-for-function.py --id mgm4441680.3 --name Central\ carbohydrate\ metabolism --level level2 --source Subsystems --evalue 10'''
167+
stat, out, err = runme(s)
168168
assert stat == 0
169169
@pytest.mark.requires_auth
170170
def test_mg_inbox_view():
171-
s='''mg-inbox.py view all'''
172-
stat, out, err = runme(s)
171+
s = '''mg-inbox.py view all'''
172+
stat, out, err = runme(s)
173173
assert stat == 0
174174
@pytest.mark.known_failing
175175
def test_mg_kegg2ss():
176176
s = '''mg-kegg2ss.py --input - --output text'''
177-
stat, out, err = runme(s)
177+
stat, out, err = runme(s)
178178
assert stat == 0
179179
def test_mg_retrieve_uniprot():
180-
s='''mg-retrieve-uniprot.py --md5 ffc62262a18b38671c3e337150ef535f --source SwissProt'''
181-
stat, out, err = runme(s)
180+
s = '''mg-retrieve-uniprot.py --md5 ffc62262a18b38671c3e337150ef535f --source SwissProt'''
181+
stat, out, err = runme(s)
182182
assert stat == 0
183183

184184
def test_mg_project():
185-
s='''mg-project.py get-info mgp128'''
186-
stat, out, err = runme(s)
185+
s = '''mg-project.py get-info mgp128'''
186+
stat, out, err = runme(s)
187187
assert stat == 0
188188

189-
def test_mg_search_metagenomes__help():
190-
s='''mg-search-metagenomes.py --help'''
191-
stat, out, err = runme(s)
189+
def test_mg_search_metagenomes__help():
190+
s = '''mg-search-metagenomes.py --help'''
191+
stat, out, err = runme(s)
192192
assert stat == 0
193193

194-
def test_mg_display_metadata():
195-
s='''mg-display-metadata.py --id "mgm4441680.3" --verbosity full'''
196-
stat, out, err = runme(s)
194+
def test_mg_display_metadata():
195+
s = '''mg-display-metadata.py --id "mgm4441680.3" --verbosity full'''
196+
stat, out, err = runme(s)
197197
assert stat == 0
198198
assert b"medium-quality grass-legume hay" in out
199199

200200
@pytest.mark.requires_auth
201201
def test_mg_submit():
202-
s='''mg-submit.py list'''
203-
stat, out, err = runme(s)
202+
s = '''mg-submit.py list'''
203+
stat, out, err = runme(s)
204204
assert stat == 0
205205

206206
def test_mg_m5nrtoolspl():
207-
s='''m5nr-tools.pl --api http://api.mg-rast.org/ --option annotation --source RefSeq --md5 0b95101ffea9396db4126e4656460ce5,068792e95e38032059ba7d9c26c1be78,0b96c9'''
208-
stat, out, err = runme(s)
207+
s = '''m5nr-tools.pl --api http://api.mg-rast.org/ --option annotation --source RefSeq --md5 0b95101ffea9396db4126e4656460ce5,068792e95e38032059ba7d9c26c1be78,0b96c9'''
208+
stat, out, err = runme(s)
209209
assert stat == 0
210210
assert b"alcohol dehydrogenase" in out
211211

212212
def test_query_matrix():
213-
s='''mg-query.py 'http://api.mg-rast.org/matrix/organism?group_level=phylum&source=SEED&hit_type=single&result_type=abundance&evalue=1&identity=60&length=15&taxid=0&id=mgm4510219.3' > matrix.biom'''
214-
stat, out, err = runme(s)
213+
s = '''mg-query.py 'http://api.mg-rast.org/matrix/organism?group_level=phylum&source=SEED&hit_type=single&result_type=abundance&evalue=1&identity=60&length=15&taxid=0&id=mgm4510219.3' > matrix.biom'''
214+
stat, out, err = runme(s)
215215
assert stat == 0
216216
def test_mg_biom_view():
217-
s='''mg-biom-view.py < {}/mgm4514486.3.refseq.biom.json'''.format(DATADIR)
218-
stat, out, err = runme(s)
219-
assert stat == 0
217+
s = '''mg-biom-view.py < {}/mgm4514486.3.refseq.biom.json'''.format(DATADIR)
218+
stat, out, err = runme(s)
219+
assert stat == 0
220220
assert b'Bacteria;Proteobacteria;Gammaproteobacteria;Vibrionales;Vibrionaceae;Vibrio;Vibrio cholerae;Vibrio cholerae BX 330286 8' in out

0 commit comments

Comments
 (0)