예제 #1
0
    difference = squashfs1.compare(squashfs1)
    assert difference is None


def test_no_warnings(capfd, squashfs1, squashfs2):
    _ = squashfs1.compare(squashfs2)
    _, err = capfd.readouterr()
    assert err == ''


@pytest.fixture
def differences(squashfs1, squashfs2):
    return squashfs1.compare(squashfs2).details


@pytest.mark.skipif(tool_missing('unsquashfs'), reason='missing unsquashfs')
def test_superblock(differences):
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/squashfs_superblock_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff


# I know, the next line is pretty lame. But fixing #794096 would be the real fix for this.
@pytest.mark.skipif(try_except(lambda: pwd.getpwuid(1000).pw_name != 'lunar',
                               True, KeyError),
                    reason='uid 1000 is not lunar')
@pytest.mark.skipif(tool_missing('unsquashfs'), reason='missing unsquashfs')
def test_listing(differences):
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
예제 #2
0
@pytest.fixture
def cpio2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

def test_identification(cpio1):
    assert isinstance(cpio1, CpioFile)

def test_no_differences(cpio1):
    difference = cpio1.compare(cpio1)
    assert difference is None

@pytest.fixture
def differences(cpio1, cpio2):
    return cpio1.compare(cpio2).details

@pytest.mark.skipif(tool_missing('cpio'), reason='missing cpio')
def test_listing(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/cpio_listing_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('cpio'), reason='missing cpio')
def test_symlink(differences):
    assert differences[1].source1 == 'dir/link'
    assert differences[1].comment == 'symlink'
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/symlink_expected_diff')).read()
    assert differences[1].unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('cpio'), reason='missing cpio')
def test_compressed_files(differences):
    assert differences[2].source1 == 'dir/text'
    assert differences[2].source2 == 'dir/text'
예제 #3
0
@pytest.fixture
def ps2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

def test_identification(ps1):
    assert isinstance(ps1, PsFile)

def test_no_differences(ps1):
    difference = ps1.compare(ps1)
    assert difference is None

@pytest.fixture
def differences(ps1, ps2):
    return ps1.compare(ps2)

@pytest.mark.skipif(tool_missing('ps2ascii'), reason='missing ps2ascii')
def test_internal_diff(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/ps_internal_expected_diff')).read()
    assert differences.unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('ps2ascii'), reason='missing ps2ascii')
def test_text_diff(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/ps_text_expected_diff')).read()
    assert differences.details[0].unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('ps2ascii'), reason='missing ps2ascii')
def test_compare_non_existing(monkeypatch, ps1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = ps1.compare(NonExistingFile('/nonexisting', ps1))
    assert difference.source2 == '/nonexisting'
    assert len(difference.details) > 0
예제 #4
0
def fuzzy_tar_in_tar2():
    return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/fuzzy-tar-in-tar2.tar')))

@pytest.mark.skipif(miss_tlsh, reason='tlsh is missing')
def test_no_fuzzy_matching(monkeypatch, fuzzy_tar_in_tar1, fuzzy_tar_in_tar2):
    monkeypatch.setattr(Config, 'fuzzy_threshold', 0)
    difference = fuzzy_tar_in_tar1.compare(fuzzy_tar_in_tar2)
    assert len(difference.details) == 1
    assert difference.details[0].source1 == 'file list'

@pytest.mark.skipif(miss_tlsh, reason='tlsh is missing')
def test_no_fuzzy_matching_new_file(monkeypatch, fuzzy_tar_in_tar1, fuzzy_tar_in_tar2):
    monkeypatch.setattr(Config, 'fuzzy_threshold', 0)
    monkeypatch.setattr(Config, 'new_file', True)
    difference = fuzzy_tar_in_tar1.compare(fuzzy_tar_in_tar2)
    assert len(difference.details) == 3
    assert difference.details[1].source2 == '/dev/null'
    assert difference.details[2].source1 == '/dev/null'

@pytest.mark.skipif(tool_missing('tee'), reason='missing tee')
def test_trim_stderr_in_command():
    class FillStderr(Command):
        def cmdline(self):
            return ['tee', '/dev/stderr']

        def feed_stdin(self, stdin):
            for dummy in range(0, Command.MAX_STDERR_LINES + 1):
                stdin.write('error {}\n'.format(self.path).encode('utf-8'))
    difference = Difference.from_command(FillStderr, 'dummy1', 'dummy2')
    assert '[ 1 lines ignored ]' in difference.comment
예제 #5
0

def test_identification(exe1):
    assert isinstance(exe1, MonoExeFile)


def test_no_differences(exe1):
    difference = exe1.compare(exe1)
    assert difference is None


@pytest.fixture
def differences(exe1, exe2):
    return exe1.compare(exe2).details


@pytest.mark.skipif(tool_missing('pedump'), reason='missing pedump')
def test_diff(differences):
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/pe_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff


@pytest.mark.skipif(tool_missing('pedump'), reason='missing pedump')
def test_compare_non_existing(monkeypatch, exe1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = exe1.compare(NonExistingFile('/nonexisting', exe1))
    assert difference.source2 == '/nonexisting'
    assert len(difference.details) > 0
예제 #6
0
@pytest.fixture
def obj2():
    return specialize(FilesystemFile(TEST_OBJ2_PATH))

def test_obj_identification(obj1):
    assert isinstance(obj1, MachoFile)

def test_obj_no_differences(obj1):
    difference = obj1.compare(obj1)
    assert difference is None

@pytest.fixture
def obj_differences(obj1, obj2):
    return obj1.compare(obj2).details

@pytest.mark.skipif(tool_missing('otool') or tool_missing('lipo'), reason='missing otool or lipo')
def test_obj_compare_non_existing(monkeypatch, obj1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = obj1.compare(NonExistingFile('/nonexisting', obj1))
    assert difference.source2 == '/nonexisting'
    assert len(difference.details) > 0

@pytest.mark.skipif(tool_missing('otool') or tool_missing('lipo'), reason='missing otool or lipo')
def test_diff(obj_differences):
    assert len(obj_differences) == 4
    l = ['macho_expected_diff_arch', 'macho_expected_diff_headers', 'macho_expected_diff_loadcommands', 'macho_expected_diff_disassembly']
    for idx, diff in enumerate(obj_differences):
        with open(os.path.join(os.path.dirname(__file__), '../data', l[idx]), 'w') as f:
            print(diff.unified_diff, file=f)
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/macho_expected_diff')).read()
    assert obj_differences[0].unified_diff == expected_diff
예제 #7
0
@pytest.fixture
def iso2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

def test_identification(iso1):
    assert isinstance(iso1, Iso9660File)

def test_no_differences(iso1):
    difference = iso1.compare(iso1)
    assert difference is None

@pytest.fixture
def differences(iso1, iso2):
    return iso1.compare(iso2).details

@pytest.mark.skipif(tool_missing('isoinfo'), reason='missing isoinfo')
def test_iso9660_content(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/iso9660_content_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('isoinfo'), reason='missing isoinfo')
def test_iso9660_rockridge(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/iso9660_rockridge_expected_diff')).read()
    assert differences[1].unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('isoinfo'), reason='missing isoinfo')
def test_symlink(differences):
    assert differences[2].comment == 'symlink'
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/symlink_expected_diff')).read()
    assert differences[2].unified_diff == expected_diff
예제 #8
0
def test_identification(dex1):
    assert isinstance(dex1, DexFile)


def test_no_differences(dex1):
    difference = dex1.compare(dex1)
    assert difference is None


@pytest.fixture
def differences(dex1, dex2):
    return dex1.compare(dex2).details


@pytest.mark.skipif(tool_missing('enjarify'), reason='missing enjarify')
@pytest.mark.skipif(tool_missing('zipinfo'), reason='missing zipinfo')
@pytest.mark.skipif(tool_missing('javap'), reason='missing javap')
def test_differences(differences):
    assert differences[0].source1 == 'test1.jar'
    assert differences[0].source2 == 'test2.jar'
    zipinfo = differences[0].details[0]
    classdiff = differences[0].details[1]
    assert zipinfo.source1 == 'zipinfo -v {}'
    assert zipinfo.source2 == 'zipinfo -v {}'
    assert classdiff.source1 == 'com/example/MainActivity.class'
    assert classdiff.source2 == 'com/example/MainActivity.class'
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/dex_expected_diffs')).read()
    found_diff = zipinfo.unified_diff + classdiff.details[0].unified_diff
예제 #9
0
def test_identification(deb1):
    assert isinstance(deb1, DebFile)


def test_no_differences(deb1):
    difference = deb1.compare(deb1)
    assert difference is None


@pytest.fixture
def differences(deb1, deb2):
    return deb1.compare(deb2).details


@pytest.mark.skipif(tool_missing('ar'), reason='missing ar')
def test_metadata(differences):
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/deb_metadata_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff


@pytest.mark.skipif(tool_missing('ar'), reason='missing ar')
def test_compressed_files(differences):
    assert differences[1].source1 == 'control.tar.gz'
    assert differences[2].source1 == 'data.tar.gz'


def test_identification_of_md5sums_outside_deb(tmpdir):
    path = str(tmpdir.join('md5sums'))
예제 #10
0
TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/Samyak-Malayalam2.ttf')

@pytest.fixture
def ttf1():
    return specialize(FilesystemFile(TEST_FILE1_PATH))

@pytest.fixture
def ttf2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

def test_identification(ttf1):
    assert isinstance(ttf1, TtfFile)

def test_no_differences(ttf1):
    difference = ttf1.compare(ttf1)
    assert difference is None

@pytest.fixture
def differences(ttf1, ttf2):
    return ttf1.compare(ttf2).details

@pytest.mark.skipif(tool_missing('showttf'), reason='missing showttf')
def test_diff(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/ttf_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff

def test_compare_non_existing(monkeypatch, ttf1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = ttf1.compare(NonExistingFile('/nonexisting', ttf1))
    assert difference.source2 == '/nonexisting'
예제 #11
0
        return False
    return True

@pytest.fixture
def img1():
    return specialize(FilesystemFile(TEST_FILE1_PATH))

@pytest.fixture
def img2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

def test_identification(img1):
    assert isinstance(img1, FsImageFile)

@pytest.mark.skipif(not guestfs_working(), reason='guestfs not working on the system')
@pytest.mark.skipif(tool_missing('qemu-img'), reason='missing qemu-img')
@pytest.mark.skipif(miss_guestfs, reason='guestfs is missing')
def test_no_differences(img1):
    difference = img1.compare(img1)
    assert difference is None

@pytest.fixture
def differences(img1, img2):
    return img1.compare(img2).details

@pytest.mark.skipif(not guestfs_working(), reason='guestfs not working on the system')
@pytest.mark.skipif(tool_missing('qemu-img'), reason='missing qemu-img')
@pytest.mark.skipif(miss_guestfs, reason='guestfs is missing')
def test_differences(differences):
    assert differences[0].source1 == 'test1.ext4.tar'
    tarinfo = differences[0].details[0]
예제 #12
0
@pytest.fixture
def deb2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

def test_identification(deb1):
    assert isinstance(deb1, DebFile)

def test_no_differences(deb1):
    difference = deb1.compare(deb1)
    assert difference is None

@pytest.fixture
def differences(deb1, deb2):
    return deb1.compare(deb2).details

@pytest.mark.skipif(tool_missing('ar'), reason='missing ar')
def test_metadata(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/deb_metadata_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('ar'), reason='missing ar')
def test_compressed_files(differences):
    assert differences[1].source1 == 'control.tar.gz'
    assert differences[2].source1 == 'data.tar.gz'

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
예제 #13
0
def test_identification(bzip1):
    assert isinstance(bzip1, Bzip2File)


def test_no_differences(bzip1):
    difference = bzip1.compare(bzip1)
    assert difference is None


@pytest.fixture
def differences(bzip1, bzip2):
    return bzip1.compare(bzip2).details


@pytest.mark.skipif(tool_missing("bzip2"), reason="missing bzip2")
def test_content_source(differences):
    assert differences[0].source1 == "test1"
    assert differences[0].source2 == "test2"


@pytest.mark.skipif(tool_missing("bzip2"), reason="missing bzip2")
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"
예제 #14
0
    assert isinstance(rpm1, RpmFile)


@pytest.mark.skipif(miss_rpm_module, reason="rpm module is not installed")
def test_no_differences(rpm1):
    difference = rpm1.compare(rpm1)
    assert difference is None


@pytest.fixture
def differences(rpm1, rpm2):
    return rpm1.compare(rpm2).details


@pytest.mark.skipif(miss_rpm_module, reason="rpm module is not installed")
@pytest.mark.skipif(tool_missing("rpm2cpio"), reason="missing rpm2cpio")
def test_header(differences):
    assert differences[0].source1 == "header"
    expected_diff = open(os.path.join(os.path.dirname(__file__), "../data/rpm_header_expected_diff")).read()
    assert differences[0].unified_diff == expected_diff


@pytest.mark.skipif(miss_rpm_module, reason="rpm module is not installed")
@pytest.mark.skipif(tool_missing("rpm2cpio"), reason="missing rpm2cpio")
def test_listing(differences):
    assert differences[1].source1 == "content"
    assert differences[1].details[0].source1 == "file list"
    expected_diff = open(os.path.join(os.path.dirname(__file__), "../data/rpm_listing_expected_diff")).read()
    assert differences[1].details[0].unified_diff == expected_diff

예제 #15
0
@pytest.fixture
def class1():
    return specialize(FilesystemFile(TEST_FILE1_PATH))

@pytest.fixture
def class2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

def test_identification(class1):
    assert isinstance(class1, ClassFile)

def test_no_differences(class1):
    difference = class1.compare(class1)
    assert difference is None

@pytest.fixture
def differences(class1, class2):
    return class1.compare(class2).details

@pytest.mark.skipif(tool_missing('javap'), reason='missing javap')
def test_diff(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/class_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('javap'), reason='missing javap')
def test_compare_non_existing(monkeypatch, class1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = class1.compare(NonExistingFile('/nonexisting', class1))
    assert difference.source2 == '/nonexisting'
    assert len(difference.details) > 0
예제 #16
0
def icc1():
    return specialize(FilesystemFile(TEST_FILE1_PATH))

@pytest.fixture
def icc2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

def test_identification(icc1):
    assert isinstance(icc1, IccFile)

def test_no_differences(icc1):
    difference = icc1.compare(icc1)
    assert difference is None

@pytest.fixture
def differences(icc1, icc2):
    return icc1.compare(icc2).details

@pytest.mark.skipif(tool_missing('cd-iccdump'), reason='missing cd-iccdump')
def test_diff(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/icc_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('cd-iccdump'), reason='missing cd-iccdump')
def test_compare_non_existing(monkeypatch, icc1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = icc1.compare(NonExistingFile('/nonexisting', icc1))
    assert difference.source2 == '/nonexisting'
    assert len(difference.details) > 0

예제 #17
0
@pytest.fixture
def sqlite3db1():
    return specialize(FilesystemFile(TEST_FILE1_PATH))

@pytest.fixture
def sqlite3db2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

def test_identification(sqlite3db1):
    assert isinstance(sqlite3db1, Sqlite3Database)

def test_no_differences(sqlite3db1):
    difference = sqlite3db1.compare(sqlite3db1)
    assert difference is None

@pytest.fixture
def differences(sqlite3db1, sqlite3db2):
    return sqlite3db1.compare(sqlite3db2).details

@pytest.mark.skipif(tool_missing('sqlite3'), reason='missing sqlite3')
def test_diff(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/sqlite3_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('sqlite3'), reason='missing sqlite3')
def test_compare_non_existing(monkeypatch, sqlite3db1):
    monkeypatch.setattr(Config.general, 'new_file', True)
    difference = sqlite3db1.compare(NonExistingFile('/nonexisting', sqlite3db1))
    assert difference.source2 == '/nonexisting'
    assert len(difference.details) > 0
예제 #18
0
def test_identification(mo1):
    assert isinstance(mo1, MoFile)


def test_no_differences(mo1):
    difference = mo1.compare(mo1)
    assert difference is None


@pytest.fixture
def differences(mo1, mo2):
    return mo1.compare(mo2).details


@pytest.mark.skipif(tool_missing('msgunfmt'), reason='missing msgunfmt')
def test_diff(differences):
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/mo_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff


@pytest.fixture
def mo_no_charset():
    return specialize(
        FilesystemFile(
            os.path.join(os.path.dirname(__file__),
                         '../data/test_no_charset.mo')))

예제 #19
0
@pytest.fixture
def zip2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

def test_identification(zip1):
    assert isinstance(zip1, ZipFile)

def test_no_differences(zip1):
    difference = zip1.compare(zip1)
    assert difference is None

@pytest.fixture
def differences(zip1, zip2):
    return zip1.compare(zip2).details

@pytest.mark.skipif(tool_missing('zipinfo'), reason='missing zip')
def test_metadata(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/zip_zipinfo_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('zipinfo'), reason='missing zip')
def test_compressed_files(differences):
    assert differences[1].source1 == 'dir/text'
    assert differences[1].source2 == 'dir/text'
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
    assert differences[1].unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('zipinfo'), reason='missing zip')
def test_compare_non_existing(monkeypatch, zip1):
    monkeypatch.setattr(Config.general, 'new_file', True)
    difference = zip1.compare(NonExistingFile('/nonexisting', zip1))
예제 #20
0
def test_obj_identification(obj1):
    assert isinstance(obj1, ElfFile)


def test_obj_no_differences(obj1):
    difference = obj1.compare(obj1)
    assert difference is None


@pytest.fixture
def obj_differences(obj1, obj2):
    return obj1.compare(obj2).details


@pytest.mark.skipif(tool_missing('readelf'), reason='missing readelf')
def test_obj_compare_non_existing(monkeypatch, obj1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = obj1.compare(NonExistingFile('/nonexisting', obj1))
    assert difference.source2 == '/nonexisting'


@pytest.mark.skipif(tool_missing('readelf'), reason='missing readelf')
def test_diff(obj_differences):
    assert len(obj_differences) == 1
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/elf_obj_expected_diff')).read()
    assert obj_differences[0].unified_diff == expected_diff

예제 #21
0
def test_no_fuzzy_matching(monkeypatch, fuzzy_tar_in_tar1, fuzzy_tar_in_tar2):
    monkeypatch.setattr(Config, 'fuzzy_threshold', 0)
    difference = fuzzy_tar_in_tar1.compare(fuzzy_tar_in_tar2)
    assert len(difference.details) == 1
    assert difference.details[0].source1 == 'file list'


@pytest.mark.skipif(miss_tlsh, reason='tlsh is missing')
def test_no_fuzzy_matching_new_file(monkeypatch, fuzzy_tar_in_tar1,
                                    fuzzy_tar_in_tar2):
    monkeypatch.setattr(Config, 'fuzzy_threshold', 0)
    monkeypatch.setattr(Config, 'new_file', True)
    difference = fuzzy_tar_in_tar1.compare(fuzzy_tar_in_tar2)
    assert len(difference.details) == 3
    assert difference.details[1].source2 == '/dev/null'
    assert difference.details[2].source1 == '/dev/null'


@pytest.mark.skipif(tool_missing('tee'), reason='missing tee')
def test_trim_stderr_in_command():
    class FillStderr(Command):
        def cmdline(self):
            return ['tee', '/dev/stderr']

        def feed_stdin(self, stdin):
            for dummy in range(0, Command.MAX_STDERR_LINES + 1):
                stdin.write('error {}\n'.format(self.path).encode('utf-8'))

    difference = Difference.from_command(FillStderr, 'dummy1', 'dummy2')
    assert '[ 1 lines ignored ]' in difference.comment
예제 #22
0
@pytest.fixture
def exe2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))


def test_identification(exe1):
    assert isinstance(exe1, MonoExeFile)


def test_no_differences(exe1):
    difference = exe1.compare(exe1)
    assert difference is None


@pytest.fixture
def differences(exe1, exe2):
    return exe1.compare(exe2).details


@pytest.mark.skipif(tool_missing("pedump"), reason="missing pedump")
def test_diff(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), "../data/pe_expected_diff")).read()
    assert differences[0].unified_diff == expected_diff


def test_compare_non_existing(monkeypatch, exe1):
    monkeypatch.setattr(Config, "new_file", True)
    difference = exe1.compare(NonExistingFile("/nonexisting", exe1))
    assert difference.source2 == "/nonexisting"
예제 #23
0
    return specialize(FilesystemFile(TEST_FILE2_PATH))


def test_identification(class1):
    assert isinstance(class1, ClassFile)


def test_no_differences(class1):
    difference = class1.compare(class1)
    assert difference is None


@pytest.fixture
def differences(class1, class2):
    return class1.compare(class2).details


@pytest.mark.skipif(tool_missing('javap'), reason='missing javap')
def test_diff(differences):
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/class_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff


@pytest.mark.skipif(tool_missing('javap'), reason='missing javap')
def test_compare_non_existing(monkeypatch, class1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = class1.compare(NonExistingFile('/nonexisting', class1))
    assert difference.source2 == '/nonexisting'
예제 #24
0
def test_identification(iso1):
    assert isinstance(iso1, Iso9660File)


def test_no_differences(iso1):
    difference = iso1.compare(iso1)
    assert difference is None


@pytest.fixture
def differences(iso1, iso2):
    return iso1.compare(iso2).details


@pytest.mark.skipif(tool_missing('isoinfo'), reason='missing isoinfo')
def test_iso9660_content(differences):
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/iso9660_content_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff


@pytest.mark.skipif(tool_missing('isoinfo'), reason='missing isoinfo')
def test_iso9660_rockridge(differences):
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/iso9660_rockridge_expected_diff')).read()
    assert differences[1].unified_diff == expected_diff

예제 #25
0
def ttf2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))


def test_identification(ttf1):
    assert isinstance(ttf1, TtfFile)


def test_no_differences(ttf1):
    difference = ttf1.compare(ttf1)
    assert difference is None


@pytest.fixture
def differences(ttf1, ttf2):
    return ttf1.compare(ttf2).details


@pytest.mark.skipif(tool_missing('showttf'), reason='missing showttf')
def test_diff(differences):
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/ttf_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff


def test_compare_non_existing(monkeypatch, ttf1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = ttf1.compare(NonExistingFile('/nonexisting', ttf1))
    assert difference.source2 == '/nonexisting'
예제 #26
0
def test_obj_identification(obj1):
    assert isinstance(obj1, ElfFile)


def test_obj_no_differences(obj1):
    difference = obj1.compare(obj1)
    assert difference is None


@pytest.fixture
def obj_differences(obj1, obj2):
    return obj1.compare(obj2).details


@pytest.mark.skipif(tool_missing('readelf'), reason='missing readelf')
def test_obj_compare_non_existing(monkeypatch, obj1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = obj1.compare(NonExistingFile('/nonexisting', obj1))
    assert difference.source2 == '/nonexisting'
    assert len(difference.details) > 0


@pytest.mark.skipif(tool_missing('readelf'), reason='missing readelf')
def test_diff(obj_differences):
    assert len(obj_differences) == 1
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/elf_obj_expected_diff')).read()
    assert obj_differences[0].unified_diff == expected_diff
예제 #27
0
@pytest.fixture
def mo2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

def test_identification(mo1):
    assert isinstance(mo1, MoFile)

def test_no_differences(mo1):
    difference = mo1.compare(mo1)
    assert difference is None

@pytest.fixture
def differences(mo1, mo2):
    return mo1.compare(mo2).details

@pytest.mark.skipif(tool_missing('msgunfmt'), reason='missing msgunfmt')
def test_diff(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/mo_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff

@pytest.fixture
def mo_no_charset():
    return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/test_no_charset.mo')))

@pytest.fixture
def mo_iso8859_1():
    return specialize(FilesystemFile(os.path.join(os.path.dirname(__file__), '../data/test_iso8859-1.mo')))

@pytest.mark.skipif(tool_missing('msgunfmt'), reason='missing msgunfmt')
def test_charsets(mo_no_charset, mo_iso8859_1):
    difference = mo_no_charset.compare(mo_iso8859_1)
예제 #28
0
def test_identification(epub1):
    assert isinstance(epub1, ZipFile)


def test_no_differences(epub1):
    difference = epub1.compare(epub1)
    assert difference is None


@pytest.fixture
def differences(epub1, epub2):
    return epub1.compare(epub2).details


@pytest.mark.skipif(tool_missing("zipinfo"), reason="missing zip")
def test_differences(differences):
    assert differences[0].source1 == "zipinfo {}"
    assert differences[0].source2 == "zipinfo {}"
    assert differences[1].source1 == "content.opf"
    assert differences[1].source2 == "content.opf"
    assert differences[2].source1 == "toc.ncx"
    assert differences[2].source2 == "toc.ncx"
    assert differences[3].source1 == "ch001.xhtml"
    assert differences[3].source2 == "ch001.xhtml"
    expected_diff = open(os.path.join(os.path.dirname(__file__), "../data/epub_expected_diffs")).read()
    assert expected_diff == "".join(map(lambda x: x.unified_diff, differences))


@pytest.mark.skipif(tool_missing("zipinfo"), reason="missing zip")
def test_compare_non_existing(monkeypatch, epub1):
예제 #29
0
@pytest.fixture
def obj2():
    return specialize(FilesystemFile(TEST_OBJ2_PATH))

def test_obj_identification(obj1):
    assert isinstance(obj1, ElfFile)

def test_obj_no_differences(obj1):
    difference = obj1.compare(obj1)
    assert difference is None

@pytest.fixture
def obj_differences(obj1, obj2):
    return obj1.compare(obj2).details

@pytest.mark.skipif(tool_missing('readelf'), reason='missing readelf')
def test_obj_compare_non_existing(monkeypatch, obj1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = obj1.compare(NonExistingFile('/nonexisting', obj1))
    assert difference.source2 == '/nonexisting'
    assert len(difference.details) > 0

@pytest.mark.skipif(tool_missing('readelf'), reason='missing readelf')
def test_diff(obj_differences):
    assert len(obj_differences) == 1
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/elf_obj_expected_diff')).read()
    assert obj_differences[0].unified_diff == expected_diff

TEST_LIB1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.a')
TEST_LIB2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.a')
예제 #30
0

def test_identification(png1):
    assert isinstance(png1, PngFile)


def test_no_differences(png1):
    difference = png1.compare(png1)
    assert difference is None


@pytest.fixture
def differences(png1, png2):
    return png1.compare(png2).details


@pytest.mark.skipif(tool_missing('sng'), reason='missing sng')
def test_diff(differences):
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/png_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff


@pytest.mark.skipif(tool_missing('sng'), reason='missing sng')
def test_compare_non_existing(monkeypatch, png1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = png1.compare(NonExistingFile('/nonexisting', png1))
    assert difference.source2 == '/nonexisting'
    assert len(difference.details) > 0
예제 #31
0

def test_guess_encoding_unicode():
    assert File.guess_encoding(TEST_UNICODE_PATH) == 'utf-8'


def test_guess_encoding_iso8859():
    assert File.guess_encoding(TEST_ISO8859_PATH) == 'iso-8859-1'


def test_no_differences_with_xxd(binary1):
    difference = binary1.compare_bytes(binary1)
    assert difference is None


@pytest.mark.skipif(tool_missing('xxd'), reason='missing xxd')
def test_compare_with_xxd(binary1, binary2):
    difference = binary1.compare_bytes(binary2)
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/binary_expected_diff')).read()
    assert difference.unified_diff == expected_diff


def test_compare_non_existing_with_xxd(binary1):
    difference = binary1.compare_bytes(NonExistingFile('/nonexisting',
                                                       binary1))
    assert difference.source2 == '/nonexisting'


@pytest.fixture
예제 #32
0
@pytest.fixture
def dex2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

def test_identification(dex1):
    assert isinstance(dex1, DexFile)

def test_no_differences(dex1):
    difference = dex1.compare(dex1)
    assert difference is None

@pytest.fixture
def differences(dex1, dex2):
    return dex1.compare(dex2).details

@pytest.mark.skipif(tool_missing('enjarify'), reason='missing enjarify')
@pytest.mark.skipif(tool_missing('zipinfo'), reason='missing zipinfo')
@pytest.mark.skipif(tool_missing('javap'), reason='missing javap')
def test_differences(differences):
    assert differences[0].source1 == 'test1.jar'
    assert differences[0].source2 == 'test2.jar'
    zipinfo = differences[0].details[0]
    classdiff = differences[0].details[1]
    assert zipinfo.source1 == 'zipinfo -v {}'
    assert zipinfo.source2 == 'zipinfo -v {}'
    assert classdiff.source1 == 'com/example/MainActivity.class'
    assert classdiff.source2 == 'com/example/MainActivity.class'
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/dex_expected_diffs')).read()
    found_diff = zipinfo.unified_diff + classdiff.details[0].unified_diff
    assert expected_diff == found_diff
예제 #33
0
def test_identification(zip1):
    assert isinstance(zip1, ZipFile)


def test_no_differences(zip1):
    difference = zip1.compare(zip1)
    assert difference is None


@pytest.fixture
def differences(zip1, zip2):
    return zip1.compare(zip2).details


@pytest.mark.skipif(tool_missing('zipinfo'), reason='missing zip')
def test_metadata(differences):
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/zip_zipinfo_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff


@pytest.mark.skipif(tool_missing('zipinfo'), reason='missing zip')
def test_compressed_files(differences):
    assert differences[1].source1 == 'dir/text'
    assert differences[1].source2 == 'dir/text'
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/text_ascii_expected_diff')).read()
    assert differences[1].unified_diff == expected_diff
예제 #34
0
def rom2(tmpdir):
    path = str(tmpdir.join('coreboot2.rom'))
    size = 32768
    check_call(['cbfstool', path, 'create', '-m', 'x86', '-s', '%s' % size], shell=False)
    check_call(['cbfstool', path, 'add', '-f', TEST_FILE2_PATH, '-n', 'text', '-t', 'raw'], shell=False)
    # Remove the last 4 bytes to exercice 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))

@pytest.mark.skipif(tool_missing('cbfstool'), reason='missing cbfstool')
def test_identification_using_offset(rom1):
    assert isinstance(rom1, CbfsFile)

@pytest.mark.skipif(tool_missing('cbfstool'), reason='missing cbfstool')
def test_identification_without_offset(rom2):
    assert isinstance(rom2, CbfsFile)

@pytest.mark.skipif(tool_missing('cbfstool'), reason='missing cbfstool')
def test_no_differences(rom1):
    difference = rom1.compare(rom1)
    assert difference is None

@pytest.fixture
def differences(rom1, rom2):
    difference = rom1.compare(rom2)
예제 #35
0

def test_identification(image1):
    assert isinstance(image1, ImageFile)


def test_no_differences(image1):
    difference = image1.compare(image1)
    assert difference is None


@pytest.fixture
def differences(image1, image2):
    return image1.compare(image2).details


@pytest.mark.skipif(tool_missing('img2txt'), reason='img2txt')
def test_diff(differences):
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/image_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff


@pytest.mark.skipif(tool_missing('img2txt'), reason='img2txt')
def test_compare_non_existing(monkeypatch, image1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = image1.compare(NonExistingFile('/nonexisting', image1))
    assert difference.source2 == '/nonexisting'
    assert len(difference.details) > 0
예제 #36
0
@pytest.fixture
def image1():
    return specialize(FilesystemFile(TEST_FILE1_PATH))

@pytest.fixture
def image2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

def test_identification(image1):
    assert isinstance(image1, ImageFile)

def test_no_differences(image1):
    difference = image1.compare(image1)
    assert difference is None

@pytest.fixture
def differences(image1, image2):
    return image1.compare(image2).details

@pytest.mark.skipif(tool_missing('img2txt'), reason='img2txt')
def test_diff(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/image_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('img2txt'), reason='img2txt')
def test_compare_non_existing(monkeypatch, image1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = image1.compare(NonExistingFile('/nonexisting', image1))
    assert difference.source2 == '/nonexisting'
    assert len(difference.details) > 0
예제 #37
0
@pytest.fixture
def pdf2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

def test_identification(pdf1):
    assert isinstance(pdf1, PdfFile)

def test_no_differences(pdf1):
    difference = pdf1.compare(pdf1)
    assert difference is None

@pytest.fixture
def differences(pdf1, pdf2):
    return pdf1.compare(pdf2).details

@pytest.mark.skipif(tool_missing('pdftk') or tool_missing('pdftotext'),
                    reason='missing pdftk or pdftotext')
def test_text_diff(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/pdf_text_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('pdftk') or tool_missing('pdftotext'),
                    reason='missing pdftk or pdftotext')
def test_internal_diff(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/pdf_internal_expected_diff')).read()
    assert differences[1].unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('pdftk') or tool_missing('pdftotext'),
                    reason='missing pdftk or pdftotext')
def test_compare_non_existing(monkeypatch, pdf1):
    monkeypatch.setattr(Config, 'new_file', True)
예제 #38
0
    assert File.guess_encoding(TEST_FILE1_PATH) == 'binary'

def test_guess_encoding_ascii():
    assert File.guess_encoding(TEST_ASCII_PATH) == 'us-ascii'

def test_guess_encoding_unicode():
    assert File.guess_encoding(TEST_UNICODE_PATH) == 'utf-8'

def test_guess_encoding_iso8859():
    assert File.guess_encoding(TEST_ISO8859_PATH) == 'iso-8859-1'

def test_no_differences_with_xxd(binary1):
    difference = binary1.compare_bytes(binary1)
    assert difference is None

@pytest.mark.skipif(tool_missing('xxd'), reason='missing xxd')
def test_compare_with_xxd(binary1, binary2):
    difference = binary1.compare_bytes(binary2)
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/binary_expected_diff')).read()
    assert difference.unified_diff == expected_diff

def test_compare_non_existing_with_xxd(binary1):
    difference = binary1.compare_bytes(NonExistingFile('/nonexisting', binary1))
    assert difference.source2 == '/nonexisting'

@pytest.fixture
def xxd_not_found(monkeypatch):
    def mock_cmdline(self):
        raise RequiredToolNotFound('xxd')
    monkeypatch.setattr(diffoscope.comparators.utils.Xxd, 'cmdline', mock_cmdline)
예제 #39
0
    assert isinstance(squashfs1, SquashfsFile)

def test_no_differences(squashfs1):
    difference = squashfs1.compare(squashfs1)
    assert difference is None

def test_no_warnings(capfd, squashfs1, squashfs2):
    _ = squashfs1.compare(squashfs2)
    _, err = capfd.readouterr()
    assert err == ''

@pytest.fixture
def differences(squashfs1, squashfs2):
    return squashfs1.compare(squashfs2).details

@pytest.mark.skipif(tool_missing('unsquashfs'), reason='missing unsquashfs')
def test_superblock(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/squashfs_superblock_expected_diff')).read()
    assert differences[0].unified_diff == expected_diff

# I know, the next line is pretty lame. But fixing #794096 would be the real fix for this.
@pytest.mark.skipif(try_except(lambda: pwd.getpwuid(1000).pw_name != 'lunar', True, KeyError), reason='uid 1000 is not lunar')
@pytest.mark.skipif(tool_missing('unsquashfs'), reason='missing unsquashfs')
def test_listing(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/squashfs_listing_expected_diff')).read()
    assert differences[1].unified_diff == expected_diff

@pytest.mark.skipif(tool_missing('unsquashfs'), reason='missing unsquashfs')
def test_symlink(differences):
    assert differences[2].comment == 'symlink'
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/symlink_expected_diff')).read()
예제 #40
0
def test_identification(ps1):
    assert isinstance(ps1, PsFile)


def test_no_differences(ps1):
    difference = ps1.compare(ps1)
    assert difference is None


@pytest.fixture
def differences(ps1, ps2):
    return ps1.compare(ps2)


@pytest.mark.skipif(tool_missing('ps2ascii'), reason='missing ps2ascii')
def test_internal_diff(differences):
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/ps_internal_expected_diff')).read()
    assert differences.unified_diff == expected_diff


@pytest.mark.skipif(tool_missing('ps2ascii'), reason='missing ps2ascii')
def test_text_diff(differences):
    expected_diff = open(
        os.path.join(os.path.dirname(__file__),
                     '../data/ps_text_expected_diff')).read()
    assert differences.details[0].unified_diff == expected_diff

예제 #41
0
def test_identification(bzip1):
    assert isinstance(bzip1, Bzip2File)


def test_no_differences(bzip1):
    difference = bzip1.compare(bzip1)
    assert difference is None


@pytest.fixture
def differences(bzip1, bzip2):
    return bzip1.compare(bzip2).details


@pytest.mark.skipif(tool_missing('bzip2'), reason='missing bzip2')
def test_content_source(differences):
    assert differences[0].source1 == 'test1'
    assert differences[0].source2 == 'test2'


@pytest.mark.skipif(tool_missing('bzip2'), reason='missing bzip2')
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'
예제 #42
0
@pytest.fixture
def obj2():
    return specialize(FilesystemFile(TEST_OBJ2_PATH))

def test_obj_identification(obj1):
    assert isinstance(obj1, ElfFile)

def test_obj_no_differences(obj1):
    difference = obj1.compare(obj1)
    assert difference is None

@pytest.fixture
def obj_differences(obj1, obj2):
    return obj1.compare(obj2).details

@pytest.mark.skipif(tool_missing('readelf'), reason='missing readelf')
def test_obj_compare_non_existing(monkeypatch, obj1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = obj1.compare(NonExistingFile('/nonexisting', obj1))
    assert difference.source2 == '/nonexisting'

@pytest.mark.skipif(tool_missing('readelf'), reason='missing readelf')
def test_diff(obj_differences):
    assert len(obj_differences) == 1
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/elf_obj_expected_diff')).read()
    assert obj_differences[0].unified_diff == expected_diff

TEST_LIB1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.a')
TEST_LIB2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.a')

@pytest.fixture
예제 #43
0
# reproducible build infrastructure. The files were originally called
# castletexturefont_dejavusans_10.ppu which are generated during package
# building of the cge package from dejavusans font in the fonts-dejavu package.

TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.ppu') 
TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.ppu') 

@pytest.fixture
def file1():
    return specialize(FilesystemFile(TEST_FILE1_PATH))

@pytest.fixture
def file2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

@pytest.mark.skipif(tool_missing('ppudump'), reason='missing ppudump')
def test_identification(file1):
    assert isinstance(file1, PpuFile)

def test_no_differences(file1):
    difference = file1.compare(file1)
    assert difference is None

@pytest.fixture
def differences(file1, file2):
    return file1.compare(file2).details

@pytest.mark.skipif(tool_missing('ppudump'), reason='missing ppudump')
def test_diff(differences):
    print(differences[0].unified_diff)
    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/ppu_expected_diff')).read()
예제 #44
0
def png2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))


def test_identification(png1):
    assert isinstance(png1, PngFile)


def test_no_differences(png1):
    difference = png1.compare(png1)
    assert difference is None


@pytest.fixture
def differences(png1, png2):
    return png1.compare(png2).details


@pytest.mark.skipif(tool_missing("sng"), reason="missing sng")
def test_diff(differences):
    expected_diff = open(os.path.join(os.path.dirname(__file__), "../data/png_expected_diff")).read()
    assert differences[0].unified_diff == expected_diff


@pytest.mark.skipif(tool_missing("sng"), reason="missing sng")
def test_compare_non_existing(monkeypatch, png1):
    monkeypatch.setattr(Config, "new_file", True)
    difference = png1.compare(NonExistingFile("/nonexisting", png1))
    assert difference.source2 == "/nonexisting"
    assert len(difference.details) > 0
예제 #45
0
def test_obj_identification(obj1):
    assert isinstance(obj1, MachoFile)


def test_obj_no_differences(obj1):
    difference = obj1.compare(obj1)
    assert difference is None


@pytest.fixture
def obj_differences(obj1, obj2):
    return obj1.compare(obj2).details


@pytest.mark.skipif(tool_missing('otool') or tool_missing('lipo'),
                    reason='missing otool or lipo')
def test_obj_compare_non_existing(monkeypatch, obj1):
    monkeypatch.setattr(Config, 'new_file', True)
    difference = obj1.compare(NonExistingFile('/nonexisting', obj1))
    assert difference.source2 == '/nonexisting'


@pytest.mark.skipif(tool_missing('otool') or tool_missing('lipo'),
                    reason='missing otool or lipo')
def test_diff(obj_differences):
    assert len(obj_differences) == 4
    l = [
        'macho_expected_diff_arch', 'macho_expected_diff_headers',
        'macho_expected_diff_loadcommands', 'macho_expected_diff_disassembly'
    ]
예제 #46
0
@pytest.fixture
def bzip2():
    return specialize(FilesystemFile(TEST_FILE2_PATH))

def test_identification(bzip1):
    assert isinstance(bzip1, Bzip2File)

def test_no_differences(bzip1):
    difference = bzip1.compare(bzip1)
    assert difference is None

@pytest.fixture
def differences(bzip1, bzip2):
    return bzip1.compare(bzip2).details

@pytest.mark.skipif(tool_missing('bzip2'), reason='missing bzip2')
def test_content_source(differences):
    assert differences[0].source1 == 'test1'
    assert differences[0].source2 == 'test2'

@pytest.mark.skipif(tool_missing('bzip2'), reason='missing bzip2')
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'