forked from caporaso-lab-graveyard/qiime_test_data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_usage_tests.py
executable file
·95 lines (80 loc) · 3.88 KB
/
script_usage_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
# File created on 15 Mar 2012
from __future__ import division
__author__ = "Greg Caporaso"
__copyright__ = "Copyright 2011, The QIIME project"
__credits__ = ["Greg Caporaso", "Jai Ram Rideout"]
__license__ = "GPL"
__version__ = "1.4.0-dev"
__maintainer__ = "Greg Caporaso"
__email__ = "[email protected]"
__status__ = "Development"
from qiime.util import (parse_command_line_parameters,
make_option, load_qiime_config, get_qiime_temp_dir)
from qiime.test import run_script_usage_tests
from qiime.workflow import generate_log_fp
from os.path import join
qiime_config = load_qiime_config()
script_info = {}
script_info['brief_description'] = ""
script_info['script_description'] = ""
script_info['script_usage'] = []
script_info['script_usage'].append(("Run a subset of the interface tests in verbose mode","Run interface tests for the add_taxa.py and make_otu_table.py scripts. This illustrates how to run from the qiime_test_dir directory.","%prog -i $PWD/ -l $HOME/qime_script_tests.log -t add_taxa,make_otu_table -v"))
script_info['script_usage'].append(("Run all of the interface tests","Run all script interface tests. This illustrates how to run from the qiime_test_dir directory.","%prog -i $PWD/ -l $HOME/all_qime_script_tests.log"))
script_info['output_description']= ""
script_info['required_options'] = []
log_fp_prefix = 'script_test_log'
log_fp_suffix = 'txt'
default_log_fp = generate_log_fp(get_qiime_temp_dir(),
basefile_name=log_fp_prefix,
suffix=log_fp_suffix,
timestamp_pattern='%Y%m%d%H%M%S')
default_log_fp_help_str = join(get_qiime_temp_dir(),
'%s_TIMESTAMP.%s' % (log_fp_prefix,log_fp_suffix))
script_info['optional_options'] = [\
make_option('-t','--tests',
help='comma-separated list of the tests to run [default: all]'),
make_option('-w','--working_dir',default=get_qiime_temp_dir(),
help='directory where the tests should be run [default: %default]',
type='existing_dirpath'),
make_option('-q','--qiime_scripts_dir',default=qiime_config['qiime_scripts_dir'],
help='directory containing scripts to test [default: %default]',
type='existing_dirpath'),
make_option('-l','--failure_log_fp',type="new_filepath",default=default_log_fp,
help='log file to store record of failures [default: %s]' % default_log_fp_help_str)
]
script_info['version'] = __version__
default_qiime_test_data_dir = qiime_config['qiime_test_data_dir']
if default_qiime_test_data_dir != None:
script_info['optional_options'].append(
make_option('-i','--qiime_test_data_dir',type="existing_dirpath",
default=default_qiime_test_data_dir,
help='the directory containing input for script usage'+\
' examples [default: %default]'))
else:
script_info['required_options'].append(
make_option('-i','--qiime_test_data_dir',type="existing_dirpath",
help='the directory containing input for script usage examples'))
script_info['help_on_no_arguments'] = False
def main():
option_parser, opts, args =\
parse_command_line_parameters(**script_info)
qiime_test_data_dir = opts.qiime_test_data_dir
qiime_scripts_dir = opts.qiime_scripts_dir
working_dir = opts.working_dir
verbose = opts.verbose
tests = opts.tests
if tests != None:
tests = tests.split(',')
failure_log_fp = opts.failure_log_fp
result_summary, num_failures = run_script_usage_tests(
qiime_test_data_dir,
qiime_scripts_dir,
working_dir,
verbose=verbose,
tests=tests,
failure_log_fp=failure_log_fp)
if verbose:
print result_summary
if __name__ == "__main__":
main()