PyUnit/UnittestDialog.py

changeset 6359
e78be0616e6e
parent 6048
82ad8ec9548c
child 6645
ad476851d7e0
--- a/PyUnit/UnittestDialog.py	Wed Jun 20 18:34:44 2018 +0200
+++ b/PyUnit/UnittestDialog.py	Wed Jun 20 18:45:07 2018 +0200
@@ -139,6 +139,8 @@
             self.dbs.utTestFailedExpected.connect(self.testFailedExpected)
             self.dbs.utTestSucceededUnexpected.connect(
                 self.testSucceededUnexpected)
+        
+        self.__editors = []
     
     def keyPressEvent(self, evt):
         """
@@ -636,18 +638,14 @@
         
         ui.showButton = ui.buttonBox.addButton(
             self.tr("Show Source"), QDialogButtonBox.ActionRole)
+        ui.showButton.clicked.connect(self.__showSource)
+        
         ui.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
         
         self.dlg.setWindowTitle(text)
         ui.testLabel.setText(test)
         ui.traceback.setPlainText(tracebackText)
         
-        # one more button if called from eric
-        if self.dbs:
-            ui.showButton.clicked.connect(self.__showSource)
-        else:
-            ui.showButton.hide()
-
         # and now fire it up
         self.dlg.show()
         self.dlg.exec_()
@@ -656,9 +654,6 @@
         """
         Private slot to show the source of a traceback in an eric6 editor.
         """
-        if not self.dbs:
-            return
-            
         # get the error info
         tracebackLines = self.dlg.traceback.toPlainText().splitlines()
         # find the last entry matching the pattern
@@ -669,7 +664,11 @@
                 break
         if fmatch:
             fn, ln = fmatch.group(1, 2)
-            self.unittestFile.emit(fn, int(ln), 1)
+            if self.dbs:
+                # running as part of eric IDE
+                self.unittestFile.emit(fn, int(ln), 1)
+            else:
+                self.__openEditor(fn, int(ln))
     
     def hasFailedTests(self):
         """
@@ -678,13 +677,48 @@
         @return flag indicating the presence of failed tests (boolean)
         """
         return bool(self.__failedTests)
+    
+    def __openEditor(self, filename, linenumber):
+        """
+        Private method to open an editor window for the given file.
+        
+        Note: This method opens an editor window when the unittest dialog
+        is called as a standalone application.
+        
+        @param filename path of the file to be opened
+        @type str
+        @param linenumber line number to place the cursor at
+        @type int
+        """
+        from QScintilla.MiniEditor import MiniEditor
+        editor = MiniEditor(filename, "Python3", self)
+        editor.gotoLine(linenumber)
+        editor.show()
+        
+        self.__editors.append(editor)
+    
+    def closeEvent(self, event):
+        """
+        Protected method to handle the close event.
+        
+        @param event close event
+        @type QCloseEvent
+        """
+        event.accept()
+        
+        for editor in self.__editors:
+            try:
+                editor.close()
+            except Exception:
+                # ignore all exceptions
+                pass
 
 
 class QtTestResult(unittest.TestResult):
     """
     A TestResult derivative to work with a graphical GUI.
     
-    For more details see pyunit.py of the standard python distribution.
+    For more details see pyunit.py of the standard Python distribution.
     """
     def __init__(self, parent):
         """

eric ide

mercurial