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

Source Code for Module EDInformationTest

  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 (jerome.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  __authors__ = ["Olof Svensson", "Jérôme Kieffer"] 
 37  __contact__ = "svensson@esrf.eu" 
 38  __license__ = "LGPLv3+" 
 39  __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" 
 40  __date__ = "20120216" 
 41  __doc__ = """ 
 42  EDInformationTest: Information for the test cases. 
 43  """ 
 44   
 45   
 46  from EDObject          import EDObject 
 47   
48 -class EDInformationTest(EDObject):
49 """ 50 Information for the test cases. 51 """
52 - def __init__(self, _pyStrNameTest="Test", _iNumberTest=0):
53 EDObject.__init__(self) 54 self.__strNameTest = _pyStrNameTest 55 self.__strException = None 56 self.__iNumberTest = _iNumberTest 57 self.__bSuccess = True 58 self.__listTest = [] 59 self.setTimeInit()
60 61
62 - def isSuccess(self):
63 bSuccess = True 64 if (self.__bSuccess): 65 for edTest in self.__listTest: 66 if (not edTest.isSuccess()): 67 bSuccess = False 68 else: 69 bSuccess = False 70 return bSuccess
71 72
73 - def getTestNumber(self):
74 return self.__iNumberTest
75 76
77 - def getTestName(self):
78 return self.__strNameTest
79 80
81 - def setTerminate(self, _bSuccess=True):
82 self.__bSuccess = _bSuccess 83 self.setTimeEnd()
84 85
86 - def setFailure(self):
87 self.__bSuccess = False
88 89
90 - def setSuccess(self):
91 self.__bSuccess = True
92 93
94 - def addInformationTest(self, _edInformationTest):
95 self.__listTest.append(_edInformationTest)
96 97
98 - def setException(self, _pyStr):
99 self.__strException = _pyStr 100 self.setFailure()
101 102
103 - def getException(self):
104 return self.__strException
105 106
107 - def getNumberTestMethod(self):
108 return len(self.__listTest)
109 110
111 - def outputString(self, _strSpacing=" "):
112 fTime = self.getRunTime() 113 bSuccess = self.isSuccess() 114 with self.locked(): 115 strMessage = _strSpacing 116 if (bSuccess): 117 strMessage += "[SUCCESS]" 118 else: 119 strMessage += "[FAILURE]" 120 strMessage += " [ %d ][ %s ][ %.3f s ]\n" % (self.__iNumberTest, self.__strNameTest, fTime) 121 if ((not bSuccess) and (self.__strException is not None)): 122 strMessage += _strSpacing + " [Exception]: " + str(self.__strException) + "\n" 123 124 for edTest in self.__listTest: 125 strMessage += edTest.outputString(" ") 126 return strMessage
127