11#!/usr/bin/env python
22from __future__ import print_function
33
4- import pytest
5-
4+ import sys
5+ import os
6+ from os .path import dirname , abspath
67from subprocess import Popen , PIPE
78import subprocess
8- import sys , os
9- from os .path import dirname , abspath
9+ import pytest
1010
1111DATADIR = 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
8889def 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
9495def 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
100101def 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
104105def 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
109110def 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
114115def 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
118119def test_annotation ():
119120 stat , out , err = runme ('annotation_table.py' )
@@ -124,97 +125,96 @@ def test_abundance():
124125 assert b'Archaea' in out
125126
126127def 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
131131def 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+
135135def 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
143143def 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
148148def 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
153153def 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
160160def 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
165165def 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
170170def 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
175175def 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
179179def 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
184184def 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
201201def 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
206206def 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
212212def 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
216216def 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