eric7/Project/ProjectSourcesBrowser.py

branch
eric7-maintenance
changeset 9111
4ac66b6c33a4
parent 8881
54e42bc2437a
child 9192
a763d57e23bc
diff -r 2b9bd8f97576 -r 4ac66b6c33a4 eric7/Project/ProjectSourcesBrowser.py
--- a/eric7/Project/ProjectSourcesBrowser.py	Mon May 02 15:53:05 2022 +0200
+++ b/eric7/Project/ProjectSourcesBrowser.py	Wed Jun 01 13:48:49 2022 +0200
@@ -161,8 +161,8 @@
             self.tr('Coverage run of Script...'),
             self.__contextMenuCoverageScript)
         
-        self.unittestAction = self.sourceMenu.addAction(
-            self.tr('Run unittest...'), self.handleUnittest)
+        self.testingAction = self.sourceMenu.addAction(
+            self.tr('Run tests...'), self.handleTesting)
         self.sourceMenu.addSeparator()
         act = self.sourceMenu.addAction(
             self.tr('Rename file'), self._renameFile)
@@ -646,7 +646,7 @@
                                         act.setEnabled(False)
                                     self.classDiagramAction.setEnabled(True)
                                     self.importsDiagramAction.setEnabled(True)
-                                    self.unittestAction.setEnabled(False)
+                                    self.testingAction.setEnabled(False)
                                     self.checksMenu.menuAction().setEnabled(
                                         False)
                                 elif fn.endswith('.rb'):
@@ -655,14 +655,14 @@
                                         act.setEnabled(False)
                                     self.classDiagramAction.setEnabled(True)
                                     self.importsDiagramAction.setEnabled(False)
-                                    self.unittestAction.setEnabled(False)
+                                    self.testingAction.setEnabled(False)
                                     self.checksMenu.menuAction().setEnabled(
                                         False)
                                 elif fn.endswith('.js'):
                                     # entry for mixed mode programs
                                     for act in self.sourceMenuActions.values():
                                         act.setEnabled(False)
-                                    self.unittestAction.setEnabled(False)
+                                    self.testingAction.setEnabled(False)
                                     self.checksMenu.menuAction().setEnabled(
                                         False)
                                     self.graphicsMenu.menuAction().setEnabled(
@@ -673,7 +673,7 @@
                                         act.setEnabled(True)
                                     self.classDiagramAction.setEnabled(True)
                                     self.importsDiagramAction.setEnabled(True)
-                                    self.unittestAction.setEnabled(True)
+                                    self.testingAction.setEnabled(True)
                                     self.checksMenu.menuAction().setEnabled(
                                         True)
                             self.sourceMenu.popup(self.mapToGlobal(coord))
@@ -755,34 +755,26 @@
         # a project coverage file
         fn = self.project.getMainScript(True)
         if fn is not None:
-            tfn = Utilities.getTestFileName(fn)
-            basename = os.path.splitext(fn)[0]
-            tbasename = os.path.splitext(tfn)[0]
             prEnable = (
-                prEnable or
-                os.path.isfile("{0}.profile".format(basename)) or
-                os.path.isfile("{0}.profile".format(tbasename))
+                self.project.isPy3Project() and
+                bool(Utilities.getProfileFileNames(fn))
             )
             coEnable = (
-                (coEnable or
-                 os.path.isfile("{0}.coverage".format(basename)) or
-                 os.path.isfile("{0}.coverage".format(tbasename))) and
-                self.project.isPy3Project()
+                self.project.isPy3Project() and
+                bool(Utilities.getCoverageFileNames(fn))
             )
         
         # now check the selected item
         itm = self.model().item(self.currentIndex())
         fn = itm.fileName()
         if fn is not None:
-            basename = os.path.splitext(fn)[0]
-            prEnable = (
-                prEnable or
-                os.path.isfile("{0}.profile".format(basename))
+            prEnable |= (
+                itm.isPython3File() and
+                bool(Utilities.getProfileFileNames(fn))
             )
-            coEnable = (
-                (coEnable or
-                 os.path.isfile("{0}.coverage".format(basename))) and
-                itm.isPython3File()
+            coEnable |= (
+                itm.isPython3File() and
+                bool(Utilities.getCoverageFileName(fn))
             )
         
         self.profileMenuAction.setEnabled(prEnable)
@@ -986,35 +978,17 @@
         fn = itm.fileName()
         pfn = self.project.getMainScript(True)
         
-        files = []
+        files = set()
         
         if pfn is not None:
-            tpfn = Utilities.getTestFileName(pfn)
-            basename = os.path.splitext(pfn)[0]
-            tbasename = os.path.splitext(tpfn)[0]
-            
-            f = "{0}.coverage".format(basename)
-            tf = "{0}.coverage".format(tbasename)
-            if os.path.isfile(f):
-                files.append(f)
-            if os.path.isfile(tf):
-                files.append(tf)
+            files |= set(Utilities.getCoverageFileNames(pfn))
         
         if fn is not None:
-            tfn = Utilities.getTestFileName(fn)
-            basename = os.path.splitext(fn)[0]
-            tbasename = os.path.splitext(tfn)[0]
-            
-            f = "{0}.coverage".format(basename)
-            tf = "{0}.coverage".format(tbasename)
-            if os.path.isfile(f) and f not in files:
-                files.append(f)
-            if os.path.isfile(tf) and tf not in files:
-                files.append(tf)
+            files |= set(Utilities.getCoverageFileNames(fn))
         
-        if files:
+        if list(files):
             if len(files) > 1:
-                pfn, ok = QInputDialog.getItem(
+                cfn, ok = QInputDialog.getItem(
                     None,
                     self.tr("Code Coverage"),
                     self.tr("Please select a coverage file"),
@@ -1023,14 +997,14 @@
                 if not ok:
                     return
             else:
-                pfn = files[0]
+                cfn = files[0]
         else:
             return
         
         from DataViews.PyCoverageDialog import PyCoverageDialog
         self.codecoverage = PyCoverageDialog()
         self.codecoverage.show()
-        self.codecoverage.start(pfn, fn)
+        self.codecoverage.start(cfn, fn)
     
     def __showProfileData(self):
         """
@@ -1040,33 +1014,15 @@
         fn = itm.fileName()
         pfn = self.project.getMainScript(True)
         
-        files = []
+        files = set()
         
         if pfn is not None:
-            tpfn = Utilities.getTestFileName(pfn)
-            basename = os.path.splitext(pfn)[0]
-            tbasename = os.path.splitext(tpfn)[0]
-            
-            f = "{0}.profile".format(basename)
-            tf = "{0}.profile".format(tbasename)
-            if os.path.isfile(f):
-                files.append(f)
-            if os.path.isfile(tf):
-                files.append(tf)
+            files |= set(Utilities.getProfileFileNames(pfn))
         
         if fn is not None:
-            tfn = Utilities.getTestFileName(fn)
-            basename = os.path.splitext(fn)[0]
-            tbasename = os.path.splitext(tfn)[0]
-            
-            f = "{0}.profile".format(basename)
-            tf = "{0}.profile".format(tbasename)
-            if os.path.isfile(f) and f not in files:
-                files.append(f)
-            if os.path.isfile(tf) and tf not in files:
-                files.append(tf)
-                
-        if files:
+            files |= set(Utilities.getProfileFileNames(fn))
+        
+        if list(files):
             if len(files) > 1:
                 pfn, ok = QInputDialog.getItem(
                     None,

eric ide

mercurial