159 self.__startMenu.addAction( |
159 self.__startMenu.addAction( |
160 UI.PixmapCache.getIcon("coverageScript"), |
160 UI.PixmapCache.getIcon("coverageScript"), |
161 self.tr('Coverage run of Script...'), |
161 self.tr('Coverage run of Script...'), |
162 self.__contextMenuCoverageScript) |
162 self.__contextMenuCoverageScript) |
163 |
163 |
164 self.unittestAction = self.sourceMenu.addAction( |
164 self.testingAction = self.sourceMenu.addAction( |
165 self.tr('Run unittest...'), self.handleUnittest) |
165 self.tr('Run tests...'), self.handleTesting) |
166 self.sourceMenu.addSeparator() |
166 self.sourceMenu.addSeparator() |
167 act = self.sourceMenu.addAction( |
167 act = self.sourceMenu.addAction( |
168 self.tr('Rename file'), self._renameFile) |
168 self.tr('Rename file'), self._renameFile) |
169 self.menuActions.append(act) |
169 self.menuActions.append(act) |
170 act = self.sourceMenu.addAction( |
170 act = self.sourceMenu.addAction( |
644 if fn.endswith('.ptl'): |
644 if fn.endswith('.ptl'): |
645 for act in self.sourceMenuActions.values(): |
645 for act in self.sourceMenuActions.values(): |
646 act.setEnabled(False) |
646 act.setEnabled(False) |
647 self.classDiagramAction.setEnabled(True) |
647 self.classDiagramAction.setEnabled(True) |
648 self.importsDiagramAction.setEnabled(True) |
648 self.importsDiagramAction.setEnabled(True) |
649 self.unittestAction.setEnabled(False) |
649 self.testingAction.setEnabled(False) |
650 self.checksMenu.menuAction().setEnabled( |
650 self.checksMenu.menuAction().setEnabled( |
651 False) |
651 False) |
652 elif fn.endswith('.rb'): |
652 elif fn.endswith('.rb'): |
653 # entry for mixed mode programs |
653 # entry for mixed mode programs |
654 for act in self.sourceMenuActions.values(): |
654 for act in self.sourceMenuActions.values(): |
655 act.setEnabled(False) |
655 act.setEnabled(False) |
656 self.classDiagramAction.setEnabled(True) |
656 self.classDiagramAction.setEnabled(True) |
657 self.importsDiagramAction.setEnabled(False) |
657 self.importsDiagramAction.setEnabled(False) |
658 self.unittestAction.setEnabled(False) |
658 self.testingAction.setEnabled(False) |
659 self.checksMenu.menuAction().setEnabled( |
659 self.checksMenu.menuAction().setEnabled( |
660 False) |
660 False) |
661 elif fn.endswith('.js'): |
661 elif fn.endswith('.js'): |
662 # entry for mixed mode programs |
662 # entry for mixed mode programs |
663 for act in self.sourceMenuActions.values(): |
663 for act in self.sourceMenuActions.values(): |
664 act.setEnabled(False) |
664 act.setEnabled(False) |
665 self.unittestAction.setEnabled(False) |
665 self.testingAction.setEnabled(False) |
666 self.checksMenu.menuAction().setEnabled( |
666 self.checksMenu.menuAction().setEnabled( |
667 False) |
667 False) |
668 self.graphicsMenu.menuAction().setEnabled( |
668 self.graphicsMenu.menuAction().setEnabled( |
669 False) |
669 False) |
670 else: |
670 else: |
671 # assume the source file is a Python file |
671 # assume the source file is a Python file |
672 for act in self.sourceMenuActions.values(): |
672 for act in self.sourceMenuActions.values(): |
673 act.setEnabled(True) |
673 act.setEnabled(True) |
674 self.classDiagramAction.setEnabled(True) |
674 self.classDiagramAction.setEnabled(True) |
675 self.importsDiagramAction.setEnabled(True) |
675 self.importsDiagramAction.setEnabled(True) |
676 self.unittestAction.setEnabled(True) |
676 self.testingAction.setEnabled(True) |
677 self.checksMenu.menuAction().setEnabled( |
677 self.checksMenu.menuAction().setEnabled( |
678 True) |
678 True) |
679 self.sourceMenu.popup(self.mapToGlobal(coord)) |
679 self.sourceMenu.popup(self.mapToGlobal(coord)) |
680 elif isinstance( |
680 elif isinstance( |
681 itm, |
681 itm, |
753 |
753 |
754 # first check if the file belongs to a project and there is |
754 # first check if the file belongs to a project and there is |
755 # a project coverage file |
755 # a project coverage file |
756 fn = self.project.getMainScript(True) |
756 fn = self.project.getMainScript(True) |
757 if fn is not None: |
757 if fn is not None: |
758 tfn = Utilities.getTestFileName(fn) |
|
759 basename = os.path.splitext(fn)[0] |
|
760 tbasename = os.path.splitext(tfn)[0] |
|
761 prEnable = ( |
758 prEnable = ( |
762 prEnable or |
759 self.project.isPy3Project() and |
763 os.path.isfile("{0}.profile".format(basename)) or |
760 bool(Utilities.getProfileFileNames(fn)) |
764 os.path.isfile("{0}.profile".format(tbasename)) |
|
765 ) |
761 ) |
766 coEnable = ( |
762 coEnable = ( |
767 (coEnable or |
763 self.project.isPy3Project() and |
768 os.path.isfile("{0}.coverage".format(basename)) or |
764 bool(Utilities.getCoverageFileNames(fn)) |
769 os.path.isfile("{0}.coverage".format(tbasename))) and |
|
770 self.project.isPy3Project() |
|
771 ) |
765 ) |
772 |
766 |
773 # now check the selected item |
767 # now check the selected item |
774 itm = self.model().item(self.currentIndex()) |
768 itm = self.model().item(self.currentIndex()) |
775 fn = itm.fileName() |
769 fn = itm.fileName() |
776 if fn is not None: |
770 if fn is not None: |
777 basename = os.path.splitext(fn)[0] |
771 prEnable |= ( |
778 prEnable = ( |
772 itm.isPython3File() and |
779 prEnable or |
773 bool(Utilities.getProfileFileNames(fn)) |
780 os.path.isfile("{0}.profile".format(basename)) |
|
781 ) |
774 ) |
782 coEnable = ( |
775 coEnable |= ( |
783 (coEnable or |
776 itm.isPython3File() and |
784 os.path.isfile("{0}.coverage".format(basename))) and |
777 bool(Utilities.getCoverageFileName(fn)) |
785 itm.isPython3File() |
|
786 ) |
778 ) |
787 |
779 |
788 self.profileMenuAction.setEnabled(prEnable) |
780 self.profileMenuAction.setEnabled(prEnable) |
789 self.coverageMenuAction.setEnabled(coEnable) |
781 self.coverageMenuAction.setEnabled(coEnable) |
790 |
782 |
984 """ |
976 """ |
985 itm = self.model().item(self.currentIndex()) |
977 itm = self.model().item(self.currentIndex()) |
986 fn = itm.fileName() |
978 fn = itm.fileName() |
987 pfn = self.project.getMainScript(True) |
979 pfn = self.project.getMainScript(True) |
988 |
980 |
989 files = [] |
981 files = set() |
990 |
982 |
991 if pfn is not None: |
983 if pfn is not None: |
992 tpfn = Utilities.getTestFileName(pfn) |
984 files |= set(Utilities.getCoverageFileNames(pfn)) |
993 basename = os.path.splitext(pfn)[0] |
|
994 tbasename = os.path.splitext(tpfn)[0] |
|
995 |
|
996 f = "{0}.coverage".format(basename) |
|
997 tf = "{0}.coverage".format(tbasename) |
|
998 if os.path.isfile(f): |
|
999 files.append(f) |
|
1000 if os.path.isfile(tf): |
|
1001 files.append(tf) |
|
1002 |
985 |
1003 if fn is not None: |
986 if fn is not None: |
1004 tfn = Utilities.getTestFileName(fn) |
987 files |= set(Utilities.getCoverageFileNames(fn)) |
1005 basename = os.path.splitext(fn)[0] |
988 |
1006 tbasename = os.path.splitext(tfn)[0] |
989 if list(files): |
1007 |
|
1008 f = "{0}.coverage".format(basename) |
|
1009 tf = "{0}.coverage".format(tbasename) |
|
1010 if os.path.isfile(f) and f not in files: |
|
1011 files.append(f) |
|
1012 if os.path.isfile(tf) and tf not in files: |
|
1013 files.append(tf) |
|
1014 |
|
1015 if files: |
|
1016 if len(files) > 1: |
990 if len(files) > 1: |
1017 pfn, ok = QInputDialog.getItem( |
991 cfn, ok = QInputDialog.getItem( |
1018 None, |
992 None, |
1019 self.tr("Code Coverage"), |
993 self.tr("Code Coverage"), |
1020 self.tr("Please select a coverage file"), |
994 self.tr("Please select a coverage file"), |
1021 files, |
995 files, |
1022 0, False) |
996 0, False) |
1023 if not ok: |
997 if not ok: |
1024 return |
998 return |
1025 else: |
999 else: |
1026 pfn = files[0] |
1000 cfn = files[0] |
1027 else: |
1001 else: |
1028 return |
1002 return |
1029 |
1003 |
1030 from DataViews.PyCoverageDialog import PyCoverageDialog |
1004 from DataViews.PyCoverageDialog import PyCoverageDialog |
1031 self.codecoverage = PyCoverageDialog() |
1005 self.codecoverage = PyCoverageDialog() |
1032 self.codecoverage.show() |
1006 self.codecoverage.show() |
1033 self.codecoverage.start(pfn, fn) |
1007 self.codecoverage.start(cfn, fn) |
1034 |
1008 |
1035 def __showProfileData(self): |
1009 def __showProfileData(self): |
1036 """ |
1010 """ |
1037 Private method to handle the show profile data context menu action. |
1011 Private method to handle the show profile data context menu action. |
1038 """ |
1012 """ |
1039 itm = self.model().item(self.currentIndex()) |
1013 itm = self.model().item(self.currentIndex()) |
1040 fn = itm.fileName() |
1014 fn = itm.fileName() |
1041 pfn = self.project.getMainScript(True) |
1015 pfn = self.project.getMainScript(True) |
1042 |
1016 |
1043 files = [] |
1017 files = set() |
1044 |
1018 |
1045 if pfn is not None: |
1019 if pfn is not None: |
1046 tpfn = Utilities.getTestFileName(pfn) |
1020 files |= set(Utilities.getProfileFileNames(pfn)) |
1047 basename = os.path.splitext(pfn)[0] |
|
1048 tbasename = os.path.splitext(tpfn)[0] |
|
1049 |
|
1050 f = "{0}.profile".format(basename) |
|
1051 tf = "{0}.profile".format(tbasename) |
|
1052 if os.path.isfile(f): |
|
1053 files.append(f) |
|
1054 if os.path.isfile(tf): |
|
1055 files.append(tf) |
|
1056 |
1021 |
1057 if fn is not None: |
1022 if fn is not None: |
1058 tfn = Utilities.getTestFileName(fn) |
1023 files |= set(Utilities.getProfileFileNames(fn)) |
1059 basename = os.path.splitext(fn)[0] |
1024 |
1060 tbasename = os.path.splitext(tfn)[0] |
1025 if list(files): |
1061 |
|
1062 f = "{0}.profile".format(basename) |
|
1063 tf = "{0}.profile".format(tbasename) |
|
1064 if os.path.isfile(f) and f not in files: |
|
1065 files.append(f) |
|
1066 if os.path.isfile(tf) and tf not in files: |
|
1067 files.append(tf) |
|
1068 |
|
1069 if files: |
|
1070 if len(files) > 1: |
1026 if len(files) > 1: |
1071 pfn, ok = QInputDialog.getItem( |
1027 pfn, ok = QInputDialog.getItem( |
1072 None, |
1028 None, |
1073 self.tr("Profile Data"), |
1029 self.tr("Profile Data"), |
1074 self.tr("Please select a profile file"), |
1030 self.tr("Please select a profile file"), |