11 ''' Use this decorator (@wvtest) in front of any function you want to run
12 as part of the unit test suite. Then run:
13 python wvtestmain.py path/to/yourtest.py
14 to run all the @wvtest functions in that file.
16 _registered.append(func)
19 def _result(msg, tb, code):
24 (filename, line, func, text) = tb
25 filename = os.path.basename(filename)
26 msg = re.sub(r'\s+', ' ', str(msg))
28 print '! %-70s %s' % ('%s:%-4d %s' % (filename, line, msg),
33 def _check(cond, msg = 'unknown', tb = None):
34 if tb == None: tb = traceback.extract_stack()[-3]
36 _result(msg, tb, 'ok')
38 _result(msg, tb, 'FAILED')
42 (filename, line, func, text) = traceback.extract_stack()[-3]
43 text = re.sub(r'^\w+\((.*)\)$', r'\1', text);
46 def WVPASS(cond = True):
47 ''' Throws an exception unless cond is true. '''
48 return _check(cond, _code())
50 def WVFAIL(cond = True):
51 ''' Throws an exception unless cond is false. '''
52 return _check(not cond, 'NOT(%s)' % _code())
55 ''' Throws an exception unless a == b. '''
56 return _check(a == b, '%s == %s' % (repr(a), repr(b)))
59 ''' Throws an exception unless a != b. '''
60 return _check(a != b, '%s != %s' % (repr(a), repr(b)))
63 ''' Throws an exception unless a < b. '''
64 return _check(a < b, '%s < %s' % (repr(a), repr(b)))
67 ''' Throws an exception unless a <= b. '''
68 return _check(a <= b, '%s <= %s' % (repr(a), repr(b)))
71 ''' Throws an exception unless a > b. '''
72 return _check(a > b, '%s > %s' % (repr(a), repr(b)))
75 ''' Throws an exception unless a >= b. '''
76 return _check(a >= b, '%s >= %s' % (repr(a), repr(b)))