Esempio n. 1
0
def test_fallback_comparisons(monkeypatch):
    manager = ComparatorManager()
    monkeypatch.setattr(
        manager,
        'COMPARATORS',
        (
            ('debian_fallback.DotChangesFile', ),
            ('debian_fallback.DotDscFile', ),
            ('debian_fallback.DotBuildinfoFile', ),
        ),
    )
    manager.reload()

    for a, b, expected_diff in (
        (
            'test1.changes',
            'test2.changes',
            'dot_changes_fallback_expected_diff',
        ),
        ('test1.dsc', 'test2.dsc', 'dot_dsc_fallback_expected_diff'),
        (
            'test1.buildinfo',
            'test2.buildinfo',
            'dot_buildinfo_fallback_expected_diff',
        ),
    ):
        # Re-specialize after reloading our Comparators
        file1 = specialize(FilesystemFile(data(a)))
        file2 = specialize(FilesystemFile(data(b)))

        assert file1.compare(file1) is None
        assert file2.compare(file2) is None
        assert file1.compare(file2).unified_diff == get_data(expected_diff)
Esempio n. 2
0
def test_compare_to_symlink(tmpdir):
    path = str(tmpdir.join('src'))
    os.symlink('/etc/passwd', path)

    a = specialize(FilesystemFile(str(tmpdir.mkdir('dir'))))
    b = specialize(FilesystemFile(path))

    assert a.compare(b).unified_diff == get_data('test_directory_symlink_diff')
Esempio n. 3
0
def test_content_source_without_extension(tmpdir, gzip1, gzip2):
    path1 = str(tmpdir.join('test1'))
    path2 = str(tmpdir.join('test2'))
    shutil.copy(gzip1.path, path1)
    shutil.copy(gzip2.path, path2)
    gzip1 = specialize(FilesystemFile(path1))
    gzip2 = specialize(FilesystemFile(path2))
    difference = gzip1.compare(gzip2).details
    assert difference[1].source1 == 'test1-content'
    assert difference[1].source2 == 'test2-content'
Esempio n. 4
0
def test_compare_to_file(tmpdir):
    path = str(tmpdir.join('file'))

    with open(path, 'w') as f:
        f.write("content")

    a = specialize(FilesystemFile(str(tmpdir.mkdir('dir'))))
    b = specialize(FilesystemFile(path))

    assert a.compare(b).unified_diff == get_data('test_directory_file_diff')
Esempio n. 5
0
def test_content_source_without_extension(tmpdir, xz1, xz2):
    path1 = str(tmpdir.join('test1'))
    path2 = str(tmpdir.join('test2'))
    shutil.copy(xz1.path, path1)
    shutil.copy(xz2.path, path2)
    xz1 = specialize(FilesystemFile(path1))
    xz2 = specialize(FilesystemFile(path2))
    difference = xz1.compare(xz2).details
    assert difference[0].source1 == 'test1-content'
    assert difference[0].source2 == 'test2-content'
Esempio n. 6
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
Esempio n. 7
0
def dot_changes4(tmpdir):
    tmpdir.mkdir('d')
    dot_changes_path = str(tmpdir.join('d/test_4.changes'))
    shutil.copy(TEST_DOT_CHANGES_FILE4_PATH, dot_changes_path)
    shutil.copy(TEST_DEB_FILE2_PATH, str(tmpdir.join('d/test_1_all.deb')))
    shutil.copy(TEST_DOT_BUILDINFO_FILE1_PATH, str(tmpdir.join('d/test_2.buildinfo')))
    return specialize(FilesystemFile(dot_changes_path))
Esempio n. 8
0
def test_dot_buildinfo_invalid(tmpdir):
    tmpdir.mkdir('a')
    dot_buildinfo_path = str(tmpdir.join('a/test_1.buildinfo'))
    shutil.copy(TEST_DOT_BUILDINFO_FILE1_PATH, dot_buildinfo_path)
    # we don't copy the referenced .deb
    identified = specialize(FilesystemFile(dot_buildinfo_path))
    assert not isinstance(identified, DotBuildinfoFile)
Esempio n. 9
0
def dot_buildinfo2(tmpdir):
    tmpdir.mkdir('b')
    dot_buildinfo_path = str(tmpdir.join('b/test_1.buildinfo'))
    shutil.copy(TEST_DOT_BUILDINFO_FILE2_PATH, dot_buildinfo_path)
    shutil.copy(TEST_DOT_DSC_FILE2_PATH, str(tmpdir.join('b/test_1.dsc')))
    shutil.copy(TEST_DEB_FILE2_PATH, str(tmpdir.join('b/test_1_all.deb')))
    return specialize(FilesystemFile(dot_buildinfo_path))
Esempio n. 10
0
def test_dot_dsc_invalid(tmpdir, dot_dsc2):
    tmpdir.mkdir('a')
    dot_dsc_path = str(tmpdir.join('a/test_1.dsc'))
    shutil.copy(TEST_DOT_CHANGES_FILE1_PATH, dot_dsc_path)
    # we don't copy the referenced .tar.gz
    identified = specialize(FilesystemFile(dot_dsc_path))
    assert not isinstance(identified, DotDscFile)
Esempio n. 11
0
def test_dot_changes_invalid(tmpdir):
    tmpdir.mkdir('a')
    dot_changes_path = str(tmpdir.join('a/test_1.changes'))
    shutil.copy(TEST_DOT_CHANGES_FILE1_PATH, dot_changes_path)
    # we don't copy the referenced .deb
    identified = specialize(FilesystemFile(dot_changes_path))
    assert not isinstance(identified, DotChangesFile)
Esempio n. 12
0
def rom2(tmpdir):
    size = 32768
    path = str(tmpdir.join('coreboot2.rom'))

    subprocess.check_call(
        ('cbfstool', path, 'create', '-m', 'x86', '-s', '%s' % size),
        shell=False,
    )

    subprocess.check_call(
        (
            'cbfstool',
            path,
            'add',
            '-f',
            TEST_FILE2_PATH,
            '-n',
            'text',
            '-t',
            'raw',
        ),
        shell=False,
    )

    # Remove the last 4 bytes to exercise the full header search
    buf = bytearray(size)
    with open(path, 'rb') as f:
        f.readinto(buf)

    with open(path, 'wb') as f:
        size = struct.unpack_from('!I', buf, offset=len(buf) - 4 - 32 + 8)[0]
        struct.pack_into('!I', buf, len(buf) - 4 - 32 + 8, size - 4)
        f.write(buf[:-4])

    return specialize(FilesystemFile(path))
Esempio n. 13
0
def test_difference_between_iso88591_and_unicode_only(iso8859, tmpdir):
    utf8_path = str(tmpdir.join('utf8'))
    with open(utf8_path, 'wb') as f:
        f.write(codecs.open(data('text_iso8859'), encoding='iso8859-1').read().encode('utf-8'))
    utf8 = specialize(FilesystemFile(utf8_path))
    difference = iso8859.compare(utf8)
    assert difference.unified_diff is None
    assert difference.details[0].source1 == 'encoding'
Esempio n. 14
0
def rom1(tmpdir):
    path = str(tmpdir.join('coreboot1'))
    subprocess.check_call(
        ['cbfstool', path, 'create', '-m', 'x86', '-s', '32768'], shell=False)
    subprocess.check_call([
        'cbfstool', path, 'add', '-f', TEST_FILE1_PATH, '-n', 'text', '-t',
        'raw'
    ],
                          shell=False)
    return specialize(FilesystemFile(path))
Esempio n. 15
0
def test_identification_of_md5sums_outside_deb(tmpdir):
    path = str(tmpdir.join('md5sums'))
    open(path, 'w')
    f = specialize(FilesystemFile(path))
    assert type(f) is FilesystemFile
Esempio n. 16
0
def init_fixture(filename):
    return pytest.fixture(lambda: specialize(FilesystemFile(filename)))
Esempio n. 17
0
def devnull():
    return specialize(FilesystemFile('/dev/null'))
Esempio n. 18
0
 def create(x):
     path = os.path.join(str(tmpdir.mkdir(x)), 'src')
     os.symlink('/{}'.format(x), path)
     return specialize(FilesystemFile(path))
Esempio n. 19
0
def test_compare_to_device(tmpdir):
    a = specialize(FilesystemFile(str(tmpdir.mkdir('dir'))))
    b = specialize(FilesystemFile('/dev/null'))

    assert a.compare(b).unified_diff == get_data('test_directory_device_diff')
Esempio n. 20
0
def dot_dsc2(tmpdir):
    tmpdir.mkdir('b')
    dot_dsc_path = str(tmpdir.join('b/test_1.dsc'))
    shutil.copy(TEST_DOT_DSC_FILE2_PATH, dot_dsc_path)
    shutil.copy(TEST_DEB_SRC2_PATH, str(tmpdir.join('b/test_1.tar.gz')))
    return specialize(FilesystemFile(dot_dsc_path))
Esempio n. 21
0
def dbgsym_dir2():
    container = FilesystemDirectory(os.path.dirname(TEST_DBGSYM_DEB2_PATH)).as_container
    return specialize(FilesystemFile(TEST_DBGSYM_DEB2_PATH, container=container))
Esempio n. 22
0
def lib2():
    return specialize(FilesystemFile(TEST_LIB2_PATH))