1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2003 - 2016 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a TestResult derivative for the eric6 debugger. |
|
8 """ |
|
9 |
|
10 import select |
|
11 from unittest import TestResult |
|
12 |
|
13 |
|
14 from DebugProtocol import ResponseUTTestFailed, ResponseUTTestErrored, \ |
|
15 ResponseUTStartTest, ResponseUTStopTest, ResponseUTTestSkipped, \ |
|
16 ResponseUTTestFailedExpected, ResponseUTTestSucceededUnexpected |
|
17 |
|
18 |
|
19 class DCTestResult(TestResult): |
|
20 """ |
|
21 A TestResult derivative to work with eric6's debug client. |
|
22 |
|
23 For more details see unittest.py of the standard python distribution. |
|
24 """ |
|
25 def __init__(self, parent): |
|
26 """ |
|
27 Constructor |
|
28 |
|
29 @param parent The parent widget. |
|
30 """ |
|
31 TestResult.__init__(self) |
|
32 self.parent = parent |
|
33 |
|
34 def addFailure(self, test, err): |
|
35 """ |
|
36 Public method called if a test failed. |
|
37 |
|
38 @param test Reference to the test object |
|
39 @param err The error traceback |
|
40 """ |
|
41 TestResult.addFailure(self, test, err) |
|
42 tracebackLines = self._exc_info_to_string(err, test) |
|
43 self.parent.write( |
|
44 '%s%s\n' % ( |
|
45 ResponseUTTestFailed, |
|
46 unicode((unicode(test), tracebackLines, test.id())))) |
|
47 |
|
48 def addError(self, test, err): |
|
49 """ |
|
50 Public method called if a test errored. |
|
51 |
|
52 @param test Reference to the test object |
|
53 @param err The error traceback |
|
54 """ |
|
55 TestResult.addError(self, test, err) |
|
56 tracebackLines = self._exc_info_to_string(err, test) |
|
57 self.parent.write( |
|
58 '%s%s\n' % ( |
|
59 ResponseUTTestErrored, |
|
60 unicode((unicode(test), tracebackLines, test.id())))) |
|
61 |
|
62 def addSkip(self, test, reason): |
|
63 """ |
|
64 Public method called if a test was skipped. |
|
65 |
|
66 @param test reference to the test object |
|
67 @param reason reason for skipping the test (string) |
|
68 """ |
|
69 TestResult.addSkip(self, test, reason) |
|
70 self.parent.write( |
|
71 '%s%s\n' % ( |
|
72 ResponseUTTestSkipped, |
|
73 str((str(test), reason, test.id())))) |
|
74 |
|
75 def addExpectedFailure(self, test, err): |
|
76 """ |
|
77 Public method called if a test failed expected. |
|
78 |
|
79 @param test reference to the test object |
|
80 @param err error traceback |
|
81 """ |
|
82 TestResult.addExpectedFailure(self, test, err) |
|
83 tracebackLines = self._exc_info_to_string(err, test) |
|
84 self.parent.write( |
|
85 '%s%s\n' % ( |
|
86 ResponseUTTestFailedExpected, |
|
87 str((str(test), tracebackLines, test.id())))) |
|
88 |
|
89 def addUnexpectedSuccess(self, test): |
|
90 """ |
|
91 Public method called if a test succeeded expectedly. |
|
92 |
|
93 @param test reference to the test object |
|
94 """ |
|
95 TestResult.addUnexpectedSuccess(self, test) |
|
96 self.parent.write( |
|
97 '%s%s\n' % ( |
|
98 ResponseUTTestSucceededUnexpected, |
|
99 str((str(test), test.id())))) |
|
100 |
|
101 def startTest(self, test): |
|
102 """ |
|
103 Public method called at the start of a test. |
|
104 |
|
105 @param test Reference to the test object |
|
106 """ |
|
107 TestResult.startTest(self, test) |
|
108 self.parent.write( |
|
109 '%s%s\n' % ( |
|
110 ResponseUTStartTest, |
|
111 unicode((unicode(test), test.shortDescription())))) |
|
112 |
|
113 def stopTest(self, test): |
|
114 """ |
|
115 Public method called at the end of a test. |
|
116 |
|
117 @param test Reference to the test object |
|
118 """ |
|
119 TestResult.stopTest(self, test) |
|
120 self.parent.write('%s\n' % ResponseUTStopTest) |
|
121 |
|
122 # ensure that pending input is processed |
|
123 rrdy, wrdy, xrdy = select.select([self.parent.readstream], [], [], |
|
124 0.01) |
|
125 |
|
126 if self.parent.readstream in rrdy: |
|
127 self.parent.readReady(self.parent.readstream.fileno()) |
|
128 |
|
129 # |
|
130 # eflag: FileType = Python2 |
|
131 # eflag: noqa = M601, M702 |
|