[diffoscope] 10/10: fix pep8 E302 in the tests
Mattia Rizzolo
mattia at debian.org
Sat Sep 9 20:39:52 UTC 2017
This is an automated email from the git hooks/post-receive script.
mattia pushed a commit to branch master
in repository diffoscope.
commit 7cf92ad1e3cf6523a3baba1a83468f273846660e
Author: Mattia Rizzolo <mattia at debian.org>
Date: Sat Sep 9 22:34:29 2017 +0200
fix pep8 E302 in the tests
Signed-off-by: Mattia Rizzolo <mattia at debian.org>
---
tests/comparators/test_apk.py | 10 ++++++++++
tests/comparators/test_archive.py | 2 ++
tests/comparators/test_binary.py | 22 ++++++++++++++++++++++
tests/comparators/test_bzip2.py | 6 ++++++
tests/comparators/test_deb.py | 12 ++++++++++++
tests/comparators/test_debian.py | 30 ++++++++++++++++++++++++++++++
tests/comparators/test_device.py | 6 ++++++
tests/comparators/test_dex.py | 6 ++++++
tests/comparators/test_directory.py | 8 ++++++++
tests/comparators/test_dtb.py | 6 ++++++
tests/comparators/test_elf.py | 17 +++++++++++++++++
tests/comparators/test_epub.py | 5 +++++
tests/comparators/test_fonts.py | 5 +++++
tests/comparators/test_fsimage.py | 6 ++++++
tests/comparators/test_gettext.py | 6 ++++++
tests/comparators/test_gif.py | 6 ++++++
tests/comparators/test_git.py | 4 ++++
tests/comparators/test_gzip.py | 7 +++++++
tests/comparators/test_haskell.py | 4 ++++
tests/comparators/test_icc.py | 5 +++++
tests/comparators/test_ico_image.py | 8 ++++++++
tests/comparators/test_ipk.py | 6 ++++++
tests/comparators/test_iso9660.py | 9 +++++++++
tests/comparators/test_java.py | 6 ++++++
tests/comparators/test_javascript.py | 5 +++++
tests/comparators/test_jpeg_image.py | 9 +++++++++
tests/comparators/test_json.py | 7 +++++++
tests/comparators/test_macho.py | 5 +++++
tests/comparators/test_mono.py | 5 +++++
tests/comparators/test_openssh_pub_key.py | 4 ++++
tests/comparators/test_pdf.py | 6 ++++++
tests/comparators/test_png.py | 6 ++++++
tests/comparators/test_ppu.py | 6 ++++++
tests/comparators/test_ps.py | 6 ++++++
tests/comparators/test_rdata.py | 5 +++++
tests/comparators/test_rlib.py | 10 ++++++++++
tests/comparators/test_sqlite.py | 5 +++++
tests/comparators/test_squashfs.py | 8 ++++++++
tests/comparators/test_tar.py | 9 +++++++++
tests/comparators/test_text.py | 7 +++++++
tests/comparators/test_utils.py | 9 +++++++++
tests/comparators/test_xz.py | 7 +++++++
tests/comparators/test_zip.py | 13 +++++++++++++
tests/test_difference.py | 6 ++++++
tests/test_excludes.py | 7 +++++++
tests/test_main.py | 10 ++++++++++
tests/test_presenters.py | 20 ++++++++++++++++++++
tests/test_progress.py | 2 ++
tests/test_readers.py | 2 ++
tests/utils/__init__.py | 1 +
tests/utils/tools.py | 8 ++++++++
51 files changed, 390 insertions(+)
diff --git a/tests/comparators/test_apk.py b/tests/comparators/test_apk.py
index 4b021b4..632f272 100644
--- a/tests/comparators/test_apk.py
+++ b/tests/comparators/test_apk.py
@@ -29,25 +29,31 @@ apk1 = load_fixture('test1.apk')
apk2 = load_fixture('test2.apk')
apk3 = load_fixture('test3.apk')
+
def test_identification(apk1):
assert isinstance(apk1, ApkFile)
+
def test_no_differences(apk1):
difference = apk1.compare(apk1)
assert difference is None
+
@pytest.fixture
def differences(apk1, apk2):
return apk1.compare(apk2).details
+
@pytest.fixture
def differences2(apk1, apk3):
return apk1.compare(apk3).details
+
@skip_unless_tools_exist('apktool', 'zipinfo')
def test_compare_non_existing(monkeypatch, apk1):
assert_non_existing(monkeypatch, apk1)
+
@skip_unless_tools_exist('apktool', 'zipinfo')
def test_zipinfo(differences):
assert differences[0].source1 == 'zipinfo {}'
@@ -55,6 +61,7 @@ def test_zipinfo(differences):
expected_diff = get_data('apk_zipinfo_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('apktool', 'zipinfo')
def test_android_manifest(differences):
assert differences[1].source1 == 'AndroidManifest.xml (decoded)'
@@ -62,11 +69,13 @@ def test_android_manifest(differences):
expected_diff = get_data('apk_manifest_expected_diff')
assert differences[1].details[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('apktool', 'zipinfo')
def test_apk_metadata_source(differences):
assert differences[2].source1 == 'APK metadata'
assert differences[2].source2 == 'APK metadata'
+
@skip_unless_tools_exist('apktool', 'zipinfo')
def test_skip_undecoded_android_manifest(differences):
assert not any(difference.source1 == 'original/AndroidManifest.xml'
@@ -79,6 +88,7 @@ def test_skip_undecoded_android_manifest(differences):
assert not any(difference.source2 == undecoded_manifest
for difference in differences)
+
@skip_unless_tools_exist('apktool', 'zipinfo')
def test_no_android_manifest(differences2):
undecoded_manifest = 'AndroidManifest.xml (original / undecoded)'
diff --git a/tests/comparators/test_archive.py b/tests/comparators/test_archive.py
index 17b68e0..e42e0b3 100644
--- a/tests/comparators/test_archive.py
+++ b/tests/comparators/test_archive.py
@@ -25,10 +25,12 @@ from ..utils.data import load_fixture
archive1 = load_fixture('archive1.tar')
archive2 = load_fixture('archive2.tar')
+
@pytest.fixture
def differences(archive1, archive2):
return archive1.compare(archive2).details
+
def test_compressed_content_name(differences):
assert differences[1].details[1].source1 == 'compressed'
assert differences[1].details[1].source2 == 'compressed'
diff --git a/tests/comparators/test_binary.py b/tests/comparators/test_binary.py
index c8c4ba5..2ed5d27 100644
--- a/tests/comparators/test_binary.py
+++ b/tests/comparators/test_binary.py
@@ -46,56 +46,70 @@ TEST_ISO8859_PATH = data('text_iso8859')
binary1 = init_fixture(TEST_FILE1_PATH)
binary2 = init_fixture(TEST_FILE2_PATH)
+
def test_same_content(binary1):
assert binary1.has_same_content_as(binary1) is True
+
def test_not_same_content(binary1, binary2):
assert binary1.has_same_content_as(binary2) is False
+
def test_guess_file_type():
assert File.guess_file_type(TEST_FILE1_PATH) == 'data'
+
def test_guess_encoding_binary():
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
+
@skip_unless_tools_exist('xxd')
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
+
def test_compare_non_existing_with_xxd(binary1):
difference = binary1.compare_bytes(MissingFile('/nonexisting', binary1))
assert difference.source2 == '/nonexisting'
+
@pytest.fixture
def xxd_not_found(monkeypatch):
def mock_cmdline(self):
raise RequiredToolNotFound('xxd')
monkeypatch.setattr(Xxd, 'cmdline', mock_cmdline)
+
def test_no_differences_without_xxd(xxd_not_found, binary1):
difference = binary1.compare_bytes(binary1)
assert difference is None
+
def test_compare_without_xxd(xxd_not_found, binary1, binary2):
difference = binary1.compare(binary2)
expected_diff = get_data('binary_hexdump_expected_diff')
assert difference.unified_diff == expected_diff
+
def test_with_compare_details():
d = Difference('diff', TEST_FILE1_PATH, TEST_FILE2_PATH, source='source')
@@ -105,6 +119,7 @@ def test_with_compare_details():
difference = MockFile(TEST_FILE1_PATH).compare(MockFile(TEST_FILE2_PATH), source='source')
assert difference.details[0] == d
+
@skip_unless_tools_exist('xxd')
def test_with_compare_details_and_fallback():
class MockFile(FilesystemFile):
@@ -115,6 +130,7 @@ def test_with_compare_details_and_fallback():
assert 'yet data differs' in difference.comment
assert normalize_zeros(difference.unified_diff) == expected_diff
+
def test_with_compare_details_and_no_actual_differences():
class MockFile(FilesystemFile):
def compare_details(self, other, source=None):
@@ -122,6 +138,7 @@ def test_with_compare_details_and_no_actual_differences():
difference = MockFile(TEST_FILE1_PATH).compare(MockFile(TEST_FILE1_PATH))
assert difference is None
+
@skip_unless_tools_exist('xxd')
def test_with_compare_details_and_failed_process():
output = 'Free Jeremy Hammond'
@@ -136,6 +153,7 @@ def test_with_compare_details_and_failed_process():
assert '42' in difference.comment
assert normalize_zeros(difference.unified_diff) == expected_diff
+
@skip_unless_tools_exist('xxd')
def test_with_compare_details_and_parsing_error():
from diffoscope.exc import OutputParsingError
@@ -149,6 +167,7 @@ def test_with_compare_details_and_parsing_error():
assert 'Error parsing output' in difference.comment
assert normalize_zeros(difference.unified_diff) == expected_diff
+
@skip_unless_tools_exist('xxd')
def test_with_compare_details_and_extraction_error():
from diffoscope.exc import ContainerExtractionError
@@ -162,6 +181,7 @@ def test_with_compare_details_and_extraction_error():
assert 'Error extracting' in difference.comment
assert normalize_zeros(difference.unified_diff) == expected_diff
+
@skip_unless_tools_exist('xxd')
@skip_unless_module_exists('distro')
def test_with_compare_details_and_tool_not_found(monkeypatch):
@@ -187,12 +207,14 @@ def test_with_compare_details_and_tool_not_found(monkeypatch):
assert 'some-package' in difference.comment
assert normalize_zeros(difference.unified_diff) == expected_diff
+
def test_compare_two_nonexisting_files():
file1 = MissingFile('/nonexisting1')
file2 = MissingFile('/nonexisting2')
difference = file1.compare(file2)
assert 'non-existing' in difference.comment
+
def test_symlink_to_dir():
# Create 2 directories, each containing sub-directory src and symbolic link dst-->src.
with TemporaryDirectory() as basepath1:
diff --git a/tests/comparators/test_bzip2.py b/tests/comparators/test_bzip2.py
index 01bf799..1f2f25e 100644
--- a/tests/comparators/test_bzip2.py
+++ b/tests/comparators/test_bzip2.py
@@ -36,19 +36,23 @@ bzip2 = load_fixture('test2.bz2')
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
+
@skip_unless_tools_exist('bzip2')
def test_content_source(differences):
assert differences[0].source1 == 'test1'
assert differences[0].source2 == 'test2'
+
@skip_unless_tools_exist('bzip2')
def test_content_source_without_extension(tmpdir, bzip1, bzip2):
path1 = str(tmpdir.join('test1'))
@@ -61,11 +65,13 @@ def test_content_source_without_extension(tmpdir, bzip1, bzip2):
assert differences[0].source1 == 'test1-content'
assert differences[0].source2 == 'test2-content'
+
@skip_unless_tools_exist('bzip2')
def test_content_diff(differences):
expected_diff = get_data('text_ascii_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('bzip2')
def test_compare_non_existing(monkeypatch, bzip1):
assert_non_existing(monkeypatch, bzip1)
diff --git a/tests/comparators/test_deb.py b/tests/comparators/test_deb.py
index 002a2f4..bd2976c 100644
--- a/tests/comparators/test_deb.py
+++ b/tests/comparators/test_deb.py
@@ -33,31 +33,38 @@ from ..utils.data import load_fixture, get_data
deb1 = load_fixture('test1.deb')
deb2 = load_fixture('test2.deb')
+
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
+
def test_metadata(differences):
expected_diff = get_data('deb_metadata_expected_diff')
assert differences[0].unified_diff == expected_diff
+
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
+
def test_identification_of_md5sums_in_deb(deb1, deb2, monkeypatch):
orig_func = Md5sumsFile.recognizes
@@ -72,13 +79,16 @@ def test_identification_of_md5sums_in_deb(deb1, deb2, monkeypatch):
deb1.compare(deb2)
assert test_identification_of_md5sums_in_deb.found
+
def test_md5sums(differences):
assert differences[1].details[0].details[1].details[0].comment == 'Files in package differ'
+
def test_identical_files_in_md5sums(deb1, deb2):
for name in ['./usr/share/doc/test/README.Debian', './usr/share/doc/test/copyright']:
assert deb1.md5sums[name] == deb2.md5sums[name]
+
def test_identification_of_data_tar(deb1, deb2, monkeypatch):
orig_func = DebDataTarFile.recognizes
@@ -93,6 +103,7 @@ def test_identification_of_data_tar(deb1, deb2, monkeypatch):
deb1.compare(deb2)
assert test_identification_of_data_tar.found
+
def test_skip_comparison_of_known_identical_files(deb1, deb2, monkeypatch):
compared = set()
orig_func = diffoscope.comparators.utils.compare.compare_files
@@ -104,6 +115,7 @@ def test_skip_comparison_of_known_identical_files(deb1, deb2, monkeypatch):
deb1.compare(deb2)
assert './usr/share/doc/test/README.Debian' not in compared
+
def test_compare_non_existing(monkeypatch, deb1):
monkeypatch.setattr(Config(), 'new_file', True)
difference = deb1.compare(MissingFile('/nonexisting', deb1))
diff --git a/tests/comparators/test_debian.py b/tests/comparators/test_debian.py
index b9ac886..9ce66d7 100644
--- a/tests/comparators/test_debian.py
+++ b/tests/comparators/test_debian.py
@@ -47,6 +47,7 @@ TEST_DOT_BUILDINFO_FILE2_PATH = data('test2.buildinfo')
TEST_DEB_FILE1_PATH = data('test1.deb')
TEST_DEB_FILE2_PATH = data('test2.deb')
+
@pytest.fixture
def dot_changes1(tmpdir):
tmpdir.mkdir('a')
@@ -56,6 +57,7 @@ def dot_changes1(tmpdir):
shutil.copy(TEST_DOT_BUILDINFO_FILE1_PATH, str(tmpdir.join('a/test_1.buildinfo')))
return specialize(FilesystemFile(dot_changes_path))
+
@pytest.fixture
def dot_changes2(tmpdir):
tmpdir.mkdir('b')
@@ -65,6 +67,7 @@ def dot_changes2(tmpdir):
shutil.copy(TEST_DOT_BUILDINFO_FILE2_PATH, str(tmpdir.join('b/test_2.buildinfo')))
return specialize(FilesystemFile(dot_changes_path))
+
@pytest.fixture
def dot_changes3(tmpdir):
tmpdir.mkdir('c')
@@ -74,6 +77,7 @@ def dot_changes3(tmpdir):
shutil.copy(TEST_DOT_BUILDINFO_FILE2_PATH, str(tmpdir.join('c/test_2.buildinfo')))
return specialize(FilesystemFile(dot_changes_path))
+
@pytest.fixture
def dot_changes4(tmpdir):
tmpdir.mkdir('d')
@@ -83,9 +87,11 @@ def dot_changes4(tmpdir):
shutil.copy(TEST_DOT_BUILDINFO_FILE1_PATH, str(tmpdir.join('d/test_2.buildinfo')))
return specialize(FilesystemFile(dot_changes_path))
+
def test_dot_changes_identification(dot_changes1):
assert isinstance(dot_changes1, DotChangesFile)
+
@skip_unless_module_exists('debian.deb822')
def test_dot_changes_invalid(tmpdir):
tmpdir.mkdir('a')
@@ -95,42 +101,50 @@ def test_dot_changes_invalid(tmpdir):
identified = specialize(FilesystemFile(dot_changes_path))
assert not isinstance(identified, DotChangesFile)
+
def test_dot_changes_no_differences(dot_changes1):
difference = dot_changes1.compare(dot_changes1)
assert difference is None
+
@pytest.fixture
def dot_changes_differences(dot_changes1, dot_changes2):
difference = dot_changes1.compare(dot_changes2)
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
+
@pytest.fixture
def dot_changes_differences_identical_contents_and_identical_files(dot_changes1, dot_changes3):
difference = dot_changes1.compare(dot_changes3)
return difference.details
+
@pytest.fixture
def dot_changes_differences_identical_contents_and_different_files(dot_changes1, dot_changes4):
difference = dot_changes1.compare(dot_changes4)
return difference.details
+
@pytest.fixture
def dot_changes_differences_different_contents_and_identical_files(dot_changes2, dot_changes4):
difference = dot_changes4.compare(dot_changes2)
return difference.details
+
@skip_unless_module_exists('debian.deb822')
def test_dot_changes_no_differences_exclude_buildinfo(dot_changes1, dot_changes3):
difference = dot_changes1.compare(dot_changes3)
assert difference is None
+
@skip_unless_module_exists('debian.deb822')
def test_dot_changes_identical_contents_and_different_files(dot_changes_differences_identical_contents_and_different_files):
assert dot_changes_differences_identical_contents_and_different_files[0]
expected_diff = get_data('dot_changes_identical_contents_and_different_files_expected_diff')
assert dot_changes_differences_identical_contents_and_different_files[0].unified_diff == expected_diff
+
@skip_unless_module_exists('debian.deb822')
def test_dot_changes_different_contents_and_identical_files(dot_changes_differences_different_contents_and_identical_files):
assert dot_changes_differences_different_contents_and_identical_files[0]
@@ -146,6 +160,7 @@ TEST_DOT_DSC_FILE2_PATH = data('test2.dsc')
TEST_DEB_SRC1_PATH = data('test1.debsrc.tar.gz')
TEST_DEB_SRC2_PATH = data('test2.debsrc.tar.gz')
+
@pytest.fixture
def dot_dsc1(tmpdir):
tmpdir.mkdir('a')
@@ -154,6 +169,7 @@ def dot_dsc1(tmpdir):
shutil.copy(TEST_DEB_SRC1_PATH, str(tmpdir.join('a/test_1.tar.gz')))
return specialize(FilesystemFile(dot_dsc_path))
+
@pytest.fixture
def dot_dsc2(tmpdir):
tmpdir.mkdir('b')
@@ -162,9 +178,11 @@ def dot_dsc2(tmpdir):
shutil.copy(TEST_DEB_SRC2_PATH, str(tmpdir.join('b/test_1.tar.gz')))
return specialize(FilesystemFile(dot_dsc_path))
+
def test_dot_dsc_identification(dot_dsc1):
assert isinstance(dot_dsc1, DotDscFile)
+
@skip_unless_module_exists('debian.deb822')
def test_dot_dsc_invalid(tmpdir, dot_dsc2):
tmpdir.mkdir('a')
@@ -174,19 +192,23 @@ def test_dot_dsc_invalid(tmpdir, dot_dsc2):
identified = specialize(FilesystemFile(dot_dsc_path))
assert not isinstance(identified, DotDscFile)
+
def test_dot_dsc_no_differences(dot_dsc1):
difference = dot_dsc1.compare(dot_dsc1)
assert difference is None
+
@pytest.fixture
def dot_dsc_differences(dot_dsc1, dot_dsc2):
difference = dot_dsc1.compare(dot_dsc2)
return difference.details
+
@skip_unless_module_exists('debian.deb822')
def test_dot_dsc_internal_diff(dot_dsc_differences):
assert dot_dsc_differences[1].source1 == 'test_1.tar.gz'
+
@skip_unless_module_exists('debian.deb822')
def test_dot_dsc_compare_non_existing(monkeypatch, dot_dsc1):
monkeypatch.setattr(Config(), 'new_file', True)
@@ -204,6 +226,7 @@ def dot_buildinfo1(tmpdir):
shutil.copy(TEST_DEB_FILE1_PATH, str(tmpdir.join('a/test_1_all.deb')))
return specialize(FilesystemFile(dot_buildinfo_path))
+
@pytest.fixture
def dot_buildinfo2(tmpdir):
tmpdir.mkdir('b')
@@ -213,9 +236,11 @@ def dot_buildinfo2(tmpdir):
shutil.copy(TEST_DEB_FILE2_PATH, str(tmpdir.join('b/test_1_all.deb')))
return specialize(FilesystemFile(dot_buildinfo_path))
+
def test_dot_buildinfo_identification(dot_buildinfo1):
assert isinstance(dot_buildinfo1, DotBuildinfoFile)
+
@skip_unless_module_exists('debian.deb822')
def test_dot_buildinfo_invalid(tmpdir):
tmpdir.mkdir('a')
@@ -225,23 +250,28 @@ def test_dot_buildinfo_invalid(tmpdir):
identified = specialize(FilesystemFile(dot_buildinfo_path))
assert not isinstance(identified, DotBuildinfoFile)
+
def test_dot_buildinfo_no_differences(dot_buildinfo1):
difference = dot_buildinfo1.compare(dot_buildinfo1)
assert difference is None
+
@pytest.fixture
def dot_buildinfo_differences(dot_buildinfo1, dot_buildinfo2):
difference = dot_buildinfo1.compare(dot_buildinfo2)
return difference.details
+
@skip_unless_module_exists('debian.deb822')
def test_dot_buildinfo_internal_diff(dot_buildinfo_differences):
assert dot_buildinfo_differences[1].source1 == 'test_1_all.deb'
+
@skip_unless_module_exists('debian.deb822')
def test_dot_buildinfo_compare_non_existing(monkeypatch, dot_buildinfo1):
assert_non_existing(monkeypatch, dot_buildinfo1)
+
def test_fallback_comparisons(monkeypatch):
manager = ComparatorManager()
monkeypatch.setattr(manager, 'COMPARATORS', (
diff --git a/tests/comparators/test_device.py b/tests/comparators/test_device.py
index b34a854..a021914 100644
--- a/tests/comparators/test_device.py
+++ b/tests/comparators/test_device.py
@@ -30,21 +30,26 @@ from ..utils.tools import skip_unless_tools_exist
text_ascii1 = load_fixture('text_ascii1')
+
@pytest.fixture
def devnull():
return specialize(FilesystemFile('/dev/null'))
+
@pytest.fixture
def differences(devnull, text_ascii1):
return devnull.compare_bytes(text_ascii1)
+
@pytest.fixture
def differences_reverse(text_ascii1, devnull):
return text_ascii1.compare_bytes(devnull)
+
def test_identification(devnull):
assert isinstance(devnull, Device)
+
@skip_unless_tools_exist('xxd')
def test_diff(differences):
if os.uname()[0] == 'FreeBSD':
@@ -53,6 +58,7 @@ def test_diff(differences):
expected_diff = get_data('device_expected_diff')
assert normalize_zeros(differences.unified_diff) == expected_diff
+
@skip_unless_tools_exist('xxd')
def test_diff_reverse(differences_reverse):
if os.uname()[0] == 'FreeBSD':
diff --git a/tests/comparators/test_dex.py b/tests/comparators/test_dex.py
index 549703a..7565c81 100644
--- a/tests/comparators/test_dex.py
+++ b/tests/comparators/test_dex.py
@@ -33,6 +33,7 @@ from .test_java import javap_version
dex1 = load_fixture('test1.dex')
dex2 = load_fixture('test2.dex')
+
def enjarify_version():
# Module enjarify.typeinference appeared in enjarify 1.0.3. We use a call
# directly to the python3 binary over importing with this module to escape
@@ -44,17 +45,21 @@ def enjarify_version():
return '1.0.3'
return '1.0.2'
+
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
+
@skip_unless_tools_exist('enjarify', 'zipinfo', 'javap')
@skip_unless_tool_is_at_least('javap', javap_version, '1.8')
@skip_unless_tool_is_at_least('enjarify', enjarify_version, '1.0.3')
@@ -71,6 +76,7 @@ def test_differences(differences):
found_diff = zipinfo.unified_diff + classdiff.details[0].unified_diff
assert expected_diff == found_diff
+
@skip_unless_tools_exist('enjarify', 'zipinfo', 'javap')
def test_compare_non_existing(monkeypatch, dex1):
monkeypatch.setattr(Config(), 'new_file', True)
diff --git a/tests/comparators/test_directory.py b/tests/comparators/test_directory.py
index 2c7c820..cc184e3 100644
--- a/tests/comparators/test_directory.py
+++ b/tests/comparators/test_directory.py
@@ -32,14 +32,17 @@ from ..utils.data import data, get_data
TEST_FILE1_PATH = data('text_ascii1')
TEST_FILE2_PATH = data('text_ascii2')
+
def test_no_differences():
difference = compare_directories(os.path.dirname(__file__), os.path.dirname(__file__))
assert difference is None
+
def test_no_differences_with_extra_slash():
difference = compare_directories(os.path.dirname(__file__) + '/', os.path.dirname(__file__))
assert difference is None
+
@pytest.fixture
def differences(tmpdir):
tmpdir.mkdir('a')
@@ -56,12 +59,14 @@ def differences(tmpdir):
os.utime(str(tmpdir.join('b')), (0, 0))
return compare_directories(str(tmpdir.join('a')), str(tmpdir.join('b'))).details
+
def test_content(differences):
assert differences[0].source1 == 'dir'
assert differences[0].details[0].source1 == 'text'
expected_diff = get_data('text_ascii_expected_diff')
assert differences[0].details[0].unified_diff == expected_diff
+
def test_stat(differences):
assert 'stat' in differences[0].details[0].details[0].source1
@@ -77,12 +82,14 @@ def test_compare_to_file(tmpdir):
assert a.compare(b).unified_diff == get_data('test_directory_file_diff')
+
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')
+
def test_compare_to_symlink(tmpdir):
path = str(tmpdir.join('src'))
os.symlink('/etc/passwd', path)
@@ -92,6 +99,7 @@ def test_compare_to_symlink(tmpdir):
assert a.compare(b).unified_diff == get_data('test_directory_symlink_diff')
+
def test_compare_to_dangling_symlink(tmpdir):
path = str(tmpdir.join('src'))
os.symlink('/dangling', path)
diff --git a/tests/comparators/test_dtb.py b/tests/comparators/test_dtb.py
index 6ebb4d6..e66c276 100644
--- a/tests/comparators/test_dtb.py
+++ b/tests/comparators/test_dtb.py
@@ -33,26 +33,32 @@ dtb1 = load_fixture('devicetree1.dtb')
# Generated by: dtc --in-format=dts --out-format=dtb --out=devicetree2.dtb devicetree2.dts
dtb2 = load_fixture('devicetree2.dtb')
+
def fdtdump_version():
out = subprocess.check_output(('fdtdump', '--version'), stderr=subprocess.STDOUT)
return out.decode().split()[2]
+
def test_identification(dtb1):
assert isinstance(dtb1, DeviceTreeFile)
+
def test_no_differences(dtb1):
difference = dtb1.compare(dtb1)
assert difference is None
+
@pytest.fixture
def differences(dtb1, dtb2):
return dtb1.compare(dtb2).details
+
@skip_unless_tool_is_at_least('fdtdump', fdtdump_version, '1.4.2')
def test_diff(differences):
expected_diff = get_data('devicetree_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('fdtdump')
def test_compare_non_existing(monkeypatch, dtb1):
monkeypatch.setattr(Config(), 'new_file', True)
diff --git a/tests/comparators/test_elf.py b/tests/comparators/test_elf.py
index 27c5894..dec380a 100644
--- a/tests/comparators/test_elf.py
+++ b/tests/comparators/test_elf.py
@@ -34,17 +34,21 @@ from ..utils.tools import skip_unless_tools_exist, \
obj1 = load_fixture('test1.o')
obj2 = load_fixture('test2.o')
+
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
+
@skip_unless_tools_exist('readelf')
@skip_if_binutils_does_not_support_x86()
def test_obj_compare_non_existing(monkeypatch, obj1):
@@ -53,6 +57,7 @@ def test_obj_compare_non_existing(monkeypatch, obj1):
assert difference.source2 == '/nonexisting'
assert len(difference.details) > 0
+
@skip_unless_tools_exist('readelf')
@skip_if_binutils_does_not_support_x86()
def test_diff(obj_differences):
@@ -64,25 +69,31 @@ def test_diff(obj_differences):
TEST_LIB1_PATH = data('test1.a')
TEST_LIB2_PATH = data('test2.a')
+
@pytest.fixture
def lib1():
return specialize(FilesystemFile(TEST_LIB1_PATH))
+
@pytest.fixture
def lib2():
return specialize(FilesystemFile(TEST_LIB2_PATH))
+
def test_lib_identification(lib1):
assert isinstance(lib1, StaticLibFile)
+
def test_lib_no_differences(lib1):
difference = lib1.compare(lib1)
assert difference is None
+
@pytest.fixture
def lib_differences(lib1, lib2):
return lib1.compare(lib2).details
+
@skip_unless_tools_exist('readelf', 'objdump')
@skip_if_binutils_does_not_support_x86()
def test_lib_differences(lib_differences):
@@ -94,6 +105,7 @@ def test_lib_differences(lib_differences):
expected_objdump_diff = get_data('elf_lib_objdump_expected_diff')
assert lib_differences[1].unified_diff == expected_objdump_diff
+
@skip_unless_tools_exist('readelf', 'objdump')
@skip_if_binutils_does_not_support_x86()
def test_lib_compare_non_existing(monkeypatch, lib1):
@@ -106,20 +118,24 @@ def test_lib_compare_non_existing(monkeypatch, lib1):
TEST_DBGSYM_DEB1_PATH = data('dbgsym/add/test-dbgsym_1_amd64.deb')
TEST_DBGSYM_DEB2_PATH = data('dbgsym/mult/test-dbgsym_1_amd64.deb')
+
@pytest.fixture
def dbgsym_dir1():
container = FilesystemDirectory(os.path.dirname(TEST_DBGSYM_DEB1_PATH)).as_container
return specialize(FilesystemFile(TEST_DBGSYM_DEB1_PATH, container=container))
+
@pytest.fixture
def dbgsym_dir2():
container = FilesystemDirectory(os.path.dirname(TEST_DBGSYM_DEB2_PATH)).as_container
return specialize(FilesystemFile(TEST_DBGSYM_DEB2_PATH, container=container))
+
@pytest.fixture
def dbgsym_differences(dbgsym_dir1, dbgsym_dir2):
return dbgsym_dir1.compare(dbgsym_dir2)
+
@skip_unless_tools_exist('readelf', 'objdump', 'objcopy')
@skip_if_binutils_does_not_support_x86()
@skip_unless_module_exists('debian.deb822')
@@ -130,6 +146,7 @@ def test_differences_with_dbgsym(dbgsym_differences):
assert bin_details.details[1].source1.startswith('objdump')
assert 'test-cases/dbgsym/package/test.c:2' in bin_details.details[1].unified_diff
+
@skip_unless_tools_exist('readelf', 'objdump', 'objcopy')
@skip_if_binutils_does_not_support_x86()
@skip_unless_module_exists('debian.deb822')
diff --git a/tests/comparators/test_epub.py b/tests/comparators/test_epub.py
index 2fbe5fa..893d9d5 100644
--- a/tests/comparators/test_epub.py
+++ b/tests/comparators/test_epub.py
@@ -30,17 +30,21 @@ from ..utils.tools import skip_unless_tools_exist
epub1 = load_fixture('test1.epub')
epub2 = load_fixture('test2.epub')
+
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
+
@skip_unless_tools_exist('zipinfo')
def test_differences(differences):
assert differences[0].source1 == 'zipinfo {}'
@@ -54,6 +58,7 @@ def test_differences(differences):
expected_diff = get_data('epub_expected_diffs')
assert expected_diff == "".join(map(lambda x: x.unified_diff, differences))
+
@skip_unless_tools_exist('zipinfo')
def test_compare_non_existing(monkeypatch, epub1):
monkeypatch.setattr(Config(), 'new_file', True)
diff --git a/tests/comparators/test_fonts.py b/tests/comparators/test_fonts.py
index 6951e5b..d41fb3e 100644
--- a/tests/comparators/test_fonts.py
+++ b/tests/comparators/test_fonts.py
@@ -30,22 +30,27 @@ from ..utils.tools import skip_unless_tools_exist
ttf1 = load_fixture('Samyak-Malayalam1.ttf')
ttf2 = load_fixture('Samyak-Malayalam2.ttf')
+
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
+
@skip_unless_tools_exist('showttf')
def test_diff(differences):
expected_diff = get_data('ttf_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('showttf')
def test_compare_non_existing(monkeypatch, ttf1):
monkeypatch.setattr(Config(), 'new_file', True)
diff --git a/tests/comparators/test_fsimage.py b/tests/comparators/test_fsimage.py
index ef5bd6c..b4d41f5 100644
--- a/tests/comparators/test_fsimage.py
+++ b/tests/comparators/test_fsimage.py
@@ -31,6 +31,7 @@ from ..utils.tools import skip_unless_tools_exist, skip_unless_module_exists
img1 = load_fixture('test1.ext4')
img2 = load_fixture('test2.ext4')
+
@pytest.fixture(scope="session")
def guestfs_tempdir():
import guestfs
@@ -50,19 +51,23 @@ def guestfs_tempdir():
pytest.skip('guestfs not working on the system: %r' % e)
yield cachedir
+
def test_identification(img1):
assert isinstance(img1, FsImageFile)
+
@skip_unless_tools_exist('qemu-img')
@skip_unless_module_exists('guestfs')
def test_no_differences(img1, guestfs_tempdir):
difference = img1.compare(img1)
assert difference is None
+
@pytest.fixture
def differences(img1, img2, guestfs_tempdir):
return img1.compare(img2).details
+
@skip_unless_tools_exist('qemu-img')
@skip_unless_module_exists('guestfs')
def test_differences(differences, guestfs_tempdir):
@@ -80,6 +85,7 @@ def test_differences(differences, guestfs_tempdir):
found_diff = tarinfo.unified_diff + tardiff.unified_diff + encodingdiff.unified_diff
assert expected_diff == found_diff
+
@skip_unless_tools_exist('qemu-img')
@skip_unless_module_exists('guestfs')
def test_compare_non_existing(monkeypatch, img1, guestfs_tempdir):
diff --git a/tests/comparators/test_gettext.py b/tests/comparators/test_gettext.py
index ac0767e..4d61e61 100644
--- a/tests/comparators/test_gettext.py
+++ b/tests/comparators/test_gettext.py
@@ -31,17 +31,21 @@ from ..utils.tools import skip_unless_tools_exist
mo1 = load_fixture('test1.mo')
mo2 = load_fixture('test2.mo')
+
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
+
@skip_unless_tools_exist('msgunfmt')
def test_diff(differences):
expected_diff = get_data('mo_expected_diff')
@@ -51,12 +55,14 @@ def test_diff(differences):
mo_no_charset = load_fixture('test_no_charset.mo')
mo_iso8859_1 = load_fixture('test_iso8859-1.mo')
+
@skip_unless_tools_exist('msgunfmt')
def test_charsets(mo_no_charset, mo_iso8859_1):
difference = mo_no_charset.compare(mo_iso8859_1)
expected_diff = codecs.open(data('mo_charsets_expected_diff'), encoding='utf-8').read()
assert difference.details[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('msgunfmt')
def test_compare_non_existing(monkeypatch, mo1):
monkeypatch.setattr(Config(), 'new_file', True)
diff --git a/tests/comparators/test_gif.py b/tests/comparators/test_gif.py
index 9755100..d7e0a80 100644
--- a/tests/comparators/test_gif.py
+++ b/tests/comparators/test_gif.py
@@ -35,23 +35,28 @@ gif4 = load_fixture('test4.gif')
def test_identification(gif1):
assert isinstance(gif1, GifFile)
+
def test_no_differences(gif1):
difference = gif1.compare(gif1)
assert difference is None
+
@pytest.fixture
def differences(gif1, gif2):
return gif1.compare(gif2).details
+
@skip_unless_tools_exist('gifbuild')
def test_diff(differences):
expected_diff = get_data('gif_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('gifbuild')
def test_compare_non_existing(monkeypatch, gif1):
assert_non_existing(monkeypatch, gif1, has_null_source=False)
+
@skip_unless_tools_exist('gifbuild', 'compose', 'convert', 'identify')
def test_has_visuals(monkeypatch, gif3, gif4):
monkeypatch.setattr(Config(), 'compute_visual_diffs', True)
@@ -61,6 +66,7 @@ def test_has_visuals(monkeypatch, gif3, gif4):
assert gif_diff.details[1].visuals[0].data_type == 'image/png;base64'
assert gif_diff.details[1].visuals[1].data_type == 'image/gif;base64'
+
@skip_unless_tools_exist('gifbuild', 'compose', 'convert', 'identify')
def test_no_visuals_different_size(monkeypatch, gif1, gif2):
monkeypatch.setattr(Config(), 'compute_visual_diffs', True)
diff --git a/tests/comparators/test_git.py b/tests/comparators/test_git.py
index c2b1247..dd0c02a 100644
--- a/tests/comparators/test_git.py
+++ b/tests/comparators/test_git.py
@@ -27,16 +27,20 @@ from ..utils.data import get_data, load_fixture
git1 = load_fixture('test1.git-index')
git2 = load_fixture('test2.git-index')
+
def test_identification(git1):
assert isinstance(git1, GitIndexFile)
+
def test_no_differences(git1):
assert git1.compare(git1) is None
+
@pytest.fixture
def differences(git1, git2):
return git1.compare(git2).details
+
def test_diff(differences):
expected_diff = get_data('git_expected_diff')
assert differences[0].unified_diff == expected_diff
diff --git a/tests/comparators/test_gzip.py b/tests/comparators/test_gzip.py
index 06d44af..0d4ae19 100644
--- a/tests/comparators/test_gzip.py
+++ b/tests/comparators/test_gzip.py
@@ -36,24 +36,29 @@ gzip2 = load_fixture('test2.gz')
def test_identification(gzip1):
assert isinstance(gzip1, GzipFile)
+
def test_no_differences(gzip1):
difference = gzip1.compare(gzip1)
assert difference is None
+
@pytest.fixture
def differences(gzip1, gzip2):
return gzip1.compare(gzip2).details
+
def test_metadata(differences):
assert differences[0].source1 == 'metadata'
assert differences[0].source2 == 'metadata'
expected_diff = get_data('gzip_metadata_expected_diff')
assert differences[0].unified_diff == expected_diff
+
def test_content_source(differences):
assert differences[1].source1 == 'test1'
assert differences[1].source2 == 'test2'
+
def test_content_source_without_extension(tmpdir, gzip1, gzip2):
path1 = str(tmpdir.join('test1'))
path2 = str(tmpdir.join('test2'))
@@ -65,10 +70,12 @@ def test_content_source_without_extension(tmpdir, gzip1, gzip2):
assert difference[1].source1 == 'test1-content'
assert difference[1].source2 == 'test2-content'
+
def test_content_diff(differences):
expected_diff = get_data('text_ascii_expected_diff')
assert differences[1].unified_diff == expected_diff
+
def test_compare_non_existing(monkeypatch, gzip1):
monkeypatch.setattr(Config(), 'new_file', True)
difference = gzip1.compare(MissingFile('/nonexisting', gzip1))
diff --git a/tests/comparators/test_haskell.py b/tests/comparators/test_haskell.py
index dd5bda9..fa6e763 100644
--- a/tests/comparators/test_haskell.py
+++ b/tests/comparators/test_haskell.py
@@ -29,6 +29,7 @@ from ..utils.tools import skip_unless_tools_exist
haskell1 = load_fixture('test1.hi')
haskell2 = load_fixture('test2.hi')
+
@skip_unless_tools_exist('ghc')
def test_identification(haskell1):
if isinstance(haskell1, FilesystemFile):
@@ -36,13 +37,16 @@ def test_identification(haskell1):
assert isinstance(haskell1, HiFile)
+
def test_no_differences(haskell1):
assert haskell1.compare(haskell1) is None
+
@pytest.fixture
def differences(haskell1, haskell2):
return haskell1.compare(haskell2).details
+
@skip_unless_tools_exist('ghc')
def test_diff(haskell1, differences):
if isinstance(haskell1, FilesystemFile):
diff --git a/tests/comparators/test_icc.py b/tests/comparators/test_icc.py
index 2c70e87..d5c131b 100644
--- a/tests/comparators/test_icc.py
+++ b/tests/comparators/test_icc.py
@@ -30,17 +30,21 @@ from ..utils.tools import skip_unless_tools_exist
icc1 = load_fixture('test1.icc')
icc2 = load_fixture('test2.icc')
+
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
+
@skip_unless_tools_exist('cd-iccdump')
def test_diff(differences):
if 'ne_SU' in differences[0].unified_diff:
@@ -50,6 +54,7 @@ def test_diff(differences):
expected_diff = get_data('icc_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('cd-iccdump')
def test_compare_non_existing(monkeypatch, icc1):
monkeypatch.setattr(Config(), 'new_file', True)
diff --git a/tests/comparators/test_ico_image.py b/tests/comparators/test_ico_image.py
index 8196c57..de230c1 100644
--- a/tests/comparators/test_ico_image.py
+++ b/tests/comparators/test_ico_image.py
@@ -33,38 +33,46 @@ image2 = load_fixture('test2.ico')
image1_meta = load_fixture('test1_meta.ico')
image2_meta = load_fixture('test2_meta.ico')
+
def test_identification(image1):
assert isinstance(image1, ICOImageFile)
+
def test_no_differences(image1):
difference = image1.compare(image1)
assert difference is None
+
@pytest.fixture
def differences(image1, image2):
return image1.compare(image2).details
+
@skip_unless_tools_exist('img2txt', 'convert')
def test_diff(differences):
expected_diff = get_data('ico_image_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@pytest.fixture
def differences_meta(image1_meta, image2_meta):
return image1_meta.compare(image2_meta).details
+
@skip_unless_tools_exist('img2txt', 'identify')
@skip_unless_tool_is_between('identify', identify_version, '6.9.6', '6.9.8-3')
def test_diff_meta(differences_meta):
expected_diff = get_data('ico_image_meta_expected_diff')
assert differences_meta[-1].unified_diff == expected_diff
+
@skip_unless_tools_exist('img2txt', 'identify')
@skip_unless_tool_is_at_least('identify', identify_version, '6.9.8-4')
def test_diff_meta(differences_meta):
expected_diff = get_data('ico_image_meta_expected_diff_v2')
assert differences_meta[-1].unified_diff == expected_diff
+
@skip_unless_tools_exist('img2txt', 'compose', 'convert', 'identify')
def test_has_visuals(monkeypatch, image1, image2):
monkeypatch.setattr(Config(), 'compute_visual_diffs', True)
diff --git a/tests/comparators/test_ipk.py b/tests/comparators/test_ipk.py
index c96eb2a..b16f4aa 100644
--- a/tests/comparators/test_ipk.py
+++ b/tests/comparators/test_ipk.py
@@ -29,26 +29,32 @@ from ..utils.data import load_fixture, get_data
ipk1 = load_fixture('base-files_157-r45695_ar71xx.ipk')
ipk2 = load_fixture('base-files_157-r45918_ar71xx.ipk')
+
def test_identification(ipk1):
assert isinstance(ipk1, IpkFile)
+
def test_no_differences(ipk1):
difference = ipk1.compare(ipk1)
assert difference is None
+
@pytest.fixture
def differences(ipk1, ipk2):
return ipk1.compare(ipk2).details
+
def test_metadata(differences):
assert differences[0].source1 == 'metadata'
expected_diff = get_data('ipk_metadata_expected_diff')
assert differences[0].unified_diff == expected_diff
+
def test_compressed_files(differences):
assert differences[1].details[1].source1 == './data.tar.gz'
assert differences[1].details[2].source1 == './control.tar.gz'
+
def test_compare_non_existing(monkeypatch, ipk1):
monkeypatch.setattr(Config(), 'new_file', True)
difference = ipk1.compare(MissingFile('/nonexisting', ipk1))
diff --git a/tests/comparators/test_iso9660.py b/tests/comparators/test_iso9660.py
index eeaa2db..9c9622c 100644
--- a/tests/comparators/test_iso9660.py
+++ b/tests/comparators/test_iso9660.py
@@ -31,23 +31,28 @@ from ..utils.tools import skip_unless_tools_exist
iso1 = load_fixture('test1.iso')
iso2 = load_fixture('test2.iso')
+
def is_cdrtools():
if b"Schilling" in subprocess.check_output(['isoinfo', '--version']):
return True
else:
return False
+
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
+
@skip_unless_tools_exist('isoinfo')
def test_iso9660_content(differences):
if is_cdrtools():
@@ -56,6 +61,7 @@ def test_iso9660_content(differences):
expected_diff = get_data('iso9660_content_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('isoinfo')
def test_iso9660_rockridge(differences):
if is_cdrtools():
@@ -64,12 +70,14 @@ def test_iso9660_rockridge(differences):
expected_diff = get_data('iso9660_rockridge_expected_diff')
assert differences[1].unified_diff == expected_diff
+
@skip_unless_tools_exist('isoinfo')
def test_symlink(differences):
assert differences[3].comment == 'symlink'
expected_diff = get_data('symlink_expected_diff')
assert differences[3].unified_diff == expected_diff
+
@skip_unless_tools_exist('isoinfo')
def test_compressed_files(differences):
assert differences[2].source1 == 'text'
@@ -77,6 +85,7 @@ def test_compressed_files(differences):
expected_diff = get_data('text_ascii_expected_diff')
assert differences[2].unified_diff == expected_diff
+
@skip_unless_tools_exist('isoinfo')
def test_compare_non_existing(monkeypatch, iso1):
monkeypatch.setattr(Config(), 'new_file', True)
diff --git a/tests/comparators/test_java.py b/tests/comparators/test_java.py
index f4b35ea..2be6af3 100644
--- a/tests/comparators/test_java.py
+++ b/tests/comparators/test_java.py
@@ -31,6 +31,7 @@ from ..utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
class1 = load_fixture('Test1.class')
class2 = load_fixture('Test2.class')
+
def javap_version():
try:
out = subprocess.check_output(['javap', '-version'])
@@ -38,22 +39,27 @@ def javap_version():
out = e.output
return out.decode('UTF-8').strip()
+
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
+
@skip_unless_tool_is_at_least('javap', javap_version, '1.8')
def test_diff(differences):
expected_diff = get_data('class_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('javap')
def test_compare_non_existing(monkeypatch, class1):
monkeypatch.setattr(Config(), 'new_file', True)
diff --git a/tests/comparators/test_javascript.py b/tests/comparators/test_javascript.py
index ba0cd5f..b14e2bd 100644
--- a/tests/comparators/test_javascript.py
+++ b/tests/comparators/test_javascript.py
@@ -30,22 +30,27 @@ from ..utils.tools import skip_unless_tools_exist
javascript1 = load_fixture('test1.js')
javascript2 = load_fixture('test2.js')
+
def test_identification(javascript1):
assert isinstance(javascript1, JavaScriptFile)
+
def test_no_differences(javascript1):
difference = javascript1.compare(javascript1)
assert difference is None
+
@pytest.fixture
def differences(javascript1, javascript2):
return javascript1.compare(javascript2).details
+
@skip_unless_tools_exist('js-beautify')
def test_diff(differences):
expected_diff = get_data('javascript_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('js-beautify')
def test_compare_non_existing(monkeypatch, javascript1):
monkeypatch.setattr(Config(), 'new_file', True)
diff --git a/tests/comparators/test_jpeg_image.py b/tests/comparators/test_jpeg_image.py
index 89ac42f..ab23547 100644
--- a/tests/comparators/test_jpeg_image.py
+++ b/tests/comparators/test_jpeg_image.py
@@ -33,6 +33,7 @@ image2 = load_fixture('test2.jpg')
image1_meta = load_fixture('test1_meta.jpg')
image2_meta = load_fixture('test2_meta.jpg')
+
def identify_version():
out = subprocess.check_output(['identify', '-version']).decode('utf-8')
# First line is expected to look like
@@ -41,22 +42,27 @@ def identify_version():
return '0.0.0'
return out.splitlines()[0].split()[2].strip()
+
def test_identification(image1):
assert isinstance(image1, JPEGImageFile)
+
def test_no_differences(image1):
difference = image1.compare(image1)
assert difference is None
+
@pytest.fixture
def differences(image1, image2):
return image1.compare(image2).details
+
@skip_unless_tools_exist('img2txt', 'identify')
def test_diff(differences):
expected_diff = get_data('jpeg_image_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('img2txt', 'identify')
def test_compare_non_existing(monkeypatch, image1):
monkeypatch.setattr(Config(), 'new_file', True)
@@ -64,16 +70,19 @@ def test_compare_non_existing(monkeypatch, image1):
assert difference.source2 == '/nonexisting'
assert len(difference.details) > 0
+
@pytest.fixture
def differences_meta(image1_meta, image2_meta):
return image1_meta.compare(image2_meta).details
+
@skip_unless_tools_exist('img2txt', 'identify')
@skip_unless_tool_is_at_least('identify', identify_version, '6.9.6')
def test_diff_meta(differences_meta):
expected_diff = get_data('jpeg_image_meta_expected_diff')
assert differences_meta[-1].unified_diff == expected_diff
+
@skip_unless_tools_exist('img2txt', 'compose', 'convert', 'identify')
def test_has_visuals(monkeypatch, image1, image2):
monkeypatch.setattr(Config(), 'compute_visual_diffs', True)
diff --git a/tests/comparators/test_json.py b/tests/comparators/test_json.py
index f10da08..0eff3dc 100644
--- a/tests/comparators/test_json.py
+++ b/tests/comparators/test_json.py
@@ -31,27 +31,34 @@ json3a = load_fixture('order1a.json')
json3b = load_fixture('order1b.json')
invalid_json = load_fixture('test_invalid.json')
+
def test_identification(json1):
assert isinstance(json1, JSONFile)
+
def test_invalid(invalid_json):
assert not isinstance(invalid_json, JSONFile)
+
def test_no_differences(json1):
assert json1.compare(json1) is None
+
@pytest.fixture
def differences(json1, json2):
return json1.compare(json2).details
+
def test_diff(differences):
expected_diff = get_data('json_expected_diff')
assert differences[0].unified_diff == expected_diff
+
def test_compare_non_existing(monkeypatch, json1):
assert_non_existing(monkeypatch, json1)
+
def test_ordering_differences(json3a, json3b):
diff = json3a.compare(json3b)
assert diff.details[0]._comments == ['ordering differences only']
diff --git a/tests/comparators/test_macho.py b/tests/comparators/test_macho.py
index 16ac6be..750cfcc 100644
--- a/tests/comparators/test_macho.py
+++ b/tests/comparators/test_macho.py
@@ -32,17 +32,21 @@ from ..utils.tools import skip_unless_tools_exist
obj1 = load_fixture('test1.macho')
obj2 = load_fixture('test2.macho')
+
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
+
@skip_unless_tools_exist('otool', 'lipo')
def test_obj_compare_non_existing(monkeypatch, obj1):
monkeypatch.setattr(Config(), 'new_file', True)
@@ -50,6 +54,7 @@ def test_obj_compare_non_existing(monkeypatch, obj1):
assert difference.source2 == '/nonexisting'
assert len(difference.details) > 0
+
@skip_unless_tools_exist('otool', 'lipo')
def test_diff(obj_differences):
assert len(obj_differences) == 4
diff --git a/tests/comparators/test_mono.py b/tests/comparators/test_mono.py
index bc279af..44806d3 100644
--- a/tests/comparators/test_mono.py
+++ b/tests/comparators/test_mono.py
@@ -35,22 +35,27 @@ from ..utils.tools import skip_unless_tools_exist
exe1 = load_fixture('test1.exe')
exe2 = load_fixture('test2.exe')
+
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
+
@skip_unless_tools_exist('pedump')
def test_diff(differences):
expected_diff = get_data('pe_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('pedump')
def test_compare_non_existing(monkeypatch, exe1):
monkeypatch.setattr(Config(), 'new_file', True)
diff --git a/tests/comparators/test_openssh_pub_key.py b/tests/comparators/test_openssh_pub_key.py
index a1182fc..b5cf962 100644
--- a/tests/comparators/test_openssh_pub_key.py
+++ b/tests/comparators/test_openssh_pub_key.py
@@ -42,19 +42,23 @@ def openssh_version():
def test_identification(opensshpubkey1):
assert isinstance(opensshpubkey1, PublicKeyFile)
+
def test_no_differences(opensshpubkey1):
difference = opensshpubkey1.compare(opensshpubkey1)
assert difference is None
+
@pytest.fixture
def differences(opensshpubkey1, opensshpubkey2):
return opensshpubkey1.compare(opensshpubkey2).details
+
@skip_unless_tool_is_at_least('ssh-keygen', openssh_version, '6.9')
def test_diff(differences):
expected_diff = get_data('openssh_pub_key_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('ssh-keygen')
def test_compare_non_existing(monkeypatch, opensshpubkey1):
monkeypatch.setattr(Config(), 'new_file', True)
diff --git a/tests/comparators/test_pdf.py b/tests/comparators/test_pdf.py
index 4c1e1b5..3fbed1d 100644
--- a/tests/comparators/test_pdf.py
+++ b/tests/comparators/test_pdf.py
@@ -29,27 +29,33 @@ from ..utils.nonexisting import assert_non_existing
pdf1 = load_fixture('test1.pdf')
pdf2 = load_fixture('test2.pdf')
+
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
+
@skip_unless_tools_exist('pdftk', 'pdftotext')
def test_text_diff(differences):
expected_diff = get_data('pdf_text_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('pdftk', 'pdftotext')
def test_internal_diff(differences):
expected_diff = get_data('pdf_internal_expected_diff')
assert differences[1].unified_diff == expected_diff
+
@skip_unless_tools_exist('pdftk', 'pdftotext')
def test_compare_non_existing(monkeypatch, pdf1):
assert_non_existing(monkeypatch, pdf1, has_null_source=False)
diff --git a/tests/comparators/test_png.py b/tests/comparators/test_png.py
index 8abb6f5..9b0f575 100644
--- a/tests/comparators/test_png.py
+++ b/tests/comparators/test_png.py
@@ -30,26 +30,32 @@ from ..utils.nonexisting import assert_non_existing
png1 = load_fixture('test1.png')
png2 = load_fixture('test2.png')
+
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
+
@skip_unless_tools_exist('sng')
def test_diff(differences):
expected_diff = get_data('png_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('sng')
def test_compare_non_existing(monkeypatch, png1):
assert_non_existing(monkeypatch, png1, has_null_source=False)
+
@skip_unless_tools_exist('sng', 'compose', 'convert', 'identify')
def test_has_visuals(monkeypatch, png1, png2):
monkeypatch.setattr(Config(), 'compute_visual_diffs', True)
diff --git a/tests/comparators/test_ppu.py b/tests/comparators/test_ppu.py
index 3b39d49..20290bd 100644
--- a/tests/comparators/test_ppu.py
+++ b/tests/comparators/test_ppu.py
@@ -37,30 +37,36 @@ from ..utils.nonexisting import assert_non_existing
file1 = load_fixture('test1.ppu')
file2 = load_fixture('test2.ppu')
+
def ppudump_version():
# first line of `PPU-Analyser Version 3.0.0` looks like:
# PPU-Analyser Version 3.0.0
out = subprocess.check_output(['ppudump', '-h'])
return out.decode('utf-8').splitlines()[0].split()[2].strip()
+
@skip_unless_tools_exist('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
+
@skip_unless_tool_is_at_least('ppudump', ppudump_version, '3.0.0')
def test_diff(differences):
print(differences[0].unified_diff)
expected_diff = get_data('ppu_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tool_is_at_least('ppudump', ppudump_version, '3.0.0')
def test_compare_non_existing(monkeypatch, file1):
assert_non_existing(monkeypatch, file1, has_null_source=False)
diff --git a/tests/comparators/test_ps.py b/tests/comparators/test_ps.py
index fd29d86..568fe38 100644
--- a/tests/comparators/test_ps.py
+++ b/tests/comparators/test_ps.py
@@ -29,27 +29,33 @@ from ..utils.nonexisting import assert_non_existing
ps1 = load_fixture('test1.ps')
ps2 = load_fixture('test2.ps')
+
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)
+
@skip_unless_tools_exist('ps2ascii')
def test_internal_diff(differences):
expected_diff = get_data('ps_internal_expected_diff')
assert differences.unified_diff == expected_diff
+
@skip_unless_tools_exist('ps2ascii')
def test_text_diff(differences):
expected_diff = get_data('ps_text_expected_diff')
assert differences.details[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('ps2ascii')
def test_compare_non_existing(monkeypatch, ps1):
assert_non_existing(monkeypatch, ps1, has_null_source=False)
diff --git a/tests/comparators/test_rdata.py b/tests/comparators/test_rdata.py
index f45e7ea..05fe149 100644
--- a/tests/comparators/test_rdata.py
+++ b/tests/comparators/test_rdata.py
@@ -28,21 +28,26 @@ from ..utils.tools import skip_unless_tools_exist
file1 = load_fixture('test1.rdx')
file2 = load_fixture('test2.rdx')
+
def test_identification(file1):
assert isinstance(file1, GzipFile)
+
def test_no_differences(file1):
difference = file1.compare(file1)
assert difference is None
+
@pytest.fixture
def differences(file1, file2):
return file1.compare(file2).details
+
@skip_unless_tools_exist('Rscript')
def test_num_items(differences):
assert len(differences) == 1
+
@skip_unless_tools_exist('Rscript')
def test_item_rds(differences):
assert differences[0].source1 == 'test1.rdx-content'
diff --git a/tests/comparators/test_rlib.py b/tests/comparators/test_rlib.py
index 98d35a7..16987b4 100644
--- a/tests/comparators/test_rlib.py
+++ b/tests/comparators/test_rlib.py
@@ -33,24 +33,30 @@ from ..utils.nonexisting import assert_non_existing
rlib1 = load_fixture('test1.rlib')
rlib2 = load_fixture('test2.rlib')
+
def llvm_version():
return subprocess.check_output(['llvm-config', '--version']).decode("utf-8").strip()
+
def test_identification(rlib1):
assert isinstance(rlib1, ArFile)
+
def test_no_differences(rlib1):
difference = rlib1.compare(rlib1)
assert difference is None
+
@pytest.fixture
def differences(rlib1, rlib2):
return rlib1.compare(rlib2).details
+
@skip_unless_tools_exist('nm')
def test_num_items(differences):
assert len(differences) == 4
+
@skip_unless_tools_exist('nm')
@skip_if_binutils_does_not_support_x86()
def test_item0_armap(differences):
@@ -59,6 +65,7 @@ def test_item0_armap(differences):
expected_diff = get_data('rlib_armap_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('nm')
@skip_if_binutils_does_not_support_x86()
def test_item1_elf(differences):
@@ -67,11 +74,13 @@ def test_item1_elf(differences):
expected_diff = get_data('rlib_elf_expected_diff')
assert differences[1].details[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('nm')
def test_item2_rust_metadata_bin(differences):
assert differences[2].source1 == 'rust.metadata.bin'
assert differences[2].source2 == 'rust.metadata.bin'
+
@skip_unless_tools_exist('llvm-dis')
@skip_unless_tool_is_at_least('llvm-config', llvm_version, '3.8')
def test_item3_deflate_llvm_bitcode(differences):
@@ -81,6 +90,7 @@ def test_item3_deflate_llvm_bitcode(differences):
actual_diff = differences[3].details[0].details[1].unified_diff
assert diff_ignore_line_numbers(actual_diff) == diff_ignore_line_numbers(expected_diff)
+
@skip_unless_tools_exist('nm')
def test_compare_non_existing(monkeypatch, rlib1):
assert_non_existing(monkeypatch, rlib1)
diff --git a/tests/comparators/test_sqlite.py b/tests/comparators/test_sqlite.py
index cfee6fd..da66767 100644
--- a/tests/comparators/test_sqlite.py
+++ b/tests/comparators/test_sqlite.py
@@ -29,23 +29,28 @@ from ..utils.nonexisting import assert_non_existing
sqlite3db1 = load_fixture('test1.sqlite3')
sqlite3db2 = load_fixture('test2.sqlite3')
+
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
+
@skip_unless_tools_exist('sqlite3')
def test_diff(differences):
expected_diff = get_data('sqlite3_expected_diff')
actual_diff = differences[0].unified_diff
assert actual_diff == expected_diff or actual_diff == expected_diff.replace('"test"', 'test')
+
@skip_unless_tools_exist('sqlite3')
def test_compare_non_existing(monkeypatch, sqlite3db1):
assert_non_existing(monkeypatch, sqlite3db1, has_null_source=False)
diff --git a/tests/comparators/test_squashfs.py b/tests/comparators/test_squashfs.py
index 277e0c4..4122d4c 100644
--- a/tests/comparators/test_squashfs.py
+++ b/tests/comparators/test_squashfs.py
@@ -40,33 +40,40 @@ def unsquashfs_version():
squashfs1 = load_fixture('test1.squashfs')
squashfs2 = load_fixture('test2.squashfs')
+
def test_identification(squashfs1):
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
+
@skip_unless_tool_is_at_least('unsquashfs', unsquashfs_version, '4.3')
def test_superblock(differences):
expected_diff = get_data('squashfs_superblock_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('unsquashfs')
def test_symlink(differences):
assert differences[2].comment == 'symlink'
expected_diff = get_data('symlink_expected_diff')
assert differences[2].unified_diff == expected_diff
+
@skip_unless_tools_exist('unsquashfs')
def test_compressed_files(differences):
assert differences[3].source1 == '/text'
@@ -74,6 +81,7 @@ def test_compressed_files(differences):
expected_diff = get_data('text_ascii_expected_diff')
assert differences[3].unified_diff == expected_diff
+
@skip_unless_tools_exist('unsquashfs')
def test_compare_non_existing(monkeypatch, squashfs1):
assert_non_existing(monkeypatch, squashfs1)
diff --git a/tests/comparators/test_tar.py b/tests/comparators/test_tar.py
index 2cfd693..fbb5a0f 100644
--- a/tests/comparators/test_tar.py
+++ b/tests/comparators/test_tar.py
@@ -30,21 +30,26 @@ from ..utils.nonexisting import assert_non_existing
tar1 = load_fixture('test1.tar')
tar2 = load_fixture('test2.tar')
+
def test_identification(tar1):
assert isinstance(tar1, TarFile)
+
def test_no_differences(tar1):
difference = tar1.compare(tar1)
assert difference is None
+
@pytest.fixture
def differences(tar1, tar2):
return tar1.compare(tar2).details
+
def test_listing(differences):
expected_diff = get_data('tar_listing_expected_diff')
assert differences[0].unified_diff == expected_diff
+
def test_symlinks(differences):
assert differences[2].source1 == 'dir/link'
assert differences[2].source2 == 'dir/link'
@@ -52,12 +57,14 @@ def test_symlinks(differences):
expected_diff = get_data('symlink_expected_diff')
assert differences[2].unified_diff == expected_diff
+
def test_text_file(differences):
assert differences[1].source1 == 'dir/text'
assert differences[1].source2 == 'dir/text'
expected_diff = get_data('text_ascii_expected_diff')
assert differences[1].unified_diff == expected_diff
+
def test_compare_non_existing(monkeypatch, tar1):
assert_non_existing(monkeypatch, tar1)
@@ -66,6 +73,8 @@ no_permissions_tar = load_fixture('no-perms.tar')
# Reported as Debian #797164. This is a good way to notice if we unpack directories
# as we won't be able to remove files in one if we don't have write permissions.
+
+
def test_no_permissions_dir_in_tarball(monkeypatch, no_permissions_tar):
# We want to make sure OSError is not raised.
# Comparing with non-existing file makes it easy to make sure all files are unpacked
diff --git a/tests/comparators/test_text.py b/tests/comparators/test_text.py
index 67f5810..5a1eac8 100644
--- a/tests/comparators/test_text.py
+++ b/tests/comparators/test_text.py
@@ -29,10 +29,12 @@ from ..utils.nonexisting import assert_non_existing
ascii1 = load_fixture('text_ascii1')
ascii2 = load_fixture('text_ascii2')
+
def test_no_differences(ascii1):
difference = ascii1.compare(ascii1)
assert difference is None
+
def test_difference_in_ascii(ascii1, ascii2):
difference = ascii1.compare(ascii2)
assert difference is not None
@@ -45,6 +47,7 @@ def test_difference_in_ascii(ascii1, ascii2):
unicode1 = load_fixture('text_unicode1')
unicode2 = load_fixture('text_unicode2')
+
def test_difference_in_unicode(unicode1, unicode2):
difference = unicode1.compare(unicode2)
expected_diff = codecs.open(data('text_unicode_expected_diff'), encoding='utf-8').read()
@@ -53,11 +56,13 @@ def test_difference_in_unicode(unicode1, unicode2):
iso8859 = load_fixture('text_iso8859')
+
def test_difference_between_iso88591_and_unicode(iso8859, unicode1):
difference = iso8859.compare(unicode1)
expected_diff = codecs.open(data('text_iso8859_expected_diff'), encoding='utf-8').read()
assert difference.unified_diff == expected_diff
+
def test_difference_between_iso88591_and_unicode_only(iso8859, tmpdir):
utf8_path = str(tmpdir.join('utf8'))
with open(utf8_path, 'wb') as f:
@@ -67,6 +72,7 @@ def test_difference_between_iso88591_and_unicode_only(iso8859, tmpdir):
assert difference.unified_diff is None
assert difference.details[0].source1 == 'encoding'
+
def test_compare_non_existing(monkeypatch, ascii1):
assert_non_existing(monkeypatch, ascii1, has_null_source=False, has_details=False)
@@ -74,6 +80,7 @@ def test_compare_non_existing(monkeypatch, ascii1):
text_order1 = load_fixture('text_order1')
text_order2 = load_fixture('text_order2')
+
def test_ordering_differences(text_order1, text_order2):
difference = text_order1.compare(text_order2)
assert difference.comments == ['ordering differences only']
diff --git a/tests/comparators/test_utils.py b/tests/comparators/test_utils.py
index 831f319..7de6350 100644
--- a/tests/comparators/test_utils.py
+++ b/tests/comparators/test_utils.py
@@ -33,20 +33,24 @@ fuzzy_tar1 = load_fixture('fuzzy1.tar')
fuzzy_tar2 = load_fixture('fuzzy2.tar')
fuzzy_tar3 = load_fixture('fuzzy3.tar')
+
def test_tools_missing():
assert tools_missing() is True
assert tools_missing('/missing') is True
for x in ['cat', 'sh']:
assert tools_missing(x) is False
+
@skip_unless_tools_exist()
def test_skip_unless_tools_exist_empty():
pytest.xfail("Test should always be skipped")
+
@skip_unless_tools_exist('/missing')
def test_skip_unless_tools_exist_missing():
pytest.xfail("Test should always be skipped")
+
def skip_unless_tool_is_at_least():
func = skip_unless_tool_is_at_least
assert func('/missing', 1, 1).name is 'skip'
@@ -58,6 +62,7 @@ def skip_unless_tool_is_at_least():
return '4.3-git'
assert func('cat', version, '4.3').args[0] is False
+
@skip_unless_module_exists('tlsh')
def test_fuzzy_matching(fuzzy_tar1, fuzzy_tar2):
differences = fuzzy_tar1.compare(fuzzy_tar2).details
@@ -67,6 +72,7 @@ def test_fuzzy_matching(fuzzy_tar1, fuzzy_tar2):
assert 'similar' in differences[1].comment
assert differences[1].unified_diff == expected_diff
+
@skip_unless_module_exists('tlsh')
def test_fuzzy_matching_only_once(fuzzy_tar1, fuzzy_tar3):
differences = fuzzy_tar1.compare(fuzzy_tar3).details
@@ -76,6 +82,7 @@ def test_fuzzy_matching_only_once(fuzzy_tar1, fuzzy_tar3):
fuzzy_tar_in_tar1 = load_fixture('fuzzy-tar-in-tar1.tar')
fuzzy_tar_in_tar2 = load_fixture('fuzzy-tar-in-tar2.tar')
+
@skip_unless_module_exists('tlsh')
def test_no_fuzzy_matching(monkeypatch, fuzzy_tar_in_tar1, fuzzy_tar_in_tar2):
monkeypatch.setattr(Config(), 'fuzzy_threshold', 0)
@@ -83,6 +90,7 @@ def test_no_fuzzy_matching(monkeypatch, fuzzy_tar_in_tar1, fuzzy_tar_in_tar2):
assert len(difference.details) == 1
assert difference.details[0].source1 == 'file list'
+
@skip_unless_module_exists('tlsh')
def test_no_fuzzy_matching_new_file(monkeypatch, fuzzy_tar_in_tar1, fuzzy_tar_in_tar2):
monkeypatch.setattr(Config(), 'fuzzy_threshold', 0)
@@ -92,6 +100,7 @@ def test_no_fuzzy_matching_new_file(monkeypatch, fuzzy_tar_in_tar1, fuzzy_tar_in
assert difference.details[1].source2 == '/dev/null'
assert difference.details[2].source1 == '/dev/null'
+
@skip_unless_tools_exist('tee')
def test_trim_stderr_in_command():
class FillStderr(Command):
diff --git a/tests/comparators/test_xz.py b/tests/comparators/test_xz.py
index 073c658..97cca09 100644
--- a/tests/comparators/test_xz.py
+++ b/tests/comparators/test_xz.py
@@ -31,22 +31,27 @@ from ..utils.nonexisting import assert_non_existing
xz1 = load_fixture('test1.xz')
xz2 = load_fixture('test2.xz')
+
def test_identification(xz1):
assert isinstance(xz1, XzFile)
+
def test_no_differences(xz1):
difference = xz1.compare(xz1)
assert difference is None
+
@pytest.fixture
def differences(xz1, xz2):
return xz1.compare(xz2).details
+
@skip_unless_tools_exist('xz')
def test_content_source(differences):
assert differences[0].source1 == 'test1'
assert differences[0].source2 == 'test2'
+
@skip_unless_tools_exist('xz')
def test_content_source_without_extension(tmpdir, xz1, xz2):
path1 = str(tmpdir.join('test1'))
@@ -59,11 +64,13 @@ def test_content_source_without_extension(tmpdir, xz1, xz2):
assert difference[0].source1 == 'test1-content'
assert difference[0].source2 == 'test2-content'
+
@skip_unless_tools_exist('xz')
def test_content_diff(differences):
expected_diff = get_data('text_ascii_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('xz')
def test_compare_non_existing(monkeypatch, xz1):
assert_non_existing(monkeypatch, xz1)
diff --git a/tests/comparators/test_zip.py b/tests/comparators/test_zip.py
index 74eb354..31c4b60 100644
--- a/tests/comparators/test_zip.py
+++ b/tests/comparators/test_zip.py
@@ -36,23 +36,28 @@ mozzip2 = load_fixture('test2.mozzip')
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.fixture
def differences2(zip1, zip3):
return zip1.compare(zip3).details
+
@skip_unless_tools_exist('zipinfo')
def test_metadata(differences):
expected_diff = get_data('zip_zipinfo_expected_diff')
assert differences[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('zipinfo')
def test_compressed_files(differences):
assert differences[1].source1 == 'dir/text'
@@ -60,26 +65,32 @@ def test_compressed_files(differences):
expected_diff = get_data('text_ascii_expected_diff')
assert differences[1].unified_diff == expected_diff
+
@skip_unless_tools_exist('zipinfo', 'bsdtar')
def test_extra_fields(differences2):
expected_diff = get_data('zip_bsdtar_expected_diff')
assert differences2[0].unified_diff == expected_diff
+
@skip_unless_tools_exist('zipinfo')
def test_compare_non_existing(monkeypatch, zip1):
assert_non_existing(monkeypatch, zip1)
+
def test_mozzip_identification(mozzip1):
assert isinstance(mozzip1, MozillaZipFile)
+
def test_mozzip_no_differences(mozzip1):
difference = mozzip1.compare(mozzip1)
assert difference is None
+
@pytest.fixture
def mozzip_differences(mozzip1, mozzip2):
return mozzip1.compare(mozzip2).details
+
@skip_unless_tools_exist('zipinfo')
def test_mozzip_metadata(mozzip_differences, mozzip1, mozzip2):
expected_diff = get_data('mozzip_zipinfo_expected_diff')
@@ -87,6 +98,7 @@ def test_mozzip_metadata(mozzip_differences, mozzip1, mozzip2):
assert (diff.replace(mozzip1.path, 'test1.mozzip')
.replace(mozzip2.path, 'test2.mozzip')) == expected_diff
+
@skip_unless_tools_exist('zipinfo')
def test_mozzip_compressed_files(mozzip_differences):
assert mozzip_differences[1].source1 == 'dir/text'
@@ -94,6 +106,7 @@ def test_mozzip_compressed_files(mozzip_differences):
expected_diff = get_data('text_ascii_expected_diff')
assert mozzip_differences[1].unified_diff == expected_diff
+
@skip_unless_tools_exist('zipinfo')
def test_mozzip_compare_non_existing(monkeypatch, mozzip1):
assert_non_existing(monkeypatch, mozzip1)
diff --git a/tests/test_difference.py b/tests/test_difference.py
index 1b46e2f..291896c 100644
--- a/tests/test_difference.py
+++ b/tests/test_difference.py
@@ -31,10 +31,12 @@ def assert_size(diff, size):
g = itertools.count()
assert size == sum(d.size_self() for d in diff.traverse_heapq(lambda x, _: next(g)))
+
def assert_algebraic_properties(d, size):
assert d.equals(d.get_reverse().get_reverse())
assert d.get_reverse().size() == d.size() == size
+
def test_too_much_input_for_diff(monkeypatch):
monkeypatch.setattr(Config(), 'max_diff_input_lines', 20)
too_long_text_a = io.StringIO("a\n" * 21)
@@ -43,6 +45,7 @@ def test_too_much_input_for_diff(monkeypatch):
assert '[ Too much input for diff ' in difference.unified_diff
assert_algebraic_properties(difference, 290)
+
def test_too_long_diff_block_lines(monkeypatch):
monkeypatch.setattr(Config(), 'enforce_constraints', False)
monkeypatch.setattr(Config(), 'max_diff_block_lines_saved', 10)
@@ -52,6 +55,7 @@ def test_too_long_diff_block_lines(monkeypatch):
assert '[ 11 lines removed ]' in difference.unified_diff
assert_algebraic_properties(difference, 124)
+
def test_size_updates():
d = Difference("0123456789", "path1", "path2")
assert_size(d, 20)
@@ -60,6 +64,7 @@ def test_size_updates():
d.add_comment("lol1")
assert_size(d, 48)
+
def test_traverse_heapq():
d0 = Difference("0", "path1/a", "path2/a")
d1 = Difference("012", "path1/b", "path2/b")
@@ -88,6 +93,7 @@ def test_traverse_heapq():
results = [d.source1[6:] for d in diff.traverse_heapq(f)]
assert results == ['', 'a', 'c', 'b', 'c/1', 'a/3', 'a/2', 'b/2', 'b/3', 'c/3', 'b/1', 'a/1', 'c/2']
+
def test_non_str_arguments_to_source1_source2():
for x in (
(None, 'str'),
diff --git a/tests/test_excludes.py b/tests/test_excludes.py
index 029a717..789ab6f 100644
--- a/tests/test_excludes.py
+++ b/tests/test_excludes.py
@@ -36,6 +36,7 @@ def run(capsys, *args):
return exc.value.code, out
+
def test_none(capsys):
ret, out = run(capsys)
@@ -43,12 +44,14 @@ def test_none(capsys):
assert '── dir/text' in out
assert '── dir/link' in out
+
def test_all(capsys):
ret, out = run(capsys, '--exclude=*')
assert ret == 0
assert out == ''
+
def test_specific(capsys):
ret, out = run(capsys, '--exclude=dir/text')
@@ -56,6 +59,7 @@ def test_specific(capsys):
assert '── dir/text' not in out
assert '── dir/link' in out
+
def test_specific_case(capsys):
ret, out = run(capsys, '--exclude=dir/TEXT')
@@ -63,6 +67,7 @@ def test_specific_case(capsys):
assert '── dir/text' in out
assert '── dir/link' in out
+
def test_multiple(capsys):
ret, out = run(capsys, '--exclude=dir/text', '--exclude=dir/link')
@@ -70,6 +75,7 @@ def test_multiple(capsys):
assert '── dir/text' not in out
assert '── dir/link' not in out
+
def test_nomatch(capsys):
ret, out = run(capsys, '--exclude=nomatch')
@@ -77,6 +83,7 @@ def test_nomatch(capsys):
assert '── dir/text' in out
assert '── dir/link' in out
+
def test_wildcard(capsys):
ret, out = run(capsys, '--exclude=*link')
diff --git a/tests/test_main.py b/tests/test_main.py
index 38f5d3e..9ec9068 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -37,6 +37,7 @@ def run(capsys, *args):
return exc.value.code, out, err
+
def test_non_existing_files(capsys):
ret, _, err = run(capsys, '/nonexisting1', '/nonexisting2')
@@ -44,6 +45,7 @@ def test_non_existing_files(capsys):
assert '/nonexisting1: No such file or directory' in err
assert '/nonexisting2: No such file or directory' in err
+
def test_non_existing_left_with_new_file(capsys):
ret, out, _ = run(capsys, '--new-file', '/nonexisting1', __file__)
@@ -51,6 +53,7 @@ def test_non_existing_left_with_new_file(capsys):
assert '--- /nonexisting1' in out
assert ('+++ %s' % __file__) in out
+
def test_non_existing_right_with_new_file(capsys):
ret, out, _ = run(capsys, '--new-file', __file__, '/nonexisting2')
@@ -58,6 +61,7 @@ def test_non_existing_right_with_new_file(capsys):
assert ('--- %s' % __file__) in out
assert '+++ /nonexisting2' in out
+
def test_non_existing_files_with_new_file(capsys):
ret, out, _ = run(capsys, '--new-file', '/nonexisting1', '/nonexisting2')
@@ -66,6 +70,7 @@ def test_non_existing_files_with_new_file(capsys):
assert '+++ /nonexisting2' in out
assert 'Trying to compare two non-existing files.' in out
+
def test_remove_temp_files_on_sigterm(capsys, tmpdir, monkeypatch):
pid = os.fork()
@@ -82,6 +87,7 @@ def test_remove_temp_files_on_sigterm(capsys, tmpdir, monkeypatch):
assert (ret >> 8) == 2 # having received SIGTERM is trouble
assert os.listdir(str(tmpdir)) == []
+
def test_ctrl_c_handling(tmpdir, monkeypatch, capsys):
monkeypatch.setattr('tempfile.tempdir', str(tmpdir))
@@ -98,6 +104,7 @@ def test_ctrl_c_handling(tmpdir, monkeypatch, capsys):
assert ret == 2
assert os.listdir(str(tmpdir)) == []
+
def test_no_differences(capsys):
ret, out, err = run(capsys, TEST_TAR1_PATH, TEST_TAR1_PATH)
@@ -105,6 +112,7 @@ def test_no_differences(capsys):
assert err == ''
assert out == ''
+
def test_no_differences_directories(capsys, tmpdir):
def create_dir(x):
path = str(tmpdir.mkdir(x))
@@ -119,6 +127,7 @@ def test_no_differences_directories(capsys, tmpdir):
assert err == '' or "getfacl" in err
assert out == ''
+
def test_list_tools(capsys):
ret, out, err = run(capsys, '--list-tools')
@@ -127,6 +136,7 @@ def test_list_tools(capsys):
assert 'External-Tools-Required: ' in out
assert 'xxd,' in out
+
def test_profiling(capsys):
ret, out, err = run(capsys, TEST_TAR1_PATH, TEST_TAR1_PATH, '--profile=-')
diff --git a/tests/test_presenters.py b/tests/test_presenters.py
index 5344b8d..82fcaf2 100644
--- a/tests/test_presenters.py
+++ b/tests/test_presenters.py
@@ -39,9 +39,11 @@ def run(capsys, *args, pair=('test1.tar', 'test2.tar')):
assert exc.value.code == 1
return out
+
def run_images(capsys, *args):
return run(capsys, *args, pair=('test1.png', 'test2.png'))
+
def extract_body(val):
"""
Extract the salient parts of HTML fixtures that won't change between
@@ -55,21 +57,25 @@ def extract_body(val):
return result
+
def test_text_option_is_default(capsys):
out = run(capsys)
assert out == get_data('output.txt')
+
def test_text_proper_indentation(capsys):
out = run(capsys, pair=('archive1.tar', 'archive2.tar'))
assert out == get_data('archive12.diff.txt')
+
def test_text_option_color(capsys):
out = run(capsys, '--text-color=always')
assert out == get_data('output.colored.txt')
+
def test_text_option_with_file(tmpdir, capsys):
report_path = str(tmpdir.join('report.txt'))
@@ -80,31 +86,37 @@ def test_text_option_with_file(tmpdir, capsys):
with open(report_path, 'r', encoding='utf-8') as f:
assert f.read() == get_data('output.txt')
+
def test_text_option_with_stdiout(capsys):
out = run(capsys, '--text', '-')
assert out == get_data('output.txt')
+
def test_markdown(capsys):
out = run(capsys, '--markdown', '-')
assert out == get_data('output.md')
+
def test_restructuredtext(capsys):
out = run(capsys, '--restructured-text', '-')
assert out == get_data('output.rst')
+
def test_json(capsys):
out = run(capsys, '--json', '-')
assert out == get_data('output.json')
+
def test_no_report_option(capsys):
out = run(capsys)
assert out == get_data('output.txt')
+
def test_html_option_with_file(tmpdir, capsys):
report_path = str(tmpdir.join('report.html'))
@@ -115,6 +127,7 @@ def test_html_option_with_file(tmpdir, capsys):
body = extract_body(f.read())
assert body.count('div class="difference"') == 4
+
@skip_unless_tools_exist('compare', 'convert', 'sng')
def test_html_visuals(tmpdir, capsys):
report_path = str(tmpdir.join('report.html'))
@@ -126,6 +139,7 @@ def test_html_visuals(tmpdir, capsys):
assert '<img src="data:image/png;base64' in body
assert '<img src="data:image/gif;base64' in body
+
def test_htmldir_option(tmpdir, capsys):
html_dir = os.path.join(str(tmpdir), 'target')
@@ -137,11 +151,13 @@ def test_htmldir_option(tmpdir, capsys):
body = extract_body(f.read())
assert body.count('div class="difference"') == 4
+
def test_html_option_with_stdout(capsys):
body = extract_body(run(capsys, '--html', '-'))
assert body.count('div class="difference"') == 4
+
def test_limited_print():
def fake(x): return None
with pytest.raises(PrintLimitReached):
@@ -155,6 +171,7 @@ def test_limited_print():
p("123")
p("456", force=True)
+
def test_partial_string():
a, b = object(), object()
tmpl = PartialString("{0} {1}", a, b)
@@ -171,6 +188,7 @@ def test_partial_string():
with pytest.raises(IndexError):
PartialString("{0} {1} {2}", a, b)
+
def test_partial_string_cont():
t, cont = PartialString.cont()
t = cont(t, "x: {0}\ny: {1}\n{-1}", object(), object())
@@ -181,11 +199,13 @@ def test_partial_string_cont():
== 'x: line1\ny: line2\nz: line3\n')
assert t.size(hole_size=5) == 27
+
def test_partial_string_numl():
tmpl = PartialString.numl("{0} {1} {2}", 2, object())
assert tmpl.holes[:2] == (0, 1)
assert tmpl.pformatl("(1)", "(2)", "(o)") == PartialString('(1) (2) (o)')
+
def test_partial_string_escape():
tmpl = PartialString.numl("find {0} -name {1} " +
PartialString.escape("-exec ls -la {} \;"), 2)
diff --git a/tests/test_progress.py b/tests/test_progress.py
index bb94117..6c2b516 100644
--- a/tests/test_progress.py
+++ b/tests/test_progress.py
@@ -39,6 +39,7 @@ def run(capsys, *args):
return exc.value.code, out, err
+
@skip_unless_module_exists('progressbar')
def test_progress(capsys):
ret, _, err = run(capsys, TEST_TAR1_PATH, TEST_TAR2_PATH, '--progress')
@@ -46,6 +47,7 @@ def test_progress(capsys):
assert ret == 1
assert "ETA" in err
+
def test_status_fd(capsys):
ProgressManager().register(StatusFD(sys.stderr))
diff --git a/tests/test_readers.py b/tests/test_readers.py
index bb7e9ce..967b043 100644
--- a/tests/test_readers.py
+++ b/tests/test_readers.py
@@ -37,12 +37,14 @@ def run_read_write(capsys, diff, *args):
assert out == get_data(diff) # presented-output is same as parsed-input
return out
+
def run_diff_read(diffpath):
with cwd_data():
diff = compare_root_paths('test1.tar', 'test2.tar')
read = load_diff_from_path(diffpath)
assert diff.equals(read)
+
def test_json(capsys):
run_read_write(capsys, 'output.json', '--json', '-')
run_diff_read('output.json')
diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py
index d1b43d8..e2dcc0c 100644
--- a/tests/utils/__init__.py
+++ b/tests/utils/__init__.py
@@ -21,5 +21,6 @@ import re
re_diff_line_numbers = re.compile(r"(^|\n)@@ -(\d+),(\d+) \+(\d+),(\d+) @@(?=\n|$)")
+
def diff_ignore_line_numbers(diff):
return re_diff_line_numbers.sub(r"\1@@ -XX,XX +XX,XX @@", diff)
diff --git a/tests/utils/tools.py b/tests/utils/tools.py
index 025d305..2ca2f6b 100644
--- a/tests/utils/tools.py
+++ b/tests/utils/tools.py
@@ -30,12 +30,14 @@ from distutils.version import LooseVersion
def tools_missing(*required):
return not required or any(find_executable(x) is None for x in required)
+
def skip_unless_tools_exist(*required):
return pytest.mark.skipif(
tools_missing(*required),
reason="requires {}".format(" and ".join(required)),
)
+
def skip_unless_tool_is_at_least(tool, actual_ver, min_ver, vcls=LooseVersion):
if tools_missing(tool):
return pytest.mark.skipif(True, reason="requires {}".format(tool))
@@ -46,6 +48,7 @@ def skip_unless_tool_is_at_least(tool, actual_ver, min_ver, vcls=LooseVersion):
reason="requires {} >= {} ({} detected)".format(tool, min_ver, actual_ver)
)
+
def skip_unless_tool_is_at_most(tool, actual_ver, max_ver, vcls=LooseVersion):
if tools_missing(tool):
return pytest.mark.skipif(True, reason="requires {}".format(tool))
@@ -56,6 +59,7 @@ def skip_unless_tool_is_at_most(tool, actual_ver, max_ver, vcls=LooseVersion):
reason="requires {} <= {} ({} detected)".format(tool, max_ver, actual_ver)
)
+
def skip_unless_tool_is_between(tool, actual_ver, min_ver, max_ver, vcls=LooseVersion):
if tools_missing(tool):
return pytest.mark.skipif(True, reason="requires {}".format(tool))
@@ -68,6 +72,7 @@ def skip_unless_tool_is_between(tool, actual_ver, min_ver, max_ver, vcls=LooseVe
max_ver, actual_ver)
)
+
def skip_if_binutils_does_not_support_x86():
if tools_missing('objdump'):
return skip_unless_tools_exist('objdump')
@@ -77,12 +82,14 @@ def skip_if_binutils_does_not_support_x86():
reason="requires a binutils capable of reading x86-64 binaries"
)
+
@functools.lru_cache()
def get_supported_elf_formats():
return set(subprocess.check_output(
('objdump', '--info'),
).decode('utf-8').splitlines())
+
def module_is_not_importable(x):
try:
if importlib.util.find_spec(x) is None:
@@ -97,6 +104,7 @@ def module_is_not_importable(x):
# import ``debian`` so we must handle that failing.
return True
+
def skip_unless_module_exists(name):
return pytest.mark.skipif(
module_is_not_importable(name),
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list