Example #1
0
def gold_diff(filename, allowed=0.95):
    path = os.path.abspath(filename)
    filename_only = os.path.basename(path)
    base_dir = os.path.dirname(path)
    goldname = os.path.join(base_dir, "gold", filename_only)
    differ = ImageDiffer(goldname, path, allowed=allowed)
    print(differ.message())
    return differ.fail()
Example #2
0
def gold_diff(filename, allowed=0.95):
    path = os.path.abspath(filename)
    filename_only = os.path.basename(path)
    base_dir = os.path.dirname(path)
    goldname = os.path.join(base_dir, "gold", filename_only)
    differ = ImageDiffer(goldname, path, allowed=allowed)
    print(differ.message())
    return differ.fail()
Example #3
0
    def assertImage(self, basename, allowed=0.99, **kwargs):
        """
        Create the supplied image and assert that it is same to the gold standard.
        """
        filename = type(self).filename(basename)
        goldname = os.path.join('gold', filename)

        self.write(filename, **kwargs)
        differ = ImageDiffer(goldname, filename, allowed=allowed)
        print differ.message()
        self.assertFalse(differ.fail(), "{} does not match the gold file.".format(filename))
Example #4
0
    def assertImage(self, basename, allowed=0.97, **kwargs):
        """
        Create the supplied image and assert that it is same to the gold standard.
        """
        filename = type(self).filename(basename)
        goldname = os.path.join('gold', filename)

        self.write(filename, **kwargs)
        differ = ImageDiffer(goldname, filename, allowed=allowed)
        print(differ.message())
        self.assertFalse(differ.fail(), "{} does not match the gold file.".format(filename))
    def processResults(self, moose_dir, retcode, options, output):
        """
        Perform image diff
        """

        # Call base class processResults
        output = FileTester.processResults(self, moose_dir, retcode, options,
                                           output)
        if self.getStatus() == self.bucket_fail:
            return output

        # Loop through files
        specs = self.specs
        for filename in specs['imagediff']:

            # Error if gold file does not exist
            if not os.path.exists(
                    os.path.join(specs['test_dir'], specs['gold_dir'],
                                 filename)):
                output += "File Not Found: " + os.path.join(
                    specs['test_dir'], specs['gold_dir'], filename)
                self.setStatus('MISSING GOLD FILE', self.bucket_fail)
                break

            # Perform diff
            else:
                output = 'Running ImageDiffer.py'
                gold = os.path.join(specs['test_dir'], specs['gold_dir'],
                                    filename)
                test = os.path.join(specs['test_dir'], filename)

                if sys.platform in ['linux', 'linux2']:
                    name = 'allowed_linux'
                elif sys.platform == 'darwin':
                    name = 'allowed_darwin'
                allowed = specs[name] if specs.isValid(
                    name) else specs['allowed']
                differ = ImageDiffer(gold, test, allowed=allowed)

                # Update golds (e.g., uncomment this to re-gold for new system or new defaults)
                #import shutil; shutil.copy(test, gold)

                output += differ.message()
                if differ.fail():
                    self.setStatus('IMAGEDIFF', self.bucket_diff)
                    break

        # If status is still pending, then it is a passing test
        if self.getStatus() == self.bucket_pending:
            self.setStatus(self.success_message, self.bucket_success)

        return output
Example #6
0
    def processResults(self, moose_dir, options, output):
        """
        Perform image diff
        """

        # Call base class processResults
        FileTester.processResults(self, moose_dir, options, output)
        if self.getStatus() == self.bucket_fail:
            return output

        # Loop through files
        specs = self.specs
        for filename in specs['imagediff']:

            # Error if gold file does not exist
            if not os.path.exists(os.path.join(specs['test_dir'], specs['gold_dir'], filename)):
                output += "File Not Found: " + os.path.join(specs['test_dir'], specs['gold_dir'], filename)
                self.setStatus('MISSING GOLD FILE', self.bucket_fail)
                break

            # Perform diff
            else:
                output = 'Running ImageDiffer.py'
                gold = os.path.join(specs['test_dir'], specs['gold_dir'], filename)
                test = os.path.join(specs['test_dir'], filename)

                if sys.platform in ['linux', 'linux2']:
                    name = 'allowed_linux'
                elif sys.platform == 'darwin':
                    name = 'allowed_darwin'
                allowed = specs[name] if specs.isValid(name) else specs['allowed']
                differ = ImageDiffer(gold, test, allowed=allowed)

                # Update golds (e.g., uncomment this to re-gold for new system or new defaults)
                #import shutil; shutil.copy(test, gold)

                output += differ.message()
                if differ.fail():
                    self.setStatus('IMAGEDIFF', self.bucket_diff)
                    break

        # If status is still pending, then it is a passing test
        if self.getStatus() == self.bucket_pending:
            self.setStatus(self.success_message, self.bucket_success)

        return output