コード例 #1
0
ファイル: test_text.py プロジェクト: dezgeg/debbindiff
def test_difference_in_ascii():
    text1 = os.path.join(os.path.dirname(__file__), '../data/text_ascii1')
    text2 = os.path.join(os.path.dirname(__file__), '../data/text_ascii2')
    difference = compare_text_files(text1, text2)
    assert difference is not None
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
    assert difference.unified_diff == expected_diff
    assert difference.comment is None
    assert len(difference.details) == 0
コード例 #2
0
def compare_unknown(path1, path2, source=None):
    logger.debug("compare unknown path: %s and %s", path1, path2)
    mime_type1 = guess_mime_type(path1)
    mime_type2 = guess_mime_type(path2)
    logger.debug("mime_type1: %s | mime_type2: %s", mime_type1, mime_type2)
    if mime_type1.startswith('text/') and mime_type2.startswith('text/'):
        encodings1 = re.findall(r'; charset=([^ ]+)', mime_type1)
        encodings2 = re.findall(r'; charset=([^ ]+)', mime_type2)
        if len(encodings1) > 0 and encodings1 == encodings2:
            encoding = encodings1[0]
        else:
            encoding = None
        return compare_text_files(path1, path2, encoding, source)
    return compare_binary_files(path1, path2, source)
コード例 #3
0
ファイル: __init__.py プロジェクト: yashi/debbindiff
def compare_unknown(path1, path2, source=None):
    logger.debug("compare unknown path: %s and %s", path1, path2)
    mime_type1 = guess_mime_type(path1)
    mime_type2 = guess_mime_type(path2)
    logger.debug("mime_type1: %s | mime_type2: %s", mime_type1, mime_type2)
    if mime_type1.startswith('text/') and mime_type2.startswith('text/'):
        encodings1 = re.findall(r'; charset=([^ ]+)', mime_type1)
        encodings2 = re.findall(r'; charset=([^ ]+)', mime_type2)
        if len(encodings1) > 0 and encodings1 == encodings2:
            encoding = encodings1[0]
        else:
            encoding = None
        return compare_text_files(path1, path2, encoding, source)
    return compare_binary_files(path1, path2, source)
コード例 #4
0
ファイル: test_text.py プロジェクト: dezgeg/debbindiff
def test_difference_between_iso88591_and_unicode():
    text1 = os.path.join(os.path.dirname(__file__), '../data/text_unicode1')
    text2 = os.path.join(os.path.dirname(__file__), '../data/text_iso8859')
    difference = compare_text_files(text1, text2)
    expected_diff = codecs.open(os.path.join(os.path.dirname(__file__), '../data/text_iso8859_expected_diff'), encoding='utf-8').read()
    assert differences.unified_diff == expected_diff
コード例 #5
0
ファイル: test_text.py プロジェクト: dezgeg/debbindiff
def test_fallback_to_binary():
    text1 = os.path.join(os.path.dirname(__file__), '../data/text_unicode1')
    text2 = os.path.join(os.path.dirname(__file__), '../data/text_unicode2')
    difference = compare_text_files(text1, text2, encoding='ascii')
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_unicode_binary_fallback')).read()
    assert difference.unified_diff == expected_diff
コード例 #6
0
ファイル: test_text.py プロジェクト: dezgeg/debbindiff
def test_no_differences():
    text1 = os.path.join(os.path.dirname(__file__), '../data/text_ascii1')
    text2 = os.path.join(os.path.dirname(__file__), '../data/text_ascii1')
    assert compare_text_files(text1, text2) is None