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 filenames = [os.path.splitext(f)[0] |
758 prEnable = ( |
759 for f in [fn] + Utilities.getTestFileNames(fn)] |
759 self.project.isPy3Project() and |
760 prEnable = any([ |
760 bool(Utilities.getProfileFileNames(fn)) |
761 os.path.isfile("{0}.profile".format(f)) |
761 ) |
762 for f in filenames |
|
763 ]) |
|
764 coEnable = ( |
762 coEnable = ( |
765 self.project.isPy3Project() and |
763 self.project.isPy3Project() and |
766 any([ |
764 bool(Utilities.getCoverageFileNames(fn)) |
767 os.path.isfile("{0}.coverage".format(f)) |
|
768 for f in filenames |
|
769 ]) |
|
770 ) |
765 ) |
771 |
766 |
772 # now check the selected item |
767 # now check the selected item |
773 itm = self.model().item(self.currentIndex()) |
768 itm = self.model().item(self.currentIndex()) |
774 fn = itm.fileName() |
769 fn = itm.fileName() |
775 if fn is not None: |
770 if fn is not None: |
776 basename = os.path.splitext(fn)[0] |
771 prEnable |= ( |
777 prEnable = ( |
772 itm.isPython3File() and |
778 prEnable or |
773 bool(Utilities.getProfileFileNames(fn)) |
779 os.path.isfile("{0}.profile".format(basename)) |
|
780 ) |
774 ) |
781 coEnable = ( |
775 coEnable |= ( |
782 (coEnable or |
776 itm.isPython3File() and |
783 os.path.isfile("{0}.coverage".format(basename))) and |
777 bool(Utilities.getCoverageFileName(fn)) |
784 itm.isPython3File() |
|
785 ) |
778 ) |
786 |
779 |
787 self.profileMenuAction.setEnabled(prEnable) |
780 self.profileMenuAction.setEnabled(prEnable) |
788 self.coverageMenuAction.setEnabled(coEnable) |
781 self.coverageMenuAction.setEnabled(coEnable) |
789 |
782 |
983 """ |
976 """ |
984 itm = self.model().item(self.currentIndex()) |
977 itm = self.model().item(self.currentIndex()) |
985 fn = itm.fileName() |
978 fn = itm.fileName() |
986 pfn = self.project.getMainScript(True) |
979 pfn = self.project.getMainScript(True) |
987 |
980 |
988 files = [] |
981 files = set() |
989 |
982 |
990 if pfn is not None: |
983 if pfn is not None: |
991 for filename in [pfn] + Utilities.getTestFileNames(pfn): |
984 files |= set(Utilities.getCoverageFileNames(pfn)) |
992 basename = os.path.splitext(filename)[0] |
|
993 f = "{0}.coverage".format(basename) |
|
994 if os.path.isfile(f): |
|
995 files.append(f) |
|
996 |
985 |
997 if fn is not None: |
986 if fn is not None: |
998 for filename in [fn] + Utilities.getTestFileNames(fn): |
987 files |= set(Utilities.getCoverageFileNames(fn)) |
999 basename = os.path.splitext(filename)[0] |
988 |
1000 f = "{0}.coverage".format(basename) |
989 if list(files): |
1001 if os.path.isfile(f): |
|
1002 files.append(f) |
|
1003 |
|
1004 if files: |
|
1005 if len(files) > 1: |
990 if len(files) > 1: |
1006 pfn, ok = QInputDialog.getItem( |
991 cfn, ok = QInputDialog.getItem( |
1007 None, |
992 None, |
1008 self.tr("Code Coverage"), |
993 self.tr("Code Coverage"), |
1009 self.tr("Please select a coverage file"), |
994 self.tr("Please select a coverage file"), |
1010 files, |
995 files, |
1011 0, False) |
996 0, False) |
1012 if not ok: |
997 if not ok: |
1013 return |
998 return |
1014 else: |
999 else: |
1015 pfn = files[0] |
1000 cfn = files[0] |
1016 else: |
1001 else: |
1017 return |
1002 return |
1018 |
1003 |
1019 from DataViews.PyCoverageDialog import PyCoverageDialog |
1004 from DataViews.PyCoverageDialog import PyCoverageDialog |
1020 self.codecoverage = PyCoverageDialog() |
1005 self.codecoverage = PyCoverageDialog() |
1021 self.codecoverage.show() |
1006 self.codecoverage.show() |
1022 self.codecoverage.start(pfn, fn) |
1007 self.codecoverage.start(cfn, fn) |
1023 |
1008 |
1024 def __showProfileData(self): |
1009 def __showProfileData(self): |
1025 """ |
1010 """ |
1026 Private method to handle the show profile data context menu action. |
1011 Private method to handle the show profile data context menu action. |
1027 """ |
1012 """ |
1028 itm = self.model().item(self.currentIndex()) |
1013 itm = self.model().item(self.currentIndex()) |
1029 fn = itm.fileName() |
1014 fn = itm.fileName() |
1030 pfn = self.project.getMainScript(True) |
1015 pfn = self.project.getMainScript(True) |
1031 |
1016 |
1032 files = [] |
1017 files = set() |
1033 |
1018 |
1034 if pfn is not None: |
1019 if pfn is not None: |
1035 for filename in [pfn] + Utilities.getTestFileNames(pfn): |
1020 files |= set(Utilities.getProfileFileNames(pfn)) |
1036 basename = os.path.splitext(filename)[0] |
|
1037 f = "{0}.profile".format(basename) |
|
1038 if os.path.isfile(f): |
|
1039 files.append(f) |
|
1040 |
1021 |
1041 if fn is not None: |
1022 if fn is not None: |
1042 for filename in [fn] + Utilities.getTestFileNames(fn): |
1023 files |= set(Utilities.getProfileFileNames(fn)) |
1043 basename = os.path.splitext(filename)[0] |
1024 |
1044 f = "{0}.profile".format(basename) |
1025 if list(files): |
1045 if os.path.isfile(f): |
|
1046 files.append(f) |
|
1047 |
|
1048 if files: |
|
1049 if len(files) > 1: |
1026 if len(files) > 1: |
1050 pfn, ok = QInputDialog.getItem( |
1027 pfn, ok = QInputDialog.getItem( |
1051 None, |
1028 None, |
1052 self.tr("Profile Data"), |
1029 self.tr("Profile Data"), |
1053 self.tr("Please select a profile file"), |
1030 self.tr("Please select a profile file"), |