Cleanups: dead code removal/etc.
[greylag.git] / test / small_run_test.py
blobc194a731ca02ac4b056b1930ae3fa4e02f8e66da
1 '''small run test cases'''
4 from __future__ import with_statement
6 import contextlib
7 import filecmp
8 import inspect
9 import subprocess
11 from nose.tools import *
13 from greylag_grind import *
16 # parallel job processes
17 CPUS = 4
19 # program locations
20 GREYLAG_PROGRAM = '../greylag_grind.py'
21 GREYLAGMP_PROGRAM = '../greylag.py'
23 # temporary output file
24 GREYLAG_OUTPUT = 'tmp-greylag-out.xml'
26 # cd to the test directory, but restore when we're done
27 SAVE_CWD = os.getcwd()
28 def setup(self):
29 if os.path.exists(GREYLAG_OUTPUT):
30 os.remove(GREYLAG_OUTPUT)
31 os.chdir('test')
32 def teardown(self):
33 if os.path.exists(GREYLAG_OUTPUT):
34 os.remove(GREYLAG_OUTPUT)
35 os.chdir(SAVE_CWD)
38 def run_gl(args):
39 "Run greylag in a subprocess, checking for error return."
40 subprocess.check_call(("%s -q -o %s %s"
41 % (GREYLAG_PROGRAM, GREYLAG_OUTPUT, args)).split())
43 def run_gl_mp(args):
44 "Run greylag in multiple subprocesses, checking for error return."
45 subprocess.check_call(("%s %s -q -o %s %s"
46 % (GREYLAGMP_PROGRAM, CPUS, GREYLAG_OUTPUT,
47 args)).split())
49 def run_combination(combination=None):
50 """Run a greylag test, as specified by combination.
52 If combination is not given, it defaults to the name of the calling
53 function.
55 For a combination 'greylag_params_0__test_2_test', greylag will be run
56 with a parameter file 'greylag-params-0.xml' and spectrum file
57 'test-2.ms2'. (Additional spectrum files can be specified, separated by
58 '__'.) The results will be compared to 'greylag-params-0--test-2-ok.xml'.
59 If this baseline file is not present and the environment variable
60 NOSEUPDATE is set, a new baseline will be created.
62 Normally the test will only be done using greylag-mp.py, to speed things
63 up. If single_cpu is True, a single greylag.py process is used. The
64 results should be identical.
65 """
66 if combination == None:
67 # name of caller
68 combination = inspect.getouterframes(inspect.currentframe())[1][3]
69 assert combination.endswith('_test')
70 combination = combination.rpartition('_test')[0]
71 run = run_gl
72 if combination.endswith('_mp'):
73 run = run_gl_mp
74 combination = combination.rpartition('_mp')[0]
75 parts = combination.split('__')
76 params, spectra = parts[0], parts[1:]
77 assert len(spectra) >= 1
78 params = params.replace('_', '-') + '.xml'
79 spectra = [ sp.replace('_', '-') + '.ms2' for sp in spectra ]
80 ok_fn = combination.replace('_', '-') + '-ok.xml'
81 assert os.path.exists(ok_fn) or 'NOSEUPDATE' in os.environ, 'no baseline'
83 run(params + ' ' + ' '.join(spectra))
84 if os.path.exists(ok_fn):
85 assert filecmp.cmp(GREYLAG_OUTPUT, ok_fn), 'output differs'
86 else:
87 os.rename(GREYLAG_OUTPUT, ok_fn)
88 # also do it for --quirks?
91 # Could do xtandem and rough compare to quirks? Is this worth doing, since we
92 # can expect at least small differences? Probably we should have a separate
93 # framework for comparing and contrasting output from any two of { greylag,
94 # xtandem, sequest }
98 class modless_run_tests:
99 def greylag_params_0__test_2_test(self):
100 run_combination()
101 def greylag_params_0__test_2_mp_test(self):
102 run_combination()
103 def greylag_params_0__6323840_test(self):
104 run_combination()
105 def greylag_params_0__6323840_mp_test(self):
106 run_combination()
108 def greylag_params_yeast_0__test_2_test(self):
109 run_combination()
110 def greylag_params_yeast_0__test_2_mp_test(self):
111 run_combination()