Mercurial > repos > nick > allele_counts_1
comparison tests/run-tests.py @ 11:566e42c97532
Uploaded tarball.
Testing automated tests.
author | nick |
---|---|
date | Tue, 10 Sep 2013 13:00:28 -0400 |
parents | db6f217dc45a |
children | 97b772e3a0f1 |
comparison
equal
deleted
inserted
replaced
10:db6f217dc45a | 11:566e42c97532 |
---|---|
14 ] | 14 ] |
15 IN_EXT = '.vcf.in' | 15 IN_EXT = '.vcf.in' |
16 OUT_EXT = '.csv.out' | 16 OUT_EXT = '.csv.out' |
17 ARGS_KEY = '##comment="ARGS=' | 17 ARGS_KEY = '##comment="ARGS=' |
18 | 18 |
19 XML = { | |
20 'tests_start':' <tests>', | |
21 'test_start': ' <test>', | |
22 'input': ' <param name="input" value="tests/%s" />', | |
23 'param': ' <param name="%s" value="%s" />', | |
24 'output': ' <output name="output" file="tests/%s" />', | |
25 'test_end': ' </test>', | |
26 'tests_end': ' </tests>', | |
27 } | |
28 PARAMS = { | |
29 '-f':'freq', | |
30 '-c':'covg', | |
31 '-H':'header', | |
32 '-s':'stranded', | |
33 '-n':'nofilt', | |
34 '-r':'seed', | |
35 } | |
36 PARAM_ARG = { | |
37 '-f':True, | |
38 '-c':True, | |
39 '-H':False, | |
40 '-s':False, | |
41 '-n':False, | |
42 '-r':True, | |
43 } | |
44 | |
19 def main(): | 45 def main(): |
46 | |
47 do_print_xml = False | |
48 if len(sys.argv) > 1: | |
49 if sys.argv[1] == '-x': | |
50 do_print_xml = True | |
51 else: | |
52 sys.stderr.write("Error: unrecognized option '"+sys.argv[1]+"'\n") | |
53 sys.exit(1) | |
20 | 54 |
21 test_dir = os.path.dirname(os.path.relpath(sys.argv[0])) | 55 test_dir = os.path.dirname(os.path.relpath(sys.argv[0])) |
22 if test_dir: | 56 if test_dir: |
23 test_dir += os.sep | 57 test_dir += os.sep |
58 | |
59 if do_print_xml: | |
60 print XML.get('tests_start') | |
24 | 61 |
25 for dataset in DATASETS: | 62 for dataset in DATASETS: |
26 infile = test_dir+dataset+IN_EXT | 63 infile = test_dir+dataset+IN_EXT |
27 outfile = test_dir+dataset+OUT_EXT | 64 outfile = test_dir+dataset+OUT_EXT |
28 | 65 |
32 if not os.path.exists(outfile): | 69 if not os.path.exists(outfile): |
33 sys.stderr.write("Error: file not found: "+outfile+"\n") | 70 sys.stderr.write("Error: file not found: "+outfile+"\n") |
34 continue | 71 continue |
35 | 72 |
36 options = read_options(infile) | 73 options = read_options(infile) |
37 script_cmd = 'allele-counts.py '+options+' -i '+infile | 74 if do_print_xml: |
38 bash_cmd = 'diff '+outfile+' <('+script_cmd+')' | 75 print_xml(infile, outfile, options, XML, PARAMS, PARAM_ARG) |
39 # print infile+":" | 76 else: |
40 print script_cmd | 77 run_tests(infile, outfile, options) |
41 subprocess.call(['bash', '-c', bash_cmd]) | 78 |
79 if do_print_xml: | |
80 print XML.get('tests_end') | |
81 | |
82 | |
83 def run_tests(infile, outfile, options): | |
84 script_cmd = 'allele-counts.py '+options+' -i '+infile | |
85 bash_cmd = 'diff '+outfile+' <('+script_cmd+')' | |
86 print script_cmd | |
87 subprocess.call(['bash', '-c', bash_cmd]) | |
88 | |
89 | |
90 def print_xml(infile, outfile, options_str, xml, params, param_arg): | |
91 infile = os.path.basename(infile) | |
92 outfile = os.path.basename(outfile) | |
93 | |
94 options = options_str.split() # on whitespace | |
95 | |
96 print xml.get('test_start') | |
97 print xml.get('input') % infile | |
98 | |
99 i = 0 | |
100 while i < len(options): | |
101 opt = options[i] | |
102 if not params.has_key(opt) or not param_arg.has_key(opt): | |
103 sys.stderr.write("Error: unknown option '"+opt+"' in ARGS list in file " | |
104 +infile+"\n") | |
105 sys.exit(1) | |
106 if param_arg[opt]: | |
107 i+=1 | |
108 arg = options[i] | |
109 print xml.get('param') % (params[opt], arg) | |
110 else: | |
111 print xml.get('param') % (params[opt], opt) | |
112 i+=1 | |
113 | |
114 print xml.get('output') % outfile | |
115 print xml.get('test_end') | |
42 | 116 |
43 | 117 |
44 def read_options(infile): | 118 def read_options(infile): |
45 with open(infile, 'r') as infilehandle: | 119 with open(infile, 'r') as infilehandle: |
46 for line in infilehandle: | 120 for line in infilehandle: |