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

Source Code for Module EDTestCase

  1  # coding: utf8 
  2  # 
  3  #    Project: The EDNA Kernel 
  4  #             http://www.edna-site.org 
  5  # 
  6  #    File: "$Id$" 
  7  # 
  8  #    Copyright (C) 2008-2012 European Synchrotron Radiation Facility 
  9  #                            Grenoble, France 
 10  # 
 11  #    Principal authors: Marie-Francoise Incardona (incardon@esrf.fr) 
 12  #                       Olof Svensson (svensson@esrf.fr)  
 13  #                       Jérôme Kieffer (jerome.kieffer@esrf.fr) 
 14  # 
 15  #    This program is free software: you can redistribute it and/or modify 
 16  #    it under the terms of the GNU Lesser General Public License as published 
 17  #    by the Free Software Foundation, either version 3 of the License, or 
 18  #    (at your option) any later version. 
 19  # 
 20  #    This program is distributed in the hope that it will be useful, 
 21  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
 22  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 23  #    GNU Lesser General Public License for more details. 
 24  # 
 25  #    You should have received a copy of the GNU General Public License 
 26  #    and the GNU Lesser General Public License  along with this program.   
 27  #    If not, see <http://www.gnu.org/licenses/>. 
 28  # 
 29  """ 
 30  EDNA test Case module ... 
 31   
 32  a TestCase is a single test, either an unit test or an execution test. 
 33  """ 
 34   
 35  __authors__ = "Marie-Francoise Incardona, Olof Svensson, Jerome Kieffer" 
 36  __contact__ = "svensson@esrf.eu" 
 37  __license__ = "LGPLv3+" 
 38  __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" 
 39  __date__ = "20120216" 
 40   
 41  from EDTest            import EDTest 
 42  from EDVerbose         import EDVerbose 
 43  from EDUtilsTest       import EDUtilsTest 
 44  from EDUtilsPath       import EDUtilsPath 
 45   
 46   
47 -class EDTestCase(EDTest):
48 """ 49 Test case class 50 """ 51
52 - def __init__(self, _strTestName=None):
53 EDTest.__init__(self, _strTestName) 54 self.__strTestSuiteName = None 55 self.__strTestsHome = None 56 self.__strTestsDataHome = None 57 self.__strTestsDataImagesHome = None 58 self.__strReasonForNotBeingExecuted = "" 59 self.__bIsExecuted = False 60 self.__iNumberTestMethodSuccess = 0 61 self.__iNumberTestMethodFailure = 0 62 self.__dictMethodFailureMessages = {}
63 64
65 - def processKernel(self):
66 """ 67 Executes the test case. 68 """ 69 EDVerbose.DEBUG("EDTestCase.processKernel") 70 EDVerbose.screen() 71 EDVerbose.unitTest("===================================================================") 72 if self.getTestSuiteName() is not None: 73 EDVerbose.unitTest("TEST SUITE : %s" % self.getTestSuiteName()) 74 EDVerbose.unitTest("TEST CASE : %s" % self.getClassName()) 75 EDVerbose.unitTest(" ") 76 if self.__strReasonForNotBeingExecuted == "": 77 self.setTimeInit() 78 iNumberMethods = self.getNumberOfTests() 79 EDVerbose.unitTest("Total number of tests : %d" % iNumberMethods) 80 EDVerbose.unitTest() 81 iTestCaseNumber = 0 82 if self.getListTest() == []: 83 self.__strReasonForNotBeingExecuted = "No test methods!" 84 else: 85 for pyTestMethod in self.getListTest(): 86 iTestCaseNumber = iTestCaseNumber + 1 87 strMethodName = EDUtilsTest.patchMethodName(pyTestMethod) 88 EDVerbose.unitTest("-------------------------------------------------------------------") 89 EDVerbose.unitTest("Test case method : %s" % strMethodName) 90 EDVerbose.unitTest() 91 try: 92 pyTestMethod() 93 self.__iNumberTestMethodSuccess += 1 94 EDVerbose.unitTest("%s executed with SUCCESS" % strMethodName) 95 EDVerbose.unitTest() 96 97 except AssertionError, pyException: 98 self.__dictMethodFailureMessages[strMethodName] = str(pyException) 99 self.__iNumberTestMethodFailure += 1 100 EDVerbose.unitTest("Assertion Error Raised!") 101 EDVerbose.unitTest("%s executed with FAILURE" % strMethodName) 102 EDVerbose.unitTest() 103 104 except Exception, pyException: 105 self.__dictMethodFailureMessages[strMethodName] = str(pyException) 106 self.__iNumberTestMethodFailure += 1 107 EDVerbose.unitTest("Unexpected Error!") 108 EDVerbose.unitTest("%s executed with FAILURE" % strMethodName) 109 EDVerbose.unitTest() 110 EDVerbose.writeErrorTrace() 111 EDVerbose.unitTest() 112 self.__bIsExecuted = True 113 self.setTimeEnd()
114 115 116
117 - def postProcess(self):
118 """ 119 Writes out a summary of the test case. 120 """ 121 if self.__bIsExecuted: 122 EDVerbose.unitTest("-------------------------------------------------------------------") 123 EDVerbose.unitTest("Result for %s" % self.getClassName()) 124 EDVerbose.unitTest() 125 EDVerbose.unitTest("Total number of test methods : %d" % self.getNumberOfTests()) 126 EDVerbose.unitTest("Number of SUCCESS : %d" % self.__iNumberTestMethodSuccess) 127 EDVerbose.unitTest("Number of FAILURE : %d" % self.__iNumberTestMethodFailure) 128 if self.__dictMethodFailureMessages != {}: 129 EDVerbose.unitTest("") 130 EDVerbose.unitTest("List of test methods ending with failure:") 131 for strMethodName in self.__dictMethodFailureMessages: 132 EDVerbose.unitTest(" %s :" % strMethodName.split(".")[1]) 133 EDVerbose.unitTest(" %s" % self.__dictMethodFailureMessages[strMethodName]) 134 EDVerbose.unitTest() 135 EDVerbose.unitTest("Runtime : %.3f [s]" % self.getRunTime()) 136 EDVerbose.unitTest("===================================================================") 137 else: 138 EDVerbose.unitTest() 139 EDVerbose.unitTest("Test case %s not executed :" % self.getClassName()) 140 EDVerbose.unitTest(self.__strReasonForNotBeingExecuted) 141 EDVerbose.unitTest() 142 EDVerbose.unitTest("===================================================================")
143 144
145 - def getMethodFailureMessages(self):
146 """ 147 This method returns a dictionary with the failure messages: 148 Key : Name of the test method 149 Value : Failure message 150 @return: MethodFailureMessages 151 @rtype: dict 152 """ 153 return self.__dictMethodFailureMessages
154 155
156 - def setTestSuiteName(self, _strTestSuiteName):
157 """ 158 Used by EDTestSuite: Sets the name of the test suite invoking the test case. 159 @param _strTestSuiteName: TestSuiteName 160 @type _strTestSuiteName: string 161 """ 162 self.__strTestSuiteName = _strTestSuiteName
163 164 165
166 - def getTestSuiteName(self):
167 """ 168 Returns the name of the test suite invoking the test case. 169 None if not inviked by a test suite. 170 @return: TestSuiteName 171 @rtype: string 172 """ 173 return self.__strTestSuiteName
174 175
176 - def setReasonForNotBeingExectuted(self, _strValue):
177 """ 178 Sets a string describing why the test case shouldn't be executed. 179 For example : missing configuration file. 180 If the string is not empty, the test case is not executed. 181 @param _strValue: ReasonForNotBeingExecuted 182 @type _strValue: string 183 """ 184 self.__strReasonForNotBeingExecuted = _strValue
185 186
188 """ 189 Returns a string describing why the test case shouldn't be executed. 190 For example : missing configuration file. 191 If the string is not empty, the test case is not executed. 192 @return: ReasonForNotBeingExecuted 193 @rtype: string 194 """ 195 return self.__strReasonForNotBeingExecuted
196 197
198 - def getTestsHome(self):
199 """ 200 Returns the Test home directory 201 @return: TestsHome 202 @rtype: string 203 """ 204 return EDUtilsPath.EDNA_TESTS
205 206
207 - def getTestsDataHome(self):
208 """ 209 Returns the Test data home directory 210 @return: TestsDataHome 211 @rtype: string 212 """ 213 return EDUtilsPath.EDNA_TESTDATA
214 215
216 - def getTestsDataImagesHome(self):
217 """ 218 Returns the Test data home directory 219 @return: TestsDataImagesHome 220 @rtype: string 221 """ 222 return EDUtilsPath.EDNA_TESTIMAGES
223 224 225
227 """ 228 The number of successful test methods. 229 @return: NumberTestMethodSuccess 230 @rtype: integer 231 """ 232 return self.__iNumberTestMethodSuccess
233 234
236 """ 237 The number of test methods executed with failure. 238 @return: NumberTestMethodFailure 239 @rtype: integer 240 """ 241 return self.__iNumberTestMethodFailure
242 243
244 - def isExecuted(self):
245 """ 246 Returns True if the test case was executed. 247 @return: IsExecuted 248 @rtype: boolean 249 """ 250 return self.__bIsExecuted
251