test: Implement combination test framework
[greylag.git] / test / small_run_test.py
blob16a68ab942bd283b627c78c9f2f7240dc309cb2a
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 import *
15 # program and initial args required to run from test directory
16 GREYLAG_PROGRAM = 'python2.5 ../greylag.py'
18 # temporary output file
19 GREYLAG_OUTPUT = 'tmp-greylag-out.xml'
21 # cd to the test directory, but restore when we're done
22 SAVE_CWD = os.getcwd()
23 def setup(self):
24 if os.path.exists(GREYLAG_OUTPUT):
25 os.remove(GREYLAG_OUTPUT)
26 os.chdir('test')
27 def teardown(self):
28 if os.path.exists(GREYLAG_OUTPUT):
29 os.remove(GREYLAG_OUTPUT)
30 os.chdir(SAVE_CWD)
33 def run_gl(args):
34 "Run greylag in a subprocess, checking for error return."
35 subprocess.check_call(("%s -q -o %s %s"
36 % (GREYLAG_PROGRAM, GREYLAG_OUTPUT, args)).split())
38 def run_combination(combination=None):
39 """Run a greylag test, as specified by combination.
41 If combination is not given, it defaults to the name of the calling
42 function.
44 For a combination 'greylag_params_0__test_2_test', greylag will be run
45 with a parameter file 'greylag-params-0.xml' and spectrum file
46 'test-2.ms2'. (Additional spectrum files can be specified, separated by
47 '__'.) The results will be compared to 'greylag-params-0--test-2-ok.xml'.
48 If this baseline file is not present and the environment variable
49 NOSEUPDATE is set, a new baseline will be created.
50 """
51 if combination == None:
52 # name of caller
53 combination = inspect.getouterframes(inspect.currentframe())[1][3]
54 assert combination.endswith('_test')
55 combination = combination.rpartition('_test')[0]
56 parts = combination.split('__')
57 params, spectra = parts[0], parts[1:]
58 assert len(spectra) >= 1
59 params = params.replace('_', '-') + '.xml'
60 spectra = [ sp.replace('_', '-') + '.ms2' for sp in spectra ]
61 correct_fn = combination.replace('_', '-') + '-ok.xml'
62 assert os.path.exists(correct_fn) or 'NOSEUPDATE' in os.environ, 'no baseline'
63 run_gl(params + ' ' + ' '.join(spectra))
64 if os.path.exists(correct_fn):
65 assert filecmp.cmp(GREYLAG_OUTPUT, correct_fn), 'output differs'
66 else:
67 os.rename(GREYLAG_OUTPUT, correct_fn)
68 # FIX: now do it in parts, and compare that result
69 # also do it for --quirks?
71 # Could do xtandem and rough compare to quirks? Is this worth doing, since we
72 # can expect at least small differences? Probably we should have a separate
73 # framework for comparing and contrasting output from any two of { greylag,
74 # xtandem, sequest }
78 class modless_run_tests:
79 def greylag_params_0__test_2_test(self):
80 run_combination()
81 def greylag_params_0__6323840_test(self):
82 run_combination()