eric7/QScintilla/Editor.py

branch
unittest
changeset 9072
8d3ae97ee666
parent 9070
eab09a1ab8ce
child 9092
043848f65726
--- a/eric7/QScintilla/Editor.py	Tue May 17 17:23:07 2022 +0200
+++ b/eric7/QScintilla/Editor.py	Wed May 18 08:43:36 2022 +0200
@@ -5632,37 +5632,35 @@
         ):
             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))
-                )
+                filenames = [os.path.splitext(f)[0]
+                             for f in [fn] + Utilities.getTestFileNames(fn)]
+                prEnable = any([
+                    os.path.isfile("{0}.profile".format(f))
+                    for f in filenames
+                ])
                 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
+                    any([
+                        os.path.isfile("{0}.coverage".format(f))
+                        for f in filenames
+                    ])
                 )
         
         # now check ourselves
         fn = self.getFileName()
         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))
-            )
-            coEnable = (
-                (coEnable or
-                 os.path.isfile("{0}.coverage".format(basename)) or
-                 os.path.isfile("{0}.coverage".format(tbasename))) and
-                self.isPyFile()
+            filenames = [os.path.splitext(f)[0]
+                         for f in [fn] + Utilities.getTestFileNames(fn)]
+            prEnable |= any([
+                os.path.isfile("{0}.profile".format(f))
+                for f in filenames
+            ])
+            coEnable |= (
+                self.project.isPy3Project() and
+                any([
+                    os.path.isfile("{0}.coverage".format(f))
+                    for f in filenames
+                ])
             )
         
         coEnable |= bool(self.__coverageFile)
@@ -6069,30 +6067,23 @@
         ):
             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]
-                
-                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)
+                for filename in [fn] + Utilities.getTestFileNames(fn):
+                    basename = os.path.splitext(filename)[0]
+                    f = "{0}.coverage".format(basename)
+                    if os.path.isfile(f):
+                        files.append(f)
         
         # now check, if there are coverage files belonging to ourselves
         fn = self.getFileName()
         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)
+            for filename in [fn] + Utilities.getTestFileNames(fn):
+                basename = os.path.splitext(filename)[0]
+                f = "{0}.coverage".format(basename)
+                if os.path.isfile(f):
+                    files.append(f)
+        
+        # make the list unique
+        files = list(set(files))
         
         if files:
             if len(files) > 1:
@@ -6261,30 +6252,23 @@
         ):
             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]
-                
-                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)
+                for filename in [fn] + Utilities.getTestFileNames(fn):
+                    basename = os.path.splitext(filename)[0]
+                    f = "{0}.profile".format(basename)
+                    if os.path.isfile(f):
+                        files.append(f)
         
         # now check, if there are profile files belonging to ourselves
         fn = self.getFileName()
         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)
+            for filename in [fn] + Utilities.getTestFileNames(fn):
+                basename = os.path.splitext(filename)[0]
+                f = "{0}.profile".format(basename)
+                if os.path.isfile(f):
+                    files.append(f)
+        
+        # make the list unique
+        files = list(set(files))
         
         if files:
             if len(files) > 1:

eric ide

mercurial