6 """ |
6 """ |
7 Module implementing a TestResult derivative for the eric5 debugger. |
7 Module implementing a TestResult derivative for the eric5 debugger. |
8 """ |
8 """ |
9 |
9 |
10 import select |
10 import select |
11 import traceback |
|
12 from unittest import TestResult |
11 from unittest import TestResult |
13 |
12 |
14 |
13 |
15 from DebugProtocol import ResponseUTTestFailed, ResponseUTTestErrored, \ |
14 from DebugProtocol import ResponseUTTestFailed, ResponseUTTestErrored, \ |
16 ResponseUTStartTest, ResponseUTStopTest |
15 ResponseUTStartTest, ResponseUTStopTest, ResponseUTTestSkipped, \ |
|
16 ResponseUTTestFailedExpected, ResponseUTTestSucceededUnexpected |
17 |
17 |
18 |
18 |
19 class DCTestResult(TestResult): |
19 class DCTestResult(TestResult): |
20 """ |
20 """ |
21 A TestResult derivative to work with eric5's debug client. |
21 A TestResult derivative to work with eric5's debug client. |
37 |
37 |
38 @param test Reference to the test object |
38 @param test Reference to the test object |
39 @param err The error traceback |
39 @param err The error traceback |
40 """ |
40 """ |
41 TestResult.addFailure(self, test, err) |
41 TestResult.addFailure(self, test, err) |
42 tracebackLines = traceback.format_exception(*(err + (10,))) |
42 tracebackLines = self._exc_info_to_string(err, test) |
43 self.parent.write('{0}{1}\n'.format(ResponseUTTestFailed, |
43 self.parent.write('{0}{1}\n'.format(ResponseUTTestFailed, |
44 str((str(test), tracebackLines)))) |
44 str((str(test), tracebackLines)))) |
45 |
45 |
46 def addError(self, test, err): |
46 def addError(self, test, err): |
47 """ |
47 """ |
49 |
49 |
50 @param test Reference to the test object |
50 @param test Reference to the test object |
51 @param err The error traceback |
51 @param err The error traceback |
52 """ |
52 """ |
53 TestResult.addError(self, test, err) |
53 TestResult.addError(self, test, err) |
54 tracebackLines = traceback.format_exception(*(err + (10,))) |
54 tracebackLines = self._exc_info_to_string(err, test) |
55 self.parent.write('{0}{1}\n'.format(ResponseUTTestErrored, |
55 self.parent.write('{0}{1}\n'.format(ResponseUTTestErrored, |
56 str((str(test), tracebackLines)))) |
56 str((str(test), tracebackLines)))) |
|
57 |
|
58 def addSkip(self, test, reason): |
|
59 """ |
|
60 Method called if a test was skipped. |
|
61 |
|
62 @param test reference to the test object |
|
63 @param reason reason for skipping the test (string) |
|
64 """ |
|
65 TestResult.addSkip(self, test, reason) |
|
66 self.parent.write('{0}{1}\n'.format(ResponseUTTestSkipped, |
|
67 str((str(test), reason)))) |
|
68 |
|
69 def addExpectedFailure(self, test, err): |
|
70 """ |
|
71 Method called if a test failed expected. |
|
72 |
|
73 @param test reference to the test object |
|
74 @param err error traceback |
|
75 """ |
|
76 TestResult.addExpectedFailure(self, test, err) |
|
77 tracebackLines = self._exc_info_to_string(err, test) |
|
78 self.parent.write('{0}{1}\n'.format(ResponseUTTestFailedExpected, |
|
79 str((str(test), tracebackLines)))) |
|
80 |
|
81 def addUnexpectedSuccess(self, test): |
|
82 """ |
|
83 Method called if a test succeeded expectedly. |
|
84 |
|
85 @param test reference to the test object |
|
86 """ |
|
87 TestResult.addUnexpectedSuccess(self, test) |
|
88 self.parent.write('{0}{1}\n'.format(ResponseUTTestSucceededUnexpected, str(test))) |
57 |
89 |
58 def startTest(self, test): |
90 def startTest(self, test): |
59 """ |
91 """ |
60 Method called at the start of a test. |
92 Method called at the start of a test. |
61 |
93 |