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

Source Code for Module pypower.t.t_end

 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  """Finish running tests and print statistics. 
18  """ 
19   
20  import sys 
21   
22  from time import time 
23   
24  from pypower.t.t_globals import TestGlobals 
25   
26   
27 -def t_end():
28 """Finish running tests and print statistics. 29 30 Checks the global counters that were updated by calls to C{t_ok} 31 and C{t_is} and prints out a summary of the test results. 32 33 @author: Ray Zimmerman (PSERC Cornell) 34 @author: Richard Lincoln 35 """ 36 TestGlobals.t_counter -= 1 37 38 if (TestGlobals.t_counter == TestGlobals.t_num_of_tests) and \ 39 (TestGlobals.t_counter == TestGlobals.t_ok_cnt + TestGlobals.t_skip_cnt) and \ 40 (TestGlobals.t_not_ok_cnt == 0): 41 all_ok = True 42 else: 43 all_ok = False 44 45 s = '' 46 if TestGlobals.t_quiet: 47 if all_ok: 48 s += 'ok' 49 if TestGlobals.t_skip_cnt: 50 s += ' (%d of %d skipped)' % \ 51 (TestGlobals.t_skip_cnt, TestGlobals.t_num_of_tests) 52 else: 53 s += 'not ok\n' 54 s += '\t##### Ran %d of %d tests: %d passed, %d failed' % \ 55 (TestGlobals.t_counter, TestGlobals.t_num_of_tests, 56 TestGlobals.t_ok_cnt, TestGlobals.t_not_ok_cnt) 57 if TestGlobals.t_skip_cnt: 58 s += ', %d skipped' % TestGlobals.t_skip_cnt 59 s += '\n' 60 else: 61 if all_ok: 62 if TestGlobals.t_skip_cnt: 63 s += 'All tests successful (%d passed, %d skipped of %d)' % \ 64 (TestGlobals.t_ok_cnt, TestGlobals.t_skip_cnt, 65 TestGlobals.t_num_of_tests) 66 else: 67 s += 'All tests successful (%d of %d)' % \ 68 (TestGlobals.t_ok_cnt, TestGlobals.t_num_of_tests) 69 else: 70 s += 'Ran %d of %d tests: %d passed, %d failed' % \ 71 (TestGlobals.t_counter, TestGlobals.t_num_of_tests, 72 TestGlobals.t_ok_cnt, TestGlobals.t_not_ok_cnt) 73 if TestGlobals.t_skip_cnt: 74 s += ', %d skipped' % TestGlobals.t_skip_cnt 75 s += '\nElapsed time %.2f seconds.\n' % (time() - TestGlobals.t_clock) 76 77 sys.stdout.write(s)
78