コード例 #1
0
ファイル: test_binary.py プロジェクト: iskey/diffoscope
def test_with_compare_details_and_fallback():
    class MockFile(FilesystemFile):
        def compare_details(self, other, source=None):
            return []

    difference = MockFile(TEST_FILE1_PATH).compare(MockFile(TEST_FILE2_PATH))
    expected_diff = get_data('binary_expected_diff')
    assert 'yet data differs' in difference.comment
    assert normalize_zeros(difference.unified_diff) == expected_diff
コード例 #2
0
ファイル: test_binary.py プロジェクト: iskey/diffoscope
def test_with_compare_details_and_tool_not_found(monkeypatch):
    monkeypatch.setattr('diffoscope.exc.RequiredToolNotFound.get_package',
                        lambda _: 'some-package')

    class MockFile(FilesystemFile):
        @tool_required('nonexistent')
        def compare_details(self, other, source=None):
            raise Exception('should not be run')

    difference = MockFile(TEST_FILE1_PATH).compare(MockFile(TEST_FILE2_PATH))
    expected_diff = get_data('binary_expected_diff')
    assert 'nonexistent' in difference.comment
    assert 'some-package' in difference.comment
    assert normalize_zeros(difference.unified_diff) == expected_diff
コード例 #3
0
ファイル: test_binary.py プロジェクト: iskey/diffoscope
def test_with_compare_details_and_failed_process():
    output = 'Free Jeremy Hammond'

    class MockFile(FilesystemFile):
        def compare_details(self, other, source=None):
            subprocess.check_output(
                ['sh', '-c', 'echo "%s"; exit 42' % output], shell=False)
            raise Exception('should not be run')

    difference = MockFile(TEST_FILE1_PATH).compare(MockFile(TEST_FILE2_PATH))
    expected_diff = get_data('../data/binary_expected_diff')
    assert output in difference.comment
    assert '42' in difference.comment
    assert normalize_zeros(difference.unified_diff) == expected_diff
コード例 #4
0
def test_fallback_comparison(monkeypatch):
    manager = ComparatorManager()
    monkeypatch.setattr(manager, 'COMPARATORS', (('rpm_fallback.RpmFile', ), ))
    manager.reload()

    # Re-specialize after reloading our Comparators
    rpm1 = specialize(FilesystemFile(data('test1.rpm')))
    rpm2 = specialize(FilesystemFile(data('test2.rpm')))

    assert rpm1.compare(rpm1) is None
    assert rpm2.compare(rpm2) is None

    expected_diff = get_data('rpm_fallback_expected_diff')
    assert normalize_zeros(rpm1.compare(rpm2).unified_diff) == expected_diff
コード例 #5
0
def test_diff_reverse(differences_reverse):
    expected_diff = get_data('device_expected_diff_reverse')
    assert normalize_zeros(differences_reverse.unified_diff) == expected_diff
コード例 #6
0
def test_diff(differences):
    expected_diff = get_data('device_expected_diff')
    assert normalize_zeros(differences.unified_diff) == expected_diff
コード例 #7
0
ファイル: test_binary.py プロジェクト: iskey/diffoscope
def test_compare_with_xxd(binary1, binary2):
    difference = binary1.compare_bytes(binary2)
    expected_diff = get_data('binary_expected_diff')
    assert normalize_zeros(difference.unified_diff) == expected_diff