diff -r 4adc2c6978f2 -r e5f03f779b00 PyUnit/UnittestDialog.py --- a/PyUnit/UnittestDialog.py Wed Mar 20 19:23:12 2019 +0100 +++ b/PyUnit/UnittestDialog.py Wed Mar 20 19:41:04 2019 +0100 @@ -44,19 +44,21 @@ unittestFile = pyqtSignal(str, int, int) unittestStopped = pyqtSignal() - def __init__(self, prog=None, dbs=None, ui=None, fromEric=False, - parent=None, name=None): + def __init__(self, prog=None, dbs=None, ui=None, parent=None, name=None): """ Constructor @param prog filename of the program to open + @type str @param dbs reference to the debug server object. It is an indication - whether we were called from within the eric6 IDE + whether we were called from within the eric6 IDE. + @type DebugServer @param ui reference to the UI object - @param fromEric flag indicating an instantiation from within the - eric IDE (boolean) - @param parent parent widget of this dialog (QWidget) - @param name name of this dialog (string) + @type UserInterface + @param parent parent widget of this dialog + @type QWidget + @param name name of this dialog + @type str """ super(UnittestDialog, self).__init__(parent) if name: @@ -93,8 +95,8 @@ self.startButton.setDefault(True) self.startFailedButton.setEnabled(False) - self.dbs = dbs - self.__fromEric = fromEric + self.__dbs = dbs + self.__forProject = False self.setWindowFlags( self.windowFlags() | Qt.WindowFlags( @@ -109,6 +111,12 @@ self.progressLed.setDarkFactor(150) self.progressLed.off() + self.venvComboBox.addItem("") + self.venvComboBox.addItems( + sorted(e5App().getObject("VirtualEnvManager") + .getVirtualenvNames())) + self.venvComboBox.setEnabled(bool(self.__dbs)) + self.fileHistory = [] self.testNameHistory = [] self.running = False @@ -128,16 +136,16 @@ self.__failedTests = [] # now connect the debug server signals if called from the eric6 IDE - if self.dbs: - self.dbs.utPrepared.connect(self.__UTPrepared) - self.dbs.utFinished.connect(self.__setStoppedMode) - self.dbs.utStartTest.connect(self.testStarted) - self.dbs.utStopTest.connect(self.testFinished) - self.dbs.utTestFailed.connect(self.testFailed) - self.dbs.utTestErrored.connect(self.testErrored) - self.dbs.utTestSkipped.connect(self.testSkipped) - self.dbs.utTestFailedExpected.connect(self.testFailedExpected) - self.dbs.utTestSucceededUnexpected.connect( + if self.__dbs: + self.__dbs.utPrepared.connect(self.__UTPrepared) + self.__dbs.utFinished.connect(self.__setStoppedMode) + self.__dbs.utStartTest.connect(self.testStarted) + self.__dbs.utStopTest.connect(self.testFinished) + self.__dbs.utTestFailed.connect(self.testFailed) + self.__dbs.utTestErrored.connect(self.testErrored) + self.__dbs.utTestSkipped.connect(self.testSkipped) + self.__dbs.utTestFailedExpected.connect(self.testFailedExpected) + self.__dbs.utTestSucceededUnexpected.connect( self.testSucceededUnexpected) self.__editors = [] @@ -148,7 +156,7 @@ @param evt key press event to handle (QKeyEvent) """ - if evt.key() == Qt.Key_Escape and self.__fromEric: + if evt.key() == Qt.Key_Escape and self.__dbs: self.close() def __setProgressColor(self, color): @@ -158,7 +166,16 @@ @param color colour to be shown (string) """ self.progressLed.setColor(QColor(color)) + + def setProjectMode(self, forProject): + """ + Public method to set the project mode of the dialog. + @param forProject flag indicating to run for the open project + @type bool + """ + self.__forProject = forProject + def insertProg(self, prog): """ Public slot to insert the filename prog into the testsuitePicker @@ -195,13 +212,13 @@ """ Private slot called before the test suite selection dialog is shown. """ - if self.dbs: + if self.__dbs: py2Extensions = \ ' '.join(["*{0}".format(ext) - for ext in self.dbs.getExtensions('Python2')]) + for ext in self.__dbs.getExtensions('Python2')]) py3Extensions = \ ' '.join(["*{0}".format(ext) - for ext in self.dbs.getExtensions('Python3')]) + for ext in self.__dbs.getExtensions('Python3')]) fileFilter = self.tr( "Python3 Files ({1});;Python2 Files ({0});;All Files (*)")\ .format(py2Extensions, py3Extensions) @@ -226,20 +243,23 @@ @param txt name of the test file (string) """ - if self.dbs: - exts = self.dbs.getExtensions("Python2") + fileTypes = { + "Python2": ("Python", "Python2"), + "Python3": ("Python3", ) + } + if self.__dbs: + ver = sys.version_info[0] + variant = "Python{0}".format(ver) + exts = self.__dbs.getExtensions(variant) flags = Utilities.extractFlagsFromFile(txt) - if txt.endswith(exts) or \ + if not txt.endswith(exts) or \ ("FileType" in flags and - flags["FileType"] in ["Python", "Python2"]): - self.coverageCheckBox.setChecked(False) - self.coverageCheckBox.setEnabled(False) + flags["FileType"] not in fileTypes[variant]): self.localCheckBox.setChecked(False) self.localCheckBox.setEnabled(False) return - self.coverageCheckBox.setEnabled(True) - self.localCheckBox.setEnabled(True) + self.localCheckBox.setEnabled(bool(self.__dbs)) def on_buttonBox_clicked(self, button): """ @@ -286,10 +306,11 @@ # build the module name from the filename without extension self.testName = os.path.splitext(os.path.basename(prog))[0] - if self.dbs and not self.localCheckBox.isChecked(): + if self.__dbs and not self.localCheckBox.isChecked(): # we are cooperating with the eric6 IDE project = e5App().getObject("Project") - if project.isOpen() and project.isProjectSource(prog): + if self.__forProject and project.isOpen() and \ + project.isProjectSource(prog): mainScript = project.getMainScript(True) clientType = project.getProjectLanguage() else: @@ -307,10 +328,12 @@ else: failed = [] self.__failedTests = [] - self.dbs.remoteUTPrepare( + self.__dbs.remoteUTPrepare( prog, self.testName, testFunctionName, failed, self.coverageCheckBox.isChecked(), mainScript, - self.coverageEraseCheckBox.isChecked(), clientType=clientType) + self.coverageEraseCheckBox.isChecked(), clientType=clientType, + forProject=self.__forProject, + venvName=self.venvComboBox.currentText()) else: # we are running as an application or in local mode sys.path = [os.path.dirname(os.path.abspath(prog))] + \ @@ -353,7 +376,7 @@ # now set up the coverage stuff if self.coverageCheckBox.isChecked(): - if self.dbs: + if self.__dbs: # we are cooperating with the eric6 IDE project = e5App().getObject("Project") if project.isOpen() and project.isProjectSource(prog): @@ -409,15 +432,15 @@ self.totalTests = nrTests self.__setRunningMode() - self.dbs.remoteUTRun() + self.__dbs.remoteUTRun() @pyqtSlot() def on_stopButton_clicked(self): """ Private slot to stop the test. """ - if self.dbs and not self.localCheckBox.isChecked(): - self.dbs.remoteUTStop() + if self.__dbs and not self.localCheckBox.isChecked(): + self.__dbs.remoteUTStop() elif self.testResult: self.testResult.stop() @@ -589,7 +612,7 @@ if doc: self.testsListWidget.insertItem(0, " {0}".format(doc)) self.testsListWidget.insertItem(0, test) - if self.dbs is None or self.localCheckBox.isChecked(): + if self.__dbs is None or self.localCheckBox.isChecked(): QApplication.processEvents() def testFinished(self): @@ -664,7 +687,7 @@ break if fmatch: fn, ln = fmatch.group(1, 2) - if self.dbs: + if self.__dbs: # running as part of eric IDE self.unittestFile.emit(fn, int(ln), 1) else: @@ -712,6 +735,20 @@ except Exception: # ignore all exceptions pass + + @pyqtSlot(str) + def on_venvComboBox_currentTextChanged(self, venvName): + """ + Private slot to handle the selection of a virtual environment. + + @param venvName name of the selected virtual environment + @type str + """ + if venvName: + self.localCheckBox.setChecked(False) + self.localCheckBox.setEnabled(False) + else: + self.localCheckBox.setEnabled(True) class QtTestResult(unittest.TestResult): @@ -812,7 +849,7 @@ @param parent reference to the parent widget (QWidget) """ super(UnittestWindow, self).__init__(parent) - self.cw = UnittestDialog(prog=prog, parent=self) + self.cw = UnittestDialog(prog, parent=self) self.cw.installEventFilter(self) size = self.cw.size() self.setCentralWidget(self.cw)