1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """Tests if a condition is true.
18 """
19
20 from pypower.t.t_globals import TestGlobals
21
22
23 -def t_ok(cond, msg=''):
24 """Tests if a condition is true.
25
26 Increments the global test count and if the C{expr}
27 is true it increments the passed tests count, otherwise increments
28 the failed tests count. Prints 'ok' or 'not ok' followed by the
29 C{msg}, unless the global variable t_quiet is true. Intended to be
30 called between calls to C{t_begin} and C{t_end}.
31
32 @author: Ray Zimmerman (PSERC Cornell)
33 @author: Richard Lincoln
34 """
35 if msg:
36 if isinstance(msg, list):
37 msg = "".join(msg)
38 msg = ' - ' + msg
39
40 s = ''
41 if cond:
42 TestGlobals.t_ok_cnt += 1
43 else:
44 TestGlobals.t_not_ok_cnt += 1
45 if not TestGlobals.t_quiet:
46 s += 'not '
47
48 if not TestGlobals.t_quiet:
49 s += 'ok %3d%s' % (TestGlobals.t_counter, msg)
50 print s
51
52 TestGlobals.t_counter += 1
53