Beispiel #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)
Beispiel #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')
Beispiel #3
0
def compare_root_paths(path1, path2):
    if not Config.general.new_file:
        bail_if_non_existing(path1, path2)
    if os.path.isdir(path1) and os.path.isdir(path2):
        return compare_directories(path1, path2)
    file1 = specialize(FilesystemFile(path1))
    file2 = specialize(FilesystemFile(path2))
    return compare_files(file1, file2)
Beispiel #4
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'
Beispiel #5
0
def test_content_source_without_extension(tmpdir):
    path1 = str(tmpdir.join('test1'))
    path2 = str(tmpdir.join('test2'))
    shutil.copy(TEST_FILE1_PATH, path1)
    shutil.copy(TEST_FILE2_PATH, path2)
    bzip1 = specialize(FilesystemFile(path1))
    bzip2 = specialize(FilesystemFile(path2))
    differences = bzip1.compare(bzip2).details
    assert differences[0].source1 == 'test1-content'
    assert differences[0].source2 == 'test2-content'
Beispiel #6
0
def compare_root_paths(path1, path2):
    if not Config.general.new_file:
        bail_if_non_existing(path1, path2)
    if os.path.isdir(path1) and os.path.isdir(path2):
        return compare_directories(path1, path2)
    container1 = FilesystemDirectory(os.path.dirname(path1)).as_container
    file1 = specialize(FilesystemFile(path1, container=container1))
    container2 = FilesystemDirectory(os.path.dirname(path2)).as_container
    file2 = specialize(FilesystemFile(path2, container=container2))
    return compare_files(file1, file2)
Beispiel #7
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'
Beispiel #8
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')
Beispiel #9
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
Beispiel #10
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)
Beispiel #11
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)
Beispiel #12
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)
Beispiel #13
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))
Beispiel #14
0
 def get_member(self, member_name):
     member_path = os.path.join(self.source.path, member_name)
     if not os.path.islink(member_path) and os.path.isdir(member_path):
         return FilesystemDirectory(member_path)
     else:
         return FilesystemFile(os.path.join(self.source.path, member_name),
                               container=self)
Beispiel #15
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))
Beispiel #16
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))
Beispiel #17
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(os.path.join(os.path.dirname(__file__), '../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'
Beispiel #18
0
def test_symlink_to_dir():
    # Create 2 directories, each containing sub-directory src and symbolic link dst-->src.
    with TemporaryDirectory() as basepath1:
        with TemporaryDirectory() as basepath2:
            src1path = os.path.join(basepath1, 'src')
            dst1path = os.path.join(basepath1, 'lnk')
            src2path = os.path.join(basepath2, 'src')
            dst2path = os.path.join(basepath2, 'lnk')
            mkdir(src1path)
            mkdir(src2path)
            symlink(src1path, dst1path)
            symlink(src2path, dst2path)

            # Compare these directories' content.
            file1 = FilesystemFile(basepath1)
            file2 = FilesystemFile(basepath2)
            assert file1.has_same_content_as(file2) is False
Beispiel #19
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))
Beispiel #20
0
def obj2():
    return specialize(FilesystemFile(TEST_OBJ2_PATH))
Beispiel #21
0
def devnull():
    return specialize(FilesystemFile('/dev/null'))
Beispiel #22
0
def fuzzy_tar3():
    return specialize(
        FilesystemFile(
            os.path.join(os.path.dirname(__file__), '../data/fuzzy3.tar')))
Beispiel #23
0
def fuzzy_tar_in_tar2():
    return specialize(
        FilesystemFile(
            os.path.join(os.path.dirname(__file__),
                         '../data/fuzzy-tar-in-tar2.tar')))
Beispiel #24
0
def bzip2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))
Beispiel #25
0
def binary1():
    return specialize(FilesystemFile(TEST_FILE1_PATH))
Beispiel #26
0
def no_permissions_tar():
    return specialize(
        FilesystemFile(
            os.path.join(os.path.dirname(__file__), '../data/no-perms.tar')))
Beispiel #27
0
def tar1():
    return specialize(FilesystemFile(TEST_FILE1_PATH))
Beispiel #28
0
def image2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))
Beispiel #29
0
def sqlite3db2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))
Beispiel #30
0
def mozzip2():
    return specialize(FilesystemFile(TEST_MOZZIP2_PATH))