Source code for schrodinger.test.stu.outcomes.custom.perceptual_diff

"""
Contains the workup is `perceptual_diff`

@copyright: Schrodinger, LLC. All rights reserved.
"""

import os
import socket
import sys

from schrodinger.test.stu import common
from schrodinger.test.stu.outcomes.standard_workups import WorkupFailure
from schrodinger.utils import subprocess

logger = common.logger


def _get_perceptual_diff_loc():
    perceptualdiff = 'perceptualdiff'
    platform = sys.platform.lower()
    if platform.startswith('win'):
        platform = 'WIN32-x86'
        perceptualdiff += '.exe'
    elif 'darwin' in platform:
        platform = 'Darwin-x86_64'
    else:
        platform = 'Linux-x86_64'
    return os.path.join(os.environ['SCHRODINGER_LIB'], platform,
                        'perceptualdiff-1.1.1', perceptualdiff)


[docs]def perceptual_diff(std_image, test_image): """ Run Perceptual Diff to compare a test image to a standard. The workup requires access to the shared installation of Perceptual Diff in /nfs/software/lib/<platform>/. It expects host-specific std images to be located in a subdirectory of the test named references/<hostname>/. For example, for the host pdx-desk-l03.schrodinger.com, refeerences are expected in stu_<testid>/references/pdx-desk-l03.schrodinger.com/. usage: custom.perceptual_diff.perceptual_diff(std_image, test_image) """ test_image_full_path = os.path.join(os.getcwd(), test_image) std_image_full_path = os.path.join(os.getcwd(), 'references', socket.gethostname(), std_image) if not os.path.isfile(test_image_full_path): raise WorkupFailure('Could not find test file: ' '{}'.format(test_image_full_path)) elif not os.path.isfile(std_image_full_path): raise WorkupFailure('Could not find reference file: ' '{}'.format(std_image_full_path)) else: per_diff = _get_perceptual_diff_loc() per_diff_cmd = [per_diff, std_image_full_path, test_image_full_path] try: exit_code = subprocess.call(per_diff_cmd) except Exception as err: raise WorkupFailure('ERROR: Perceptual Diff failed ' 'with error {}'.format(err)) if exit_code == 0: return True else: raise WorkupFailure('Perceptual Diff comparison failed. {} does ' 'not match {}'.format(std_image_full_path, test_image_full_path))