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