eric7/Utilities/__init__.py

branch
eric7-maintenance
changeset 9111
4ac66b6c33a4
parent 9027
f259edcf185a
child 9192
a763d57e23bc
--- a/eric7/Utilities/__init__.py	Mon May 02 15:53:05 2022 +0200
+++ b/eric7/Utilities/__init__.py	Wed Jun 01 13:48:49 2022 +0200
@@ -1304,18 +1304,110 @@
         return volumeDirectory
 
 
-def getTestFileName(fn):
+def getTestFileNames(fn):
     """
-    Function to build the filename of a unittest file.
+    Function to build the potential file names of a test file.
     
-    The filename for the unittest file is built by prepending
-    the string "test" to the filename passed into this function.
+    The file names for the test file is built by prepending the string
+    "test" and "test_" to the file name passed into this function and
+    by appending the string "_test".
     
-    @param fn filename basis to be used for the unittest filename (string)
-    @return filename of the corresponding unittest file (string)
+    @param fn file name basis to be used for the test file names
+    @type str
+    @return file names of the corresponding test file
+    @rtype list of str
     """
     dn, fn = os.path.split(fn)
-    return os.path.join(dn, "test{0}".format(fn))
+    fn, ext = os.psth.splitext(fn)
+    prefixes = ["test", "test_"]
+    postfixes = ["_test"]
+    return [
+        os.path.join(dn, "{0}{1}{2}".format(prefix, fn, ext))
+        for prefix in prefixes
+    ] + [
+        os.path.join(dn, "{0}{1}{2}".format(fn, postfix, ext))
+        for postfix in postfixes
+    ]
+
+
+def getCoverageFileNames(fn):
+    """
+    Function to build a list of coverage data file names.
+    
+    @param fn file name basis to be used for the coverage data file
+    @type str
+    @return list of existing coverage data files
+    @rtype list of str
+    """
+    files = []
+    for filename in [fn, os.path.dirname(fn) + os.sep] + getTestFileNames(fn):
+        f = getCoverageFileName(filename)
+        if f:
+            files.append(f)
+    return files
+
+
+def getCoverageFileName(fn, mustExist=True):
+    """
+    Function to build a file name for a coverage data file.
+    
+    @param fn file name basis to be used for the coverage data file name
+    @type str
+    @param mustExist flag indicating to check that the file exists (defaults
+        to True)
+    @type bool (optional)
+    @return coverage data file name
+    @rtype str
+    """
+    basename = os.path.splitext(fn)[0]
+    filename = "{0}.coverage".format(basename)
+    if mustExist:
+        if os.path.isfile(filename):
+            return filename
+        else:
+            return ""
+    else:
+        return filename
+
+
+def getProfileFileNames(fn):
+    """
+    Function to build a list of profile data file names.
+    
+    @param fn file name basis to be used for the profile data file
+    @type str
+    @return list of existing profile data files
+    @rtype list of str
+    """
+    files = []
+    for filename in [fn, os.path.dirname(fn) + os.sep] + getTestFileNames(fn):
+        f = getProfileFileName(filename)
+        if f:
+            files.append(f)
+    return files
+
+
+def getProfileFileName(fn, mustExist=True):
+    """
+    Function to build a file name for a profile data file.
+    
+    @param fn file name basis to be used for the profile data file name
+    @type str
+    @param mustExist flag indicating to check that the file exists (defaults
+        to True)
+    @type bool (optional)
+    @return profile data file name
+    @rtype str
+    """
+    basename = os.path.splitext(fn)[0]
+    filename = "{0}.profile".format(basename)
+    if mustExist:
+        if os.path.isfile(filename):
+            return filename
+        else:
+            return ""
+    else:
+        return filename
 
 
 def parseOptionString(s):

eric ide

mercurial