testsuite.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码
def _finddifference(self, casedirpath):

        # Get the full output and reference paths
        outpath = os.path.join(casedirpath, "out")
        refpath = os.path.join(casedirpath, "ref")

        # Check for the presence of the reference directory
        if not os.path.isdir(refpath): return "Test case has no reference directory"

        # Initialize lists to contain the extra files, missing files and differing files
        extra = []
        missing = []
        differ = []

        # Verify list of filenames
        if len(filter(lambda fn: os.path.isdir(fn), os.listdir(outpath))) > 0: return "Output contains a directory"
        dircomp = filecmp.dircmp(outpath, refpath, ignore=['.DS_Store'])

        # Create a list of files that were not present in the reference directory
        for file in dircomp.left_only: extra.append(file)

        # Create a list of files that are missing from the output directory
        for file in dircomp.right_only: missing.append(file)

        # Compare files, focusing on those that aren't trivially equal.
        matches, mismatches, errors = filecmp.cmpfiles(outpath, refpath, dircomp.common, shallow=False)

        for filename in mismatches + errors:

            reffile = os.path.join(refpath, filename)
            outfile = os.path.join(outpath, filename)

            # For a soft comparison between files, check if both files are similar enough
            if self._parallel:
                if not similarfiles(reffile, outfile): differ.append(filename)

            # In the other case, check if both files are equal (except for potential timestamps)
            else:
                if not equalfiles(reffile, outfile): differ.append(filename)

        # Return the list of extra files, the list of missing files and the list of differing files
        return extra, missing, differ

# -----------------------------------------------------------------

# This functions searches for directories within a certain parent directories that have a specific name
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号