def METHOD_NAME( filename, this_path = '.' ):
    import filecmp
    result_file = os.path.join(this_path, 'result', filename)
    expected_file = os.path.join(this_path, 'expected', filename)
    try:
        os.stat( result_file )
    except OSError:
        return 'noresult'
    try:
        os.stat( expected_file )
    except OSError:
        return 'noexpected'
    # netCDF files contain a NC_GLOBAL#history that contains a datetime.
    # Binary comparison can't work
    if not expected_file.endswith('.nc'):
        if filecmp.cmp(expected_file,result_file,0):
            return 'match'
        expected_file_alternative = expected_file + ".alternative"
        if os.path.exists( expected_file_alternative ):
            if filecmp.cmp(expected_file_alternative,result_file,0):
                return 'match'
        if expected_file[-4:] == '.xml':
            return 'nomatch'
    ###################################################################
    # Check image checksums with GDAL if it is available.
    try:
        from osgeo import gdal
        gdal.VersionInfo(None) # make pyflakes happy
        has_gdal = True
    except:
        has_gdal = False
    if has_gdal:
        ret = check_with_gdal(result_file, expected_file)
        if ret != 'nomatch':
            return ret
        expected_file_alternative = expected_file + ".alternative"
        if os.path.exists( expected_file_alternative ):
            ret = check_with_gdal(result_file, expected_file_alternative)
            if ret != 'nomatch':
                return ret
    ###################################################################
    # Test with perceptualdiff if this is tiff or png.  If we discover
    # we don't have it, then set have_pdiff to 'false' so we will know.
    global have_pdiff
    try:
        result = open(result_file, "rb").read(1000)
    except:
        result = ''
    from sys import version_info
    if version_info >= (3,0,0):
        result = str(result, 'iso-8859-1')
    run_perceptualdiff = have_pdiff != 'false' and \
            ('\x49\x49\x2A\x00' in result \
            or '\x49\x49\x00\x2A' in result \
            or '\x47\x49\x46\x38\x37\x61' in result \
            or '\x89\x50\x4e\x47\x0d\x0a\x1a\x0a' in result)
    if run_perceptualdiff:
        # Skip to real image if there's some HTTP headers before
        tmp_result_file = strip_headers(result_file)
        if tmp_result_file is not None:
            result_file = tmp_result_file
        tmp_expected_file = strip_headers(expected_file)
        if tmp_expected_file is not None:
            expected_file = tmp_expected_file
        try:
            cmd = 'perceptualdiff %s %s -verbose > pd.out 2>&1 ' % (result_file,expected_file)
            os.system( cmd )
            pdout = open('pd.out').read()
            os.remove( 'pd.out' )
        except:
            pdout = ''
            pass
        if tmp_result_file is not None:
            os.remove(tmp_result_file)
        if tmp_expected_file is not None:
            os.remove(tmp_expected_file)
        if pdout.find('PASS:') != -1 \
            and pdout.find('binary identical') != -1:
            return 'files_differ_image_match'
        if pdout.find('PASS:') != -1 \
            and pdout.find('indistinguishable') != -1:
            return 'files_differ_image_nearly_match'
        if pdout.find('PASS:') == -1 \
            and pdout.find('FAIL:') == -1:
            have_pdiff = 'false'
    return 'nomatch'