103 Qt.WindowContextHelpButtonHint)) |
103 Qt.WindowContextHelpButtonHint)) |
104 self.setWindowIcon(UI.PixmapCache.getIcon("eric.png")) |
104 self.setWindowIcon(UI.PixmapCache.getIcon("eric.png")) |
105 self.setWindowTitle(self.tr("Unittest")) |
105 self.setWindowTitle(self.tr("Unittest")) |
106 if dbs: |
106 if dbs: |
107 self.ui = ui |
107 self.ui = ui |
108 else: |
|
109 self.localCheckBox.hide() |
|
110 self.__setProgressColor("green") |
108 self.__setProgressColor("green") |
111 self.progressLed.setDarkFactor(150) |
109 self.progressLed.setDarkFactor(150) |
112 self.progressLed.off() |
110 self.progressLed.off() |
113 |
111 |
114 self.venvComboBox.addItem("") |
112 self.venvComboBox.addItem("") |
234 @param suite file name of the test suite |
232 @param suite file name of the test suite |
235 @type str |
233 @type str |
236 """ |
234 """ |
237 self.insertProg(suite) |
235 self.insertProg(suite) |
238 |
236 |
239 @pyqtSlot(str) |
|
240 def on_testsuitePicker_editTextChanged(self, txt): |
|
241 """ |
|
242 Private slot to handle changes of the test file name. |
|
243 |
|
244 @param txt name of the test file (string) |
|
245 """ |
|
246 fileTypes = { |
|
247 "Python2": ("Python", "Python2"), |
|
248 "Python3": ("Python3", ) |
|
249 } |
|
250 if self.__dbs: |
|
251 ver = sys.version_info[0] |
|
252 variant = "Python{0}".format(ver) |
|
253 exts = self.__dbs.getExtensions(variant) |
|
254 flags = Utilities.extractFlagsFromFile(txt) |
|
255 if not txt.endswith(exts) or \ |
|
256 ("FileType" in flags and |
|
257 flags["FileType"] not in fileTypes[variant]): |
|
258 self.localCheckBox.setChecked(False) |
|
259 self.localCheckBox.setEnabled(False) |
|
260 return |
|
261 |
|
262 self.localCheckBox.setEnabled(bool(self.__dbs)) |
|
263 |
|
264 def on_buttonBox_clicked(self, button): |
237 def on_buttonBox_clicked(self, button): |
265 """ |
238 """ |
266 Private slot called by a button of the button box clicked. |
239 Private slot called by a button of the button box clicked. |
267 |
240 |
268 @param button button that was clicked (QAbstractButton) |
241 @param button button that was clicked (QAbstractButton) |
304 testFunctionName = "suite" |
277 testFunctionName = "suite" |
305 |
278 |
306 # build the module name from the filename without extension |
279 # build the module name from the filename without extension |
307 self.testName = os.path.splitext(os.path.basename(prog))[0] |
280 self.testName = os.path.splitext(os.path.basename(prog))[0] |
308 |
281 |
309 if self.__dbs and not self.localCheckBox.isChecked(): |
282 if self.__dbs: |
310 # we are cooperating with the eric6 IDE |
283 # we are cooperating with the eric6 IDE |
311 project = e5App().getObject("Project") |
284 project = e5App().getObject("Project") |
312 if self.__forProject and project.isOpen() and \ |
285 if self.__forProject and project.isOpen() and \ |
313 project.isProjectSource(prog): |
286 project.isProjectSource(prog): |
314 mainScript = project.getMainScript(True) |
287 mainScript = os.path.abspath(project.getMainScript(True)) |
315 clientType = project.getProjectLanguage() |
288 clientType = project.getProjectLanguage() |
|
289 sysPath = [os.path.dirname(mainScript)] |
316 else: |
290 else: |
317 mainScript = os.path.abspath(prog) |
291 mainScript = os.path.abspath(prog) |
|
292 sysPath = [] |
318 flags = Utilities.extractFlagsFromFile(mainScript) |
293 flags = Utilities.extractFlagsFromFile(mainScript) |
319 if mainScript.endswith( |
294 if mainScript.endswith( |
320 tuple(Preferences.getPython("PythonExtensions"))) or \ |
295 tuple(Preferences.getPython("PythonExtensions"))) or \ |
321 ("FileType" in flags and |
296 ("FileType" in flags and |
322 flags["FileType"] in ["Python", "Python2"]): |
297 flags["FileType"] in ["Python", "Python2"]): |
332 self.__dbs.remoteUTPrepare( |
307 self.__dbs.remoteUTPrepare( |
333 prog, self.testName, testFunctionName, failed, |
308 prog, self.testName, testFunctionName, failed, |
334 self.coverageCheckBox.isChecked(), mainScript, |
309 self.coverageCheckBox.isChecked(), mainScript, |
335 self.coverageEraseCheckBox.isChecked(), clientType=clientType, |
310 self.coverageEraseCheckBox.isChecked(), clientType=clientType, |
336 forProject=self.__forProject, |
311 forProject=self.__forProject, |
337 venvName=self.venvComboBox.currentText()) |
312 venvName=self.venvComboBox.currentText(), syspath=sysPath) |
338 else: |
313 else: |
339 # we are running as an application or in local mode |
314 # we are running as an application |
340 sys.path = [os.path.dirname(os.path.abspath(prog))] + \ |
315 sys.path = [os.path.dirname(os.path.abspath(prog))] + \ |
341 self.savedSysPath |
316 self.savedSysPath |
342 |
317 |
343 # clean up list of imported modules to force a reimport upon |
318 # clean up list of imported modules to force a reimport upon |
344 # running the test |
319 # running the test |
438 @pyqtSlot() |
413 @pyqtSlot() |
439 def on_stopButton_clicked(self): |
414 def on_stopButton_clicked(self): |
440 """ |
415 """ |
441 Private slot to stop the test. |
416 Private slot to stop the test. |
442 """ |
417 """ |
443 if self.__dbs and not self.localCheckBox.isChecked(): |
418 if self.__dbs: |
444 self.__dbs.remoteUTStop() |
419 self.__dbs.remoteUTStop() |
445 elif self.testResult: |
420 elif self.testResult: |
446 self.testResult.stop() |
421 self.testResult.stop() |
447 |
422 |
448 def on_errorsListWidget_currentTextChanged(self, text): |
423 def on_errorsListWidget_currentTextChanged(self, text): |
611 @param doc documentation of the started test (string) |
586 @param doc documentation of the started test (string) |
612 """ |
587 """ |
613 if doc: |
588 if doc: |
614 self.testsListWidget.insertItem(0, " {0}".format(doc)) |
589 self.testsListWidget.insertItem(0, " {0}".format(doc)) |
615 self.testsListWidget.insertItem(0, test) |
590 self.testsListWidget.insertItem(0, test) |
616 if self.__dbs is None or self.localCheckBox.isChecked(): |
591 if self.__dbs is None: |
617 QApplication.processEvents() |
592 QApplication.processEvents() |
618 |
593 |
619 def testFinished(self): |
594 def testFinished(self): |
620 """ |
595 """ |
621 Public method called if a test has finished. |
596 Public method called if a test has finished. |
734 try: |
709 try: |
735 editor.close() |
710 editor.close() |
736 except Exception: |
711 except Exception: |
737 # ignore all exceptions |
712 # ignore all exceptions |
738 pass |
713 pass |
739 |
|
740 @pyqtSlot(str) |
|
741 def on_venvComboBox_currentTextChanged(self, venvName): |
|
742 """ |
|
743 Private slot to handle the selection of a virtual environment. |
|
744 |
|
745 @param venvName name of the selected virtual environment |
|
746 @type str |
|
747 """ |
|
748 if venvName: |
|
749 self.localCheckBox.setChecked(False) |
|
750 self.localCheckBox.setEnabled(False) |
|
751 else: |
|
752 self.localCheckBox.setEnabled(True) |
|
753 |
714 |
754 |
715 |
755 class QtTestResult(unittest.TestResult): |
716 class QtTestResult(unittest.TestResult): |
756 """ |
717 """ |
757 A TestResult derivative to work with a graphical GUI. |
718 A TestResult derivative to work with a graphical GUI. |