Package pypower :: Package t :: Module t_ok
[hide private]
[frames] | no frames]

Source Code for Module pypower.t.t_ok

 1  # Copyright (C) 2004-2011 Power System Engineering Research Center (PSERC) 
 2  # Copyright (C) 2011 Richard Lincoln 
 3  # 
 4  # PYPOWER is free software: you can redistribute it and/or modify 
 5  # it under the terms of the GNU General Public License as published 
 6  # by the Free Software Foundation, either version 3 of the License, 
 7  # or (at your option) any later version. 
 8  # 
 9  # PYPOWER is distributed in the hope that it will be useful, 
10  # but WITHOUT ANY WARRANTY], without even the implied warranty of 
11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
12  # GNU General Public License for more details. 
13  # 
14  # You should have received a copy of the GNU General Public License 
15  # along with PYPOWER. If not, see <http://www.gnu.org/licenses/>. 
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