3 # Copyright (C)2009 EQL Data Inc. and contributors.
4 # Licensed under the GNU Library General Public License, version 2.
5 # See the included file named LICENSE for license information.
17 ''' Use this decorator (@wvtest) in front of any function you want to run
18 as part of the unit test suite. Then run:
19 python wvtestmain.py path/to/yourtest.py
20 to run all the @wvtest functions in that file.
22 _registered.append(func)
25 def _result(msg, tb, code):
30 (filename, line, func, text) = tb
31 filename = os.path.basename(filename)
32 msg = re.sub(r'\s+', ' ', str(msg))
34 print '! %-70s %s' % ('%s:%-4d %s' % (filename, line, msg),
39 def _check(cond, msg = 'unknown', tb = None):
40 if tb == None: tb = traceback.extract_stack()[-3]
42 _result(msg, tb, 'ok')
44 _result(msg, tb, 'FAILED')
48 (filename, line, func, text) = traceback.extract_stack()[-3]
49 text = re.sub(r'^\w+\((.*)\)$', r'\1', text);
52 def WVPASS(cond = True):
53 ''' Throws an exception unless cond is true. '''
54 return _check(cond, _code())
56 def WVFAIL(cond = True):
57 ''' Throws an exception unless cond is false. '''
58 return _check(not cond, 'NOT(%s)' % _code())
61 ''' Throws an exception unless a == b. '''
62 return _check(a == b, '%s == %s' % (repr(a), repr(b)))
65 ''' Throws an exception unless a != b. '''
66 return _check(a != b, '%s != %s' % (repr(a), repr(b)))
69 ''' Throws an exception unless a < b. '''
70 return _check(a < b, '%s < %s' % (repr(a), repr(b)))
73 ''' Throws an exception unless a <= b. '''
74 return _check(a <= b, '%s <= %s' % (repr(a), repr(b)))
77 ''' Throws an exception unless a > b. '''
78 return _check(a > b, '%s > %s' % (repr(a), repr(b)))
81 ''' Throws an exception unless a >= b. '''
82 return _check(a >= b, '%s >= %s' % (repr(a), repr(b)))