Module EDManagerTest
[hide private]
[frames] | no frames]

Source Code for Module EDManagerTest

  1  #coding: utf8 
  2  # 
  3  #    Project: The EDNA Kernel 
  4  #             http://www.edna-site.org 
  5  # 
  6  #    File: "$Id$" 
  7  # 
  8  #    Copyright (C) 2008-2009 European Synchrotron Radiation Facility 
  9  #                            Grenoble, France 
 10  # 
 11  #    Principal authors: Olof Svensson (svensson@esrf.fr) 
 12  #                       Jérôme Kieffer (kieffer@esrf.fr) 
 13  # 
 14  #    This program is free software: you can redistribute it and/or modify 
 15  #    it under the terms of the GNU Lesser General Public License as published 
 16  #    by the Free Software Foundation, either version 3 of the License, or 
 17  #    (at your option) any later version. 
 18  # 
 19  #    This program is distributed in the hope that it will be useful, 
 20  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
 21  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 22  #    GNU Lesser General Public License for more details. 
 23  # 
 24  #    You should have received a copy of the GNU General Public License 
 25  #    and the GNU Lesser General Public License  along with this program.   
 26  #    If not, see <http://www.gnu.org/licenses/>. 
 27  # 
 28   
 29  # 
 30  # This class has been inspired by the corresponding AALib class  
 31  # (20090518-PyAALib-JyAALib-111) and modified according to the needs  
 32  # for the EDNA project. 
 33  # 
 34   
 35  from __future__ import with_statement 
 36   
 37  __authors__ = [ "Olof Svensson, Jerome Kieffer" ] 
 38  __contact__ = "svensson@esrf.eu" 
 39  __license__ = "LGPLv3+" 
 40  __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" 
 41  __date__ = "20120216" 
 42  __doc__ = """ 
 43   EDManagerTest stores all information comming from tests  
 44   Static class for storing all test information / results. 
 45  """ 
 46   
 47  import time 
 48   
 49  from EDVerbose          import EDVerbose 
 50  from EDObject           import EDObject 
51 52 53 54 -class EDManagerTest(EDObject):
55 """ 56 Static class for storing all test information / results. 57 """ 58 __listTest = [] 59 __listTestTotal = [] 60 __semaphore = EDObject() 61 __edTestRunning = None 62 __iCumulativeTotalTest = 0 63 __iCumulativeTotalTestMethod = 0 64 __iCumulativeTotalTestSuccess = 0 65 __iCumulativeTotalTestFailure = 0 66 __pyStrReport = None 67 68 69 @classmethod
70 - def synchronizeOn(cls):
71 """ 72 Locks the EDManagerTest class 73 """ 74 cls.__semaphore.synchronizeOn()
75 76 77 @classmethod
78 - def synchronizeOff(cls):
79 """ 80 Unlocks the EDManagerTest class 81 """ 82 cls.__semaphore.synchronizeOff()
83 84 85 @classmethod
86 - def create(cls):
87 """ 88 Create 89 """ 90 cls.__iCumulativeTotalTest += cls.getNumberTest() 91 cls.__iCumulativeTotalTestMethod += cls.getNumberTestMethod() 92 cls.__iCumulativeTotalTestSuccess += cls.getNumberTestSuccess() 93 cls.__iCumulativeTotalTestFailure += cls.getNumberTestFailure() 94 with cls.__semaphore: 95 for edTest in cls.__listTest: 96 cls.__listTestTotal.append(edTest) 97 del cls.__listTest 98 cls.__listTest = []
99 100 101 @classmethod
102 - def outputScreen(cls):
103 with cls.__semaphore: 104 strMessage = "" 105 strMessage += "\n ===============================================================================\n" 106 strMessage += " Final Report\n" 107 strMessage += " Date: %s\n" % time.strftime("%Y/%m/%d-%H:%M:%S", time.localtime()) 108 strMessage += " Total Cumulated Tests: [ %d ]\n" % cls.__iCumulativeTotalTest 109 strMessage += " Total Cumulated Test SUCCESS: [ %d ]\n" % cls.__iCumulativeTotalTestSuccess 110 strMessage += " Total Cumulated Test FAILLURE: [ %d ]\n" % cls.__iCumulativeTotalTestFailure 111 strMessage += " Total Cumulated Test Methods: [ %d ]\n" % cls.__iCumulativeTotalTestMethod 112 strMessage += " -------------------------------------------------------------------------------\n" 113 strFailedTests = "" 114 for edTest in cls.__listTestTotal: 115 strMessage += edTest.outputString() 116 if (not edTest.isSuccess()): 117 strFailedTests += edTest.outputString() 118 strMessage += "\n ===============================================================================\n" 119 if (strFailedTests != ""): 120 strMessage += " Failed tests:\n" 121 strMessage += strFailedTests 122 cls.__pyStrReport = strMessage 123 EDVerbose.screen(cls.__pyStrReport) 124 cls.synchronizeOff()
125 126 127 @classmethod
128 - def getNumberTestCumulative(cls):
129 return cls.__iCumulativeTotalTest
130 131 132 @classmethod 135 136 137 @classmethod 140 141 142 @classmethod 145 146 147 @classmethod
148 - def addInformationTest(cls, _edInformationTest):
149 with cls.__semaphore: 150 cls.__edTestRunning = _edInformationTest 151 cls.__listTest.append(_edInformationTest)
152 153 154 @classmethod
155 - def addInformationTestMethod(cls, _edInformationTest):
156 with cls.__semaphore: 157 if (cls.__edTestRunning is not None): 158 cls.__edTestRunning.addInformationTest(_edInformationTest)
159 160 161 @classmethod
162 - def getNumberTest(cls):
163 with cls.__semaphore: 164 iNumberTestTotal = len(cls.__listTest) 165 return iNumberTestTotal
166 167 168 @classmethod
169 - def getNumberTestMethod(cls):
170 with cls.__semaphore: 171 iNumberTestTotal = 0 172 for edTest in cls.__listTest: 173 iNumberTestTotal += edTest.getNumberTestMethod() 174 return iNumberTestTotal
175 176 177 @classmethod
178 - def getNumberTestSuccess(cls):
179 with cls.__semaphore: 180 iNumberTestTotal = 0 181 for edTest in cls.__listTest: 182 if (edTest.isSuccess()): 183 iNumberTestTotal += 1 184 return iNumberTestTotal
185 186 187 @classmethod
188 - def getNumberTestFailure(cls):
189 with cls.__semaphore: 190 iNumberTestTotal = 0 191 for edTest in cls.__listTest: 192 if (not edTest.isSuccess()): 193 iNumberTestTotal += 1 194 return iNumberTestTotal
195