1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 """
29 EDNA test suite module ...
30
31 a TestSuite is a sequence of EDTestCase and/or EDTestSuite
32
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 EDVerbose import EDVerbose
42 from EDTest import EDTest
43 from EDUtilsTest import EDUtilsTest
44
45
47 """
48 A test suite can contain a list of test cases and/or other test suites.
49 At the end of the execution of a test suite a summary is written containing:
50 - The number of test suites in the test suite(if any)
51 - If there are test suites not executed a list of these
52 - The total number of test cases not executed due to e.g. missing configuration file and a list of these
53 - The total number of test cases ending with success
54 - The total number of test cases ending with failure
55 - If there are test methods ending with failure a list of the test cases, test methods and the failures.
56 - The total number of test methods ending with success
57 - The total number of test methods ending with failure
58 """
59
60
61 - def __init__(self, _strTestSuiteName=None):
62 EDTest.__init__(self, _strTestSuiteName)
63 self.__listTestCase = []
64 self.__listTestSuite = []
65 self.__bTopLevel = True
66 self.__iNumberTestSuite = 0
67 self.__iNumberTestMethodSuccess = 0
68 self.__iNumberTestMethodFailure = 0
69 self.__iNumberTestCaseSuccess = 0
70 self.__iNumberTestCaseFailure = 0
71 self.__dictTestCaseFailureMessages = {}
72 self.__dictTestCaseNotExecuted = {}
73 self.__dictTestSuiteNotExecuted = {}
74
75
77 """
78 This method adds a test case give it's name to the test suite. If the test case
79 cannot be loaded an error message is issued and it's name is added to the list of not
80 executed test cases.
81 @return: NumberTestCaseFailure
82 @rtype: integer
83 """
84 edTestCase = None
85 exceptionObject = None
86 try:
87 edTestCase = EDUtilsTest.getFactoryPluginTest().loadPlugin(_strTestCaseName)
88 except ImportError, exceptionObject:
89 strWarningMessage = "Could not create the test case: %s, reason: %s" % (_strTestCaseName, exceptionObject)
90 EDVerbose.WARNING(strWarningMessage)
91 self.__dictTestCaseNotExecuted[_strTestCaseName] = "%s : %s" % (self.getClassName(), strWarningMessage)
92 if edTestCase is None:
93 if exceptionObject is None:
94 EDVerbose.error("EDTestSuite.addTestCaseFromName: Could not create the test case: " + _strTestCaseName)
95 self.__dictTestCaseNotExecuted[_strTestCaseName] = "%s : Could not create the test case" % self.getClassName()
96 else:
97 edTestCase.setTestSuiteName(self.getClassName())
98 self.__listTestCase.append(edTestCase)
99
100
102 """
103 This method adds a test suite give it's name to the test suite. If the test case
104 cannot be loaded an error message is issued and it's name is added to the list of not
105 executed test suites.
106 @return: NumberTestCaseFailure
107 @rtype: integer
108 """
109 edTestSuite = None
110 exceptionObject = None
111 try:
112 edTestSuite = EDUtilsTest.getFactoryPluginTest().loadPlugin(_strTestSuiteName)
113 except ImportError, exceptionObject:
114 strWarningMessage = "Could not create the test suite: %s, reason: %s" % (_strTestSuiteName, exceptionObject)
115 EDVerbose.WARNING(strWarningMessage)
116 self.__dictTestCaseNotExecuted[_strTestSuiteName] = "%s : %s" % (self.getClassName(), strWarningMessage)
117 if edTestSuite is None:
118 if exceptionObject is None:
119 EDVerbose.error("EDTestSuitePluginUnit.addTestSuiteFromName: Could not create test suite: " + _strTestSuiteName)
120 self.__dictTestSuiteNotExecuted[_strTestSuiteName] = "%s : Could not create the test suite" % self.getClassName()
121 else:
122 self.__listTestSuite.append(edTestSuite)
123
124
125
161
162
163
164 - def postProcess(self):
165 """
166 This method writes out the results of the test suite.
167 """
168 EDVerbose.screen()
169 EDVerbose.screen()
170 EDVerbose.unitTest("###################################################################")
171 strResult = None
172 if self.__iNumberTestCaseFailure == 0 and self.__iNumberTestMethodFailure == 0:
173 strResult = "SUCCESS"
174 else:
175 strResult = "FAILURE"
176 EDVerbose.unitTest("Result for %s : %s" % (self.getTestName(), strResult))
177 EDVerbose.unitTest()
178 if self.__iNumberTestSuite > 0:
179 EDVerbose.unitTest(" Number of executed test suites in this test suite : %d" % self.__iNumberTestSuite)
180 EDVerbose.unitTest()
181 if self.__dictTestSuiteNotExecuted != {}:
182 EDVerbose.unitTest()
183 EDVerbose.unitTest("OBS! The following test suites were not executed due to errors:")
184 EDVerbose.unitTest()
185 for strTestSuiteName in self.__dictTestSuiteNotExecuted.keys():
186 EDVerbose.unitTest(" %s : %s" % (self.__dictTestSuiteNotExecuted[strTestSuiteName], strTestSuiteName))
187 EDVerbose.unitTest()
188 if self.__dictTestCaseNotExecuted != {}:
189 EDVerbose.unitTest()
190 EDVerbose.unitTest("OBS! The following test cases not executed due to errors:")
191 EDVerbose.unitTest()
192 for strTestCaseName in self.__dictTestCaseNotExecuted.keys():
193 EDVerbose.unitTest(" %s :" % strTestCaseName)
194 EDVerbose.unitTest(" %s" % self.__dictTestCaseNotExecuted[strTestCaseName])
195 EDVerbose.unitTest()
196 EDVerbose.unitTest(" Total number of test cases NOT EXECUTED : %d" % len(self.__dictTestCaseNotExecuted))
197 EDVerbose.unitTest()
198 if self.__iNumberTestCaseSuccess != 0 or self.__iNumberTestCaseFailure != 0:
199 EDVerbose.unitTest(" Total number of test cases executed with SUCCESS : %d" % self.__iNumberTestCaseSuccess)
200 EDVerbose.unitTest(" Total number of test cases executed with FAILURE : %d" % self.__iNumberTestCaseFailure)
201 EDVerbose.unitTest()
202 if self.__dictTestCaseFailureMessages != {}:
203 EDVerbose.unitTest("")
204 EDVerbose.unitTest("OBS! The following test methods ended with failure:")
205 EDVerbose.unitTest("")
206 for strTestCaseName in self.__dictTestCaseFailureMessages.keys():
207 EDVerbose.unitTest(" %s :" % strTestCaseName)
208 for strMethodName in self.__dictTestCaseFailureMessages[strTestCaseName].keys():
209 EDVerbose.unitTest(" %s :" % strMethodName.split(".")[1])
210 EDVerbose.unitTest(" %s" % self.__dictTestCaseFailureMessages[strTestCaseName][strMethodName])
211 EDVerbose.unitTest("")
212 EDVerbose.unitTest("")
213 if self.__iNumberTestMethodSuccess != 0 or self.__iNumberTestMethodFailure != 0:
214 EDVerbose.unitTest("Total number of test methods executed with SUCCESS : %d" % self.__iNumberTestMethodSuccess)
215 EDVerbose.unitTest("Total number of test methods executed with FAILURE : %d" % self.__iNumberTestMethodFailure)
216 EDVerbose.unitTest()
217 EDVerbose.unitTest(" Runtime : %.3f [s]" % self.getRunTime())
218 EDVerbose.unitTest("###################################################################")
219
220
222 """
223 Helper function for "extending" a dictionary. Example:
224 >>> a={"a":1, "b": 2}
225 >>> b={"c":3, "d": 4}
226 >>> extendDictionary(a,b)
227 >>>a
228 {"a":1, "b": 2, "c":3, "d": 4}
229
230 @param _dictBase: The dictionary to be extended
231 @type _dictBase: dict
232
233 @param _dictExtend: The dictionary that will extend _dictBase
234 @type _dictExtend: dict
235 """
236 for key in _dictExtend.keys():
237 _dictBase[key] = _dictExtend[key]
238
239
241 """
242 Total number of test cases ended with failure.
243 @return: NumberTestCaseFailure
244 @rtype: integer
245 """
246 return self.__iNumberTestCaseFailure
247
248
250 """
251 Total number of test cases ended with success.
252 @return: NumberTestCaseSuccess
253 @rtype: integer
254 """
255 return self.__iNumberTestCaseSuccess
256
257
259 """
260 Total number of test methods ending with failure.
261 @return: NumberTestMethodFailure
262 @rtype: integer
263 """
264 return self.__iNumberTestMethodFailure
265
266
268 """
269 Total number of test methods ending with success.
270 @return: NumberTestMethodSuccess
271 @rtype: integer
272 """
273 return self.__iNumberTestMethodSuccess
274
275
276
278 """
279 Returns a dictionary containing:
280 Key : Test case name with failed test method(s)
281 Value : Dictionary with method names (keys) and error messages (values).
282 @return: TestCaseFailureMessages
283 @rtype: dict
284 """
285 return self.__dictTestCaseFailureMessages
286
287
289 """
290 Returns a dictionary containing:
291 Key : Test case name
292 Value : Description of why the test case was not executed
293 @return: TestCaseNotExecuted
294 @rtype: dict
295 """
296 return self.__dictTestCaseNotExecuted
297
298
300 """
301 Returns a dictionary containing:
302 Key : Test suite name
303 Value : Description of why the test suite was not executed
304 @return: TestCaseNotExecuted
305 @rtype: list
306 """
307 return self.__dictTestSuiteNotExecuted
308