DebugClients/Python3/DCTestResult.py

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

eric ide

mercurial