eric6/DebugClients/Python/DCTestResult.py

branch
maintenance
changeset 6989
8b8cadf8d7e9
parent 6942
2602857055c5
child 7360
9190402e4505
equal deleted inserted replaced
6938:7926553b7509 6989:8b8cadf8d7e9
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2003 - 2019 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, failfast):
21 """
22 Constructor
23
24 @param dbgClient reference to the debug client
25 @type DebugClientBase
26 @param failfast flag indicating to stop at the first error
27 @type bool
28 """
29 TestResult.__init__(self)
30 self.__dbgClient = dbgClient
31 self.failfast = failfast
32
33 def addFailure(self, test, err):
34 """
35 Public method called if a test failed.
36
37 @param test Reference to the test object
38 @param err The error traceback
39 """
40 TestResult.addFailure(self, test, err)
41 tracebackLines = self._exc_info_to_string(err, test)
42 self.__dbgClient.sendJsonCommand("ResponseUTTestFailed", {
43 "testname": str(test),
44 "traceback": tracebackLines,
45 "id": test.id(),
46 })
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.__dbgClient.sendJsonCommand("ResponseUTTestErrored", {
58 "testname": str(test),
59 "traceback": tracebackLines,
60 "id": test.id(),
61 })
62
63 def addSkip(self, test, reason):
64 """
65 Public method called if a test was skipped.
66
67 @param test reference to the test object
68 @param reason reason for skipping the test (string)
69 """
70 TestResult.addSkip(self, test, reason)
71 self.__dbgClient.sendJsonCommand("ResponseUTTestSkipped", {
72 "testname": str(test),
73 "reason": reason,
74 "id": test.id(),
75 })
76
77 def addExpectedFailure(self, test, err):
78 """
79 Public method called if a test failed expected.
80
81 @param test reference to the test object
82 @param err error traceback
83 """
84 TestResult.addExpectedFailure(self, test, err)
85 tracebackLines = self._exc_info_to_string(err, test)
86 self.__dbgClient.sendJsonCommand("ResponseUTTestFailedExpected", {
87 "testname": str(test),
88 "traceback": tracebackLines,
89 "id": test.id(),
90 })
91
92 def addUnexpectedSuccess(self, test):
93 """
94 Public method called if a test succeeded expectedly.
95
96 @param test reference to the test object
97 """
98 TestResult.addUnexpectedSuccess(self, test)
99 self.__dbgClient.sendJsonCommand("ResponseUTTestSucceededUnexpected", {
100 "testname": str(test),
101 "id": test.id(),
102 })
103
104 def startTest(self, test):
105 """
106 Public method called at the start of a test.
107
108 @param test Reference to the test object
109 """
110 TestResult.startTest(self, test)
111 self.__dbgClient.sendJsonCommand("ResponseUTStartTest", {
112 "testname": str(test),
113 "description": test.shortDescription(),
114 })
115
116 def stopTest(self, test):
117 """
118 Public method called at the end of a test.
119
120 @param test Reference to the test object
121 """
122 TestResult.stopTest(self, test)
123 self.__dbgClient.sendJsonCommand("ResponseUTStopTest", {})
124
125 # ensure that pending input is processed
126 rrdy, wrdy, xrdy = select.select(
127 [self.__dbgClient.readstream], [], [], 0.01)
128
129 if self.__dbgClient.readstream in rrdy:
130 self.__dbgClient.readReady(self.__dbgClient.readstream)
131
132 #
133 # eflag: noqa = M702

eric ide

mercurial