comparison tests/run-tests.py @ 9:6cc488e11544 draft

"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
author nick
date Tue, 31 Mar 2020 05:09:12 -0400
parents 411adeff1eec
children
comparison
equal deleted inserted replaced
8:411adeff1eec 9:6cc488e11544
1 #!/usr/bin/env python 1 #!/usr/bin/env python3
2 import os 2 import os
3 import sys 3 import sys
4 import subprocess 4 import subprocess
5 5
6 SCRIPT_NAME = 'allele-counts.py' 6 SCRIPT_NAME = 'allele-counts.py'
56 test_dir = os.path.dirname(os.path.realpath(__file__)) 56 test_dir = os.path.dirname(os.path.realpath(__file__))
57 script_dir = os.path.relpath(os.path.dirname(test_dir)) 57 script_dir = os.path.relpath(os.path.dirname(test_dir))
58 test_dir = os.path.relpath(test_dir) 58 test_dir = os.path.relpath(test_dir)
59 59
60 if do_print_xml: 60 if do_print_xml:
61 print XML.get('tests_start') 61 print(XML.get('tests_start'))
62 62
63 for dataset in DATASETS: 63 for dataset in DATASETS:
64 infile = os.path.join(test_dir, dataset+IN_EXT) 64 infile = os.path.join(test_dir, dataset+IN_EXT)
65 outfile = os.path.join(test_dir, dataset+OUT_EXT) 65 outfile = os.path.join(test_dir, dataset+OUT_EXT)
66 66
76 print_xml(infile, outfile, options, XML, PARAMS, PARAM_ARG) 76 print_xml(infile, outfile, options, XML, PARAMS, PARAM_ARG)
77 else: 77 else:
78 run_tests(infile, outfile, options, script_dir) 78 run_tests(infile, outfile, options, script_dir)
79 79
80 if do_print_xml: 80 if do_print_xml:
81 print XML.get('tests_end') 81 print(XML.get('tests_end'))
82 82
83 83
84 def run_tests(infile, outfile, options, script_dir): 84 def run_tests(infile, outfile, options, script_dir):
85 script_cmd = os.path.join(script_dir, SCRIPT_NAME)+' '+options+' -i '+infile 85 script_cmd = os.path.join(script_dir, SCRIPT_NAME)+' '+options+' -i '+infile
86 bash_cmd = 'diff '+outfile+' <('+script_cmd+')' 86 bash_cmd = 'diff '+outfile+' <('+script_cmd+')'
87 print script_cmd 87 print(script_cmd)
88 subprocess.call(['bash', '-c', bash_cmd]) 88 subprocess.call(['bash', '-c', bash_cmd])
89 89
90 90
91 def print_xml(infile, outfile, options_str, xml, params, param_arg): 91 def print_xml(infile, outfile, options_str, xml, params, param_arg):
92 infile = os.path.basename(infile) 92 infile = os.path.basename(infile)
93 outfile = os.path.basename(outfile) 93 outfile = os.path.basename(outfile)
94 94
95 options = options_str.split() # on whitespace 95 options = options_str.split() # on whitespace
96 96
97 print xml.get('test_start') 97 print(xml.get('test_start'))
98 print xml.get('input') % infile 98 print(xml.get('input') % infile)
99 99
100 # read in options one at a time, print <param> line 100 # read in options one at a time, print <param> line
101 i = 0 101 i = 0
102 while i < len(options): 102 while i < len(options):
103 opt = options[i] 103 opt = options[i]
104 if not params.has_key(opt) or not param_arg.has_key(opt): 104 if opt not in params or opt not in param_arg:
105 sys.stderr.write("Error: unknown option '"+opt+"' in ARGS list in file " 105 sys.stderr.write("Error: unknown option '"+opt+"' in ARGS list in file "+infile+"\n")
106 +infile+"\n")
107 sys.exit(1) 106 sys.exit(1)
108 # takes argument 107 # takes argument
109 if param_arg[opt]: 108 if param_arg[opt]:
110 i+=1 109 i+=1
111 arg = options[i] 110 arg = options[i]
112 print xml.get('param') % (params[opt], arg) 111 print(xml.get('param') % (params[opt], arg))
113 # no argument (boolean) 112 # no argument (boolean)
114 else: 113 else:
115 print xml.get('param') % (params[opt], 'true') 114 print(xml.get('param') % (params[opt], 'true'))
116 i+=1 115 i+=1
117 116
118 print xml.get('output') % outfile 117 print(xml.get('output') % outfile)
119 print xml.get('test_end') 118 print(xml.get('test_end'))
120 119
121 120
122 def read_options(infile): 121 def read_options(infile):
123 with open(infile, 'r') as infilehandle: 122 with open(infile, 'r') as infilehandle:
124 for line in infilehandle: 123 for line in infilehandle: