14 import re |
14 import re |
15 import os |
15 import os |
16 |
16 |
17 from PyQt5.QtCore import pyqtSignal, QEvent, Qt, pyqtSlot |
17 from PyQt5.QtCore import pyqtSignal, QEvent, Qt, pyqtSlot |
18 from PyQt5.QtGui import QColor |
18 from PyQt5.QtGui import QColor |
19 from PyQt5.QtWidgets import QWidget, QDialog, QApplication, QDialogButtonBox, \ |
19 from PyQt5.QtWidgets import ( |
20 QListWidgetItem, QComboBox, QTreeWidgetItem |
20 QWidget, QDialog, QApplication, QDialogButtonBox, QListWidgetItem, |
|
21 QComboBox, QTreeWidgetItem |
|
22 ) |
21 |
23 |
22 from E5Gui.E5Application import e5App |
24 from E5Gui.E5Application import e5App |
23 from E5Gui import E5MessageBox |
25 from E5Gui import E5MessageBox |
24 from E5Gui.E5MainWindow import E5MainWindow |
26 from E5Gui.E5MainWindow import E5MainWindow |
25 from E5Gui.E5PathPicker import E5PathPickerModes |
27 from E5Gui.E5PathPicker import E5PathPickerModes |
284 def on_testsuitePicker_aboutToShowPathPickerDialog(self): |
286 def on_testsuitePicker_aboutToShowPathPickerDialog(self): |
285 """ |
287 """ |
286 Private slot called before the test suite selection dialog is shown. |
288 Private slot called before the test suite selection dialog is shown. |
287 """ |
289 """ |
288 if self.__dbs: |
290 if self.__dbs: |
289 py2Extensions = \ |
291 py2Extensions = ' '.join( |
290 ' '.join(["*{0}".format(ext) |
292 ["*{0}".format(ext) |
291 for ext in self.__dbs.getExtensions('Python2')]) |
293 for ext in self.__dbs.getExtensions('Python2')] |
292 py3Extensions = \ |
294 ) |
293 ' '.join(["*{0}".format(ext) |
295 py3Extensions = ' '.join( |
294 for ext in self.__dbs.getExtensions('Python3')]) |
296 ["*{0}".format(ext) |
|
297 for ext in self.__dbs.getExtensions('Python3')] |
|
298 ) |
295 fileFilter = self.tr( |
299 fileFilter = self.tr( |
296 "Python3 Files ({1});;Python2 Files ({0});;All Files (*)")\ |
300 "Python3 Files ({1});;Python2 Files ({0});;All Files (*)" |
297 .format(py2Extensions, py3Extensions) |
301 ).format(py2Extensions, py3Extensions) |
298 else: |
302 else: |
299 fileFilter = self.tr("Python Files (*.py);;All Files (*)") |
303 fileFilter = self.tr("Python Files (*.py);;All Files (*)") |
300 self.testsuitePicker.setFilters(fileFilter) |
304 self.testsuitePicker.setFilters(fileFilter) |
301 |
305 |
302 defaultDirectory = Preferences.getMultiProject("Workspace") |
306 defaultDirectory = Preferences.getMultiProject("Workspace") |
401 self.tr("You must enter a start directory for" |
405 self.tr("You must enter a start directory for" |
402 " auto-discovery.")) |
406 " auto-discovery.")) |
403 return |
407 return |
404 |
408 |
405 workdir = "" |
409 workdir = "" |
406 clientType = \ |
410 clientType = self.__venvManager.getVirtualenvVariant(venvName) |
407 self.__venvManager.getVirtualenvVariant(venvName) |
|
408 if not clientType: |
411 if not clientType: |
409 # assume Python 3 |
412 # assume Python 3 |
410 clientType = "Python3" |
413 clientType = "Python3" |
411 sysPath = [] |
414 sysPath = [] |
412 self.__dbs.remoteUTDiscover(clientType, self.__forProject, |
415 self.__dbs.remoteUTDiscover(clientType, self.__forProject, |
421 self.tr("You must enter a start directory for" |
424 self.tr("You must enter a start directory for" |
422 " auto-discovery.")) |
425 " auto-discovery.")) |
423 return |
426 return |
424 |
427 |
425 if discoveryStart: |
428 if discoveryStart: |
426 sys.path = [os.path.abspath(discoveryStart)] + \ |
429 sys.path = ( |
|
430 [os.path.abspath(discoveryStart)] + |
427 self.savedSysPath |
431 self.savedSysPath |
|
432 ) |
428 |
433 |
429 # clean up list of imported modules to force a reimport upon |
434 # clean up list of imported modules to force a reimport upon |
430 # running the test |
435 # running the test |
431 if self.savedModulelist: |
436 if self.savedModulelist: |
432 for modname in list(sys.modules.keys()): |
437 for modname in list(sys.modules.keys()): |
438 # now try to discover the testsuite |
443 # now try to discover the testsuite |
439 os.chdir(discoveryStart) |
444 os.chdir(discoveryStart) |
440 try: |
445 try: |
441 testLoader = unittest.TestLoader() |
446 testLoader = unittest.TestLoader() |
442 test = testLoader.discover(discoveryStart) |
447 test = testLoader.discover(discoveryStart) |
443 if hasattr(testLoader, "errors") and \ |
448 if hasattr(testLoader, "errors") and bool(testLoader.errors): |
444 bool(testLoader.errors): |
|
445 E5MessageBox.critical( |
449 E5MessageBox.critical( |
446 self, |
450 self, |
447 self.tr("Unittest"), |
451 self.tr("Unittest"), |
448 self.tr( |
452 self.tr( |
449 "<p>Unable to discover tests.</p>" |
453 "<p>Unable to discover tests.</p>" |
492 for test in suite: |
496 for test in suite: |
493 if isinstance(test, unittest.TestSuite): |
497 if isinstance(test, unittest.TestSuite): |
494 testCases.extend(self.__assembleTestCasesList(test, start)) |
498 testCases.extend(self.__assembleTestCasesList(test, start)) |
495 else: |
499 else: |
496 testId = test.id() |
500 testId = test.id() |
497 if "ModuleImportFailure" not in testId and \ |
501 if ( |
498 "LoadTestsFailure" not in testId and \ |
502 "ModuleImportFailure" not in testId and |
499 "_FailedTest" not in testId: |
503 "LoadTestsFailure" not in testId and |
|
504 "_FailedTest" not in testId |
|
505 ): |
500 filename = os.path.join( |
506 filename = os.path.join( |
501 start, |
507 start, |
502 test.__module__.replace(".", os.sep) + ".py") |
508 test.__module__.replace(".", os.sep) + ".py") |
503 testCases.append( |
509 testCases.append( |
504 (test.id(), test.shortDescription(), filename) |
510 (test.id(), test.shortDescription(), filename) |
546 [testPath[index - 1]]) |
552 [testPath[index - 1]]) |
547 pitm.setExpanded(True) |
553 pitm.setExpanded(True) |
548 itm.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) |
554 itm.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) |
549 itm.setCheckState(0, Qt.Unchecked) |
555 itm.setCheckState(0, Qt.Unchecked) |
550 itm.setData(0, UnittestDialog.TestCaseNameRole, modulePath) |
556 itm.setData(0, UnittestDialog.TestCaseNameRole, modulePath) |
551 if os.path.splitext(os.path.basename(filename))[0] == \ |
557 if ( |
552 itm.text(0): |
558 os.path.splitext(os.path.basename(filename))[0] == |
|
559 itm.text(0) |
|
560 ): |
553 itm.setData(0, UnittestDialog.TestCaseFileRole, |
561 itm.setData(0, UnittestDialog.TestCaseFileRole, |
554 filename) |
562 filename) |
555 elif pitm: |
563 elif pitm: |
556 fn = pitm.data(0, UnittestDialog.TestCaseFileRole) |
564 fn = pitm.data(0, UnittestDialog.TestCaseFileRole) |
557 if fn: |
565 if fn: |
746 " auto-discovery.")) |
754 " auto-discovery.")) |
747 return |
755 return |
748 |
756 |
749 coverageFile = os.path.join(discoveryStart, "unittest") |
757 coverageFile = os.path.join(discoveryStart, "unittest") |
750 workdir = "" |
758 workdir = "" |
751 clientType = \ |
759 clientType = self.__venvManager.getVirtualenvVariant( |
752 self.__venvManager.getVirtualenvVariant(venvName) |
760 venvName) |
753 if not clientType: |
761 if not clientType: |
754 # assume Python 3 |
762 # assume Python 3 |
755 clientType = "Python3" |
763 clientType = "Python3" |
756 elif testFileName: |
764 elif testFileName: |
757 mainScript = os.path.abspath(testFileName) |
765 mainScript = os.path.abspath(testFileName) |
758 flags = Utilities.extractFlagsFromFile(mainScript) |
766 flags = Utilities.extractFlagsFromFile(mainScript) |
759 workdir = os.path.dirname(mainScript) |
767 workdir = os.path.dirname(mainScript) |
760 if mainScript.endswith( |
768 if ( |
761 tuple(Preferences.getPython("PythonExtensions"))) or \ |
769 mainScript.endswith(tuple( |
762 ("FileType" in flags and |
770 Preferences.getPython("PythonExtensions"))) or |
763 flags["FileType"] in ["Python", "Python2"]): |
771 ("FileType" in flags and |
|
772 flags["FileType"] in ["Python", "Python2"]) |
|
773 ): |
764 clientType = "Python2" |
774 clientType = "Python2" |
765 else: |
775 else: |
766 # if it is not Python2 it must be Python3! |
776 # if it is not Python2 it must be Python3! |
767 clientType = "Python3" |
777 clientType = "Python3" |
768 coverageFile = os.path.splitext(mainScript)[0] |
778 coverageFile = os.path.splitext(mainScript)[0] |
769 else: |
779 else: |
770 coverageFile = os.path.abspath("unittest") |
780 coverageFile = os.path.abspath("unittest") |
771 workdir = "" |
781 workdir = "" |
772 clientType = \ |
782 clientType = self.__venvManager.getVirtualenvVariant( |
773 self.__venvManager.getVirtualenvVariant(venvName) |
783 venvName) |
774 if not clientType: |
784 if not clientType: |
775 # assume Python 3 |
785 # assume Python 3 |
776 clientType = "Python3" |
786 clientType = "Python3" |
777 sysPath = [] |
787 sysPath = [] |
778 if failedOnly and self.__failedTests: |
788 if failedOnly and self.__failedTests: |
800 self.tr("You must enter a start directory for" |
810 self.tr("You must enter a start directory for" |
801 " auto-discovery.")) |
811 " auto-discovery.")) |
802 return |
812 return |
803 |
813 |
804 if testFileName: |
814 if testFileName: |
805 sys.path = [os.path.dirname(os.path.abspath(testFileName))] + \ |
815 sys.path = ( |
|
816 [os.path.dirname(os.path.abspath(testFileName))] + |
806 self.savedSysPath |
817 self.savedSysPath |
|
818 ) |
807 elif discoveryStart: |
819 elif discoveryStart: |
808 sys.path = [os.path.abspath(discoveryStart)] + \ |
820 sys.path = ( |
|
821 [os.path.abspath(discoveryStart)] + |
809 self.savedSysPath |
822 self.savedSysPath |
|
823 ) |
810 |
824 |
811 # clean up list of imported modules to force a reimport upon |
825 # clean up list of imported modules to force a reimport upon |
812 # running the test |
826 # running the test |
813 if self.savedModulelist: |
827 if self.savedModulelist: |
814 for modname in list(sys.modules.keys()): |
828 for modname in list(sys.modules.keys()): |
866 # now set up the coverage stuff |
880 # now set up the coverage stuff |
867 if self.coverageCheckBox.isChecked(): |
881 if self.coverageCheckBox.isChecked(): |
868 if discover: |
882 if discover: |
869 covname = os.path.join(discoveryStart, "unittest") |
883 covname = os.path.join(discoveryStart, "unittest") |
870 elif testFileName: |
884 elif testFileName: |
871 covname = \ |
885 covname = os.path.splitext( |
872 os.path.splitext(os.path.abspath(testFileName))[0] |
886 os.path.abspath(testFileName))[0] |
873 else: |
887 else: |
874 covname = "unittest" |
888 covname = "unittest" |
875 |
889 |
876 from DebugClients.Python.coverage import coverage |
890 from DebugClients.Python.coverage import coverage |
877 cover = coverage(data_file="{0}.coverage".format(covname)) |
891 cover = coverage(data_file="{0}.coverage".format(covname)) |