DebugClients/Python/DCTestResult.py

branch
debugger speed
changeset 5178
878ce843ca9f
parent 5131
889ed5ff7a68
child 5179
5f56410e7624
equal deleted inserted replaced
5174:8c48f5e0cd92 5178:878ce843ca9f
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2009 - 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 class DCTestResult(TestResult):
15 """
16 A TestResult derivative to work with eric6's debug client.
17
18 For more details see unittest.py of the standard python distribution.
19 """
20 def __init__(self, dbgClient):
21 """
22 Constructor
23
24 @param dbgClient reference to the debug client
25 @type DebugClientBase
26 """
27 TestResult.__init__(self)
28 self.__dbgClient = dbgClient
29
30 def addFailure(self, test, err):
31 """
32 Public method called if a test failed.
33
34 @param test Reference to the test object
35 @param err The error traceback
36 """
37 TestResult.addFailure(self, test, err)
38 tracebackLines = self._exc_info_to_string(err, test)
39 self.__dbgClient.sendJsonCommand("ResponseUTTestFailed", {
40 "testname": str(test),
41 "traceback": tracebackLines,
42 "id": test.id(),
43 })
44
45 def addError(self, test, err):
46 """
47 Public method called if a test errored.
48
49 @param test Reference to the test object
50 @param err The error traceback
51 """
52 TestResult.addError(self, test, err)
53 tracebackLines = self._exc_info_to_string(err, test)
54 self.__dbgClient.sendJsonCommand("ResponseUTTestErrored", {
55 "testname": str(test),
56 "traceback": tracebackLines,
57 "id": test.id(),
58 })
59
60 def addSkip(self, test, reason):
61 """
62 Public method called if a test was skipped.
63
64 @param test reference to the test object
65 @param reason reason for skipping the test (string)
66 """
67 TestResult.addSkip(self, test, reason)
68 self.__dbgClient.sendJsonCommand("ResponseUTTestSkipped", {
69 "testname": str(test),
70 "reason": reason,
71 "id": test.id(),
72 })
73
74 def addExpectedFailure(self, test, err):
75 """
76 Public method called if a test failed expected.
77
78 @param test reference to the test object
79 @param err error traceback
80 """
81 TestResult.addExpectedFailure(self, test, err)
82 tracebackLines = self._exc_info_to_string(err, test)
83 self.__dbgClient.sendJsonCommand("ResponseUTTestFailedExpected", {
84 "testname": str(test),
85 "traceback": tracebackLines,
86 "id": test.id(),
87 })
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.__dbgClient.sendJsonCommand("ResponseUTTestSucceededUnexpected", {
97 "testname": str(test),
98 "id": test.id(),
99 })
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.__dbgClient.sendJsonCommand("ResponseUTStartTest", {
109 "testname": str(test),
110 "description": test.shortDescription(),
111 })
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.__dbgClient.sendJsonCommand("ResponseUTStopTest", {})
121
122 # ensure that pending input is processed
123 rrdy, wrdy, xrdy = select.select(
124 [self.__dbgClient.readstream], [], [], 0.01)
125
126 if self.__dbgClient.readstream in rrdy:
127 self.__dbgClient.readReady(self.__dbgClient.readstream)
128
129 #
130 # eflag: noqa = M702

eric ide

mercurial