Пример #1
0
 def __init__(self, test, stem, standardFile, tmpFile, testInProgress=False, **kw):
     self.stdFile = standardFile
     self.stdCmpFile = self.stdFile
     self.tmpFile = tmpFile
     self.tmpCmpFile = tmpFile
     self.stem = stem
     self.differenceCache = self.SAME
     self.recalculationTime = None
     self.diag = logging.getLogger("FileComparison")
     self.severity = test.getCompositeConfigValue("failure_severity", self.stem)
     self.displayPriority = test.getCompositeConfigValue("failure_display_priority", self.stem)
     maxLength = test.getConfigValue("lines_of_text_difference")
     maxWidth = test.getConfigValue("max_width_text_difference")
     # It would be nice if this could be replaced by some automagic file type detection
     # mechanism, such as the *nix 'file' command, but as the first implementation I've
     # chosen to use a manually created list instead.
     self.binaryFile = test.configValueMatches("binary_file", self.stem)
     self.previewGenerator = plugins.PreviewGenerator(maxWidth, maxLength)
     self.textDiffTool = test.getConfigValue("text_diff_program")
     self.textDiffToolMaxSize = plugins.parseBytes(test.getCompositeConfigValue("max_file_size", self.textDiffTool))
     self.freeTextBody = None
     # subclasses may override if they don't want to store in this way
     self.cacheDifferences(test, testInProgress)
     self.diag.info("Created file comparison std: " + repr(self.stdFile) + " tmp: " +
                    repr(self.tmpFile) + " diff: " + repr(self.differenceCache))
Пример #2
0
    def getConfMessageForFile(self, fileName, associatedObject):
        fileToView = self.getFileToView(fileName, associatedObject)
        if os.path.isfile(fileToView) or os.path.islink(fileToView):
            viewTool = self.getViewToolName(fileToView)
            if viewTool:
                args = (viewTool, fileToView, associatedObject)
                maxFileSize = plugins.parseBytes(self.getConfigValue("max_file_size", viewTool))
                if maxFileSize >= 0:
                    largestFileSize = self.getLargestFileSize(fileToView, associatedObject)
                    if largestFileSize > maxFileSize:
                        message = (
                            "You are trying to view a file of size "
                            + str(largestFileSize)
                            + " bytes, while a limit of "
                            + str(maxFileSize)
                            + " bytes is set for the tool '"
                            + viewTool
                            + "'. Are you sure you wish to continue?"
                        )
                        return message, args

                return "", args
            else:
                raise plugins.TextTestError, "No " + self.getToolDescription() + " is defined for files of type '" + os.path.basename(
                    fileToView
                ).split(
                    "."
                )[
                    0
                ] + "'.\nPlease point the configuration entry '" + self.getToolConfigEntry() + "' at a valid program to view the file."
        else:
            raise plugins.TextTestError, "File '" + os.path.basename(
                fileName
            ) + "' cannot be viewed as it has been removed in the file system." + self.noFileAdvice()