DebugClients/Python/DCTestResult.py

branch
jsonrpc
changeset 5132
a094eee9f862
parent 4631
5c1a96925da4
--- a/DebugClients/Python/DCTestResult.py	Sat Sep 03 18:01:19 2016 +0200
+++ b/DebugClients/Python/DCTestResult.py	Sat Sep 03 18:02:37 2016 +0200
@@ -11,25 +11,21 @@
 from unittest import TestResult
 
 
-from DebugProtocol import ResponseUTTestFailed, ResponseUTTestErrored, \
-    ResponseUTStartTest, ResponseUTStopTest, ResponseUTTestSkipped, \
-    ResponseUTTestFailedExpected, ResponseUTTestSucceededUnexpected
-
-
 class DCTestResult(TestResult):
     """
     A TestResult derivative to work with eric6's debug client.
     
     For more details see unittest.py of the standard python distribution.
     """
-    def __init__(self, parent):
+    def __init__(self, dbgClient):
         """
         Constructor
         
-        @param parent The parent widget.
+        @param dbgClient reference to the debug client
+        @type DebugClientBase
         """
         TestResult.__init__(self)
-        self.parent = parent
+        self.__dbgClient = dbgClient
         
     def addFailure(self, test, err):
         """
@@ -40,10 +36,11 @@
         """
         TestResult.addFailure(self, test, err)
         tracebackLines = self._exc_info_to_string(err, test)
-        self.parent.write(
-            '%s%s\n' % (
-                ResponseUTTestFailed,
-                unicode((unicode(test), tracebackLines, test.id()))))
+        self.__dbgClient.sendJsonCommand("ResponseUTTestFailed", {
+            "testname": str(test),
+            "traceback": tracebackLines,
+            "id": test.id(),
+        })
         
     def addError(self, test, err):
         """
@@ -54,10 +51,11 @@
         """
         TestResult.addError(self, test, err)
         tracebackLines = self._exc_info_to_string(err, test)
-        self.parent.write(
-            '%s%s\n' % (
-                ResponseUTTestErrored,
-                unicode((unicode(test), tracebackLines, test.id()))))
+        self.__dbgClient.sendJsonCommand("ResponseUTTestErrored", {
+            "testname": str(test),
+            "traceback": tracebackLines,
+            "id": test.id(),
+        })
         
     def addSkip(self, test, reason):
         """
@@ -67,10 +65,11 @@
         @param reason reason for skipping the test (string)
         """
         TestResult.addSkip(self, test, reason)
-        self.parent.write(
-            '%s%s\n' % (
-                ResponseUTTestSkipped,
-                str((str(test), reason, test.id()))))
+        self.__dbgClient.sendJsonCommand("ResponseUTTestSkipped", {
+            "testname": str(test),
+            "reason": reason,
+            "id": test.id(),
+        })
         
     def addExpectedFailure(self, test, err):
         """
@@ -81,10 +80,11 @@
         """
         TestResult.addExpectedFailure(self, test, err)
         tracebackLines = self._exc_info_to_string(err, test)
-        self.parent.write(
-            '%s%s\n' % (
-                ResponseUTTestFailedExpected,
-                str((str(test), tracebackLines, test.id()))))
+        self.__dbgClient.sendJsonCommand("ResponseUTTestFailedExpected", {
+            "testname": str(test),
+            "traceback": tracebackLines,
+            "id": test.id(),
+        })
         
     def addUnexpectedSuccess(self, test):
         """
@@ -93,10 +93,10 @@
         @param test reference to the test object
         """
         TestResult.addUnexpectedSuccess(self, test)
-        self.parent.write(
-            '%s%s\n' % (
-                ResponseUTTestSucceededUnexpected,
-                str((str(test), test.id()))))
+        self.__dbgClient.sendJsonCommand("ResponseUTTestSucceededUnexpected", {
+            "testname": str(test),
+            "id": test.id(),
+        })
         
     def startTest(self, test):
         """
@@ -105,10 +105,10 @@
         @param test Reference to the test object
         """
         TestResult.startTest(self, test)
-        self.parent.write(
-            '%s%s\n' % (
-                ResponseUTStartTest,
-                unicode((unicode(test), test.shortDescription()))))
+        self.__dbgClient.sendJsonCommand("ResponseUTStartTest", {
+            "testname": str(test),
+            "description": test.shortDescription(),
+        })
 
     def stopTest(self, test):
         """
@@ -117,14 +117,14 @@
         @param test Reference to the test object
         """
         TestResult.stopTest(self, test)
-        self.parent.write('%s\n' % ResponseUTStopTest)
+        self.__dbgClient.sendJsonCommand("ResponseUTStopTest", {})
         
         # ensure that pending input is processed
-        rrdy, wrdy, xrdy = select.select([self.parent.readstream], [], [],
-                                         0.01)
+        rrdy, wrdy, xrdy = select.select(
+            [self.__dbgClient.readstream], [], [], 0.01)
 
-        if self.parent.readstream in rrdy:
-            self.parent.readReady(self.parent.readstream.fileno())
+        if self.__dbgClient.readstream in rrdy:
+            self.__dbgClient.readReady(self.__dbgClient.readstream)
 
 #
 # eflag: FileType = Python2

eric ide

mercurial