Mercurial > repos > nick > allele_counts_1
diff tests/run-tests.py @ 17:44c3abd1b767 draft
"planemo upload for repository https://github.com/galaxyproject/dunovo commit 5a2e08bc1213b0437d0adcb45f7f431bd3c735f4"
author | nick |
---|---|
date | Tue, 31 Mar 2020 09:00:51 +0000 |
parents | 97b772e3a0f1 |
children |
line wrap: on
line diff
--- a/tests/run-tests.py Wed Dec 09 11:31:13 2015 -0500 +++ b/tests/run-tests.py Tue Mar 31 09:00:51 2020 +0000 @@ -1,8 +1,9 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import sys import subprocess +SCRIPT_NAME = 'allele-counts.py' DATASETS = [ 'artificial', 'artificial-samples', @@ -16,15 +17,52 @@ OUT_EXT = '.csv.out' ARGS_KEY = '##comment="ARGS=' +XML = { + 'tests_start':' <tests>', + 'test_start': ' <test>', + 'input': ' <param name="input" value="tests/%s" />', + 'param': ' <param name="%s" value="%s" />', + 'output': ' <output name="output" file="tests/%s" />', + 'test_end': ' </test>', + 'tests_end': ' </tests>', +} +PARAMS = { + '-f':'freq', + '-c':'covg', + '-H':'header', + '-s':'stranded', + '-n':'nofilt', + '-r':'seed', +} +PARAM_ARG = { + '-f':True, + '-c':True, + '-H':False, + '-s':False, + '-n':False, + '-r':True, +} + def main(): - test_dir = os.path.dirname(os.path.relpath(sys.argv[0])) - if test_dir: - test_dir += os.sep + do_print_xml = False + if len(sys.argv) > 1: + if sys.argv[1] == '-x': + do_print_xml = True + else: + sys.stderr.write("Error: unrecognized option '"+sys.argv[1]+"'\n") + sys.exit(1) + + test_dir = os.path.dirname(os.path.realpath(__file__)) + script_dir = os.path.relpath(os.path.dirname(test_dir)) + test_dir = os.path.relpath(test_dir) + + if do_print_xml: + print(XML.get('tests_start')) for dataset in DATASETS: - infile = test_dir+dataset+IN_EXT - outfile = test_dir+dataset+OUT_EXT + infile = os.path.join(test_dir, dataset+IN_EXT) + outfile = os.path.join(test_dir, dataset+OUT_EXT) if not os.path.exists(infile): sys.stderr.write("Error: file not found: "+infile+"\n") @@ -34,11 +72,50 @@ continue options = read_options(infile) - script_cmd = 'allele-counts.py '+options+' -i '+infile - bash_cmd = 'diff '+outfile+' <('+script_cmd+')' - # print infile+":" - print script_cmd - subprocess.call(['bash', '-c', bash_cmd]) + if do_print_xml: + print_xml(infile, outfile, options, XML, PARAMS, PARAM_ARG) + else: + run_tests(infile, outfile, options, script_dir) + + if do_print_xml: + print(XML.get('tests_end')) + + +def run_tests(infile, outfile, options, script_dir): + script_cmd = os.path.join(script_dir, SCRIPT_NAME)+' '+options+' -i '+infile + bash_cmd = 'diff '+outfile+' <('+script_cmd+')' + print(script_cmd) + subprocess.call(['bash', '-c', bash_cmd]) + + +def print_xml(infile, outfile, options_str, xml, params, param_arg): + infile = os.path.basename(infile) + outfile = os.path.basename(outfile) + + options = options_str.split() # on whitespace + + print(xml.get('test_start')) + print(xml.get('input') % infile) + + # read in options one at a time, print <param> line + i = 0 + while i < len(options): + opt = options[i] + if opt not in params or opt not in param_arg: + sys.stderr.write("Error: unknown option '"+opt+"' in ARGS list in file "+infile+"\n") + sys.exit(1) + # takes argument + if param_arg[opt]: + i+=1 + arg = options[i] + print(xml.get('param') % (params[opt], arg)) + # no argument (boolean) + else: + print(xml.get('param') % (params[opt], 'true')) + i+=1 + + print(xml.get('output') % outfile) + print(xml.get('test_end')) def read_options(infile):