[diffoscope] 02/03: Move many tests to use new @skip_unless_module_exists decorator.

Chris Lamb chris at chris-lamb.co.uk
Wed Feb 8 22:34:55 CET 2017


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch master
in repository diffoscope.

commit e04e4f79a72949007a7d0aaa349819bf04fa7d61
Author: Chris Lamb <lamby at debian.org>
Date:   Thu Feb 9 10:15:44 2017 +1300

    Move many tests to use new @skip_unless_module_exists decorator.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 tests/comparators/test_debian.py  | 24 ++++++++++++------------
 tests/comparators/test_elf.py     | 13 +++----------
 tests/comparators/test_fsimage.py | 19 +++++++------------
 tests/comparators/test_rpm.py     | 14 ++++++--------
 tests/comparators/test_utils.py   | 17 ++++++-----------
 5 files changed, 34 insertions(+), 53 deletions(-)

diff --git a/tests/comparators/test_debian.py b/tests/comparators/test_debian.py
index 5836d3a..a516bbf 100644
--- a/tests/comparators/test_debian.py
+++ b/tests/comparators/test_debian.py
@@ -27,16 +27,16 @@ from diffoscope.comparators.missing_file import MissingFile
 from diffoscope.comparators.utils.specialize import specialize
 
 from utils.data import data, get_data
+from utils.tools import skip_unless_module_exists
+
 from utils.nonexisting import assert_non_existing
 
 try:
     from diffoscope.comparators.debian import DotChangesFile, DotDscFile, \
         DotBuildinfoFile
-    miss_debian_module = False
 except ImportError:
     from diffoscope.comparators.debian_fallback import DotChangesFile, DotDscFile, \
         DotBuildinfoFile
-    miss_debian_module = True
 
 TEST_DOT_CHANGES_FILE1_PATH = data('test1.changes')
 TEST_DOT_CHANGES_FILE2_PATH = data('test2.changes')
@@ -86,7 +86,7 @@ def dot_changes4(tmpdir):
 def test_dot_changes_identification(dot_changes1):
     assert isinstance(dot_changes1, DotChangesFile)
 
- at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
+ at skip_unless_module_exists('debian.deb822')
 def test_dot_changes_invalid(tmpdir):
     tmpdir.mkdir('a')
     dot_changes_path = str(tmpdir.join('a/test_1.changes'))
@@ -120,18 +120,18 @@ def dot_changes_differences_different_contents_and_identical_files(dot_changes2,
     difference = dot_changes4.compare(dot_changes2)
     return difference.details
 
- at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
+ at 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
 
- at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
+ at 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
 
- at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
+ at 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]
     assert dot_changes_differences_different_contents_and_identical_files[1]
@@ -165,7 +165,7 @@ def dot_dsc2(tmpdir):
 def test_dot_dsc_identification(dot_dsc1):
     assert isinstance(dot_dsc1, DotDscFile)
 
- at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
+ at skip_unless_module_exists('debian.deb822')
 def test_dot_dsc_invalid(tmpdir, dot_dsc2):
     tmpdir.mkdir('a')
     dot_dsc_path = str(tmpdir.join('a/test_1.dsc'))
@@ -183,11 +183,11 @@ def dot_dsc_differences(dot_dsc1, dot_dsc2):
     difference = dot_dsc1.compare(dot_dsc2)
     return difference.details
 
- at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
+ at 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'
 
- at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
+ at skip_unless_module_exists('debian.deb822')
 def test_dot_dsc_compare_non_existing(monkeypatch, dot_dsc1):
     monkeypatch.setattr(Config(), 'new_file', True)
     difference = dot_dsc1.compare(MissingFile('/nonexisting', dot_dsc1))
@@ -216,7 +216,7 @@ def dot_buildinfo2(tmpdir):
 def test_dot_buildinfo_identification(dot_buildinfo1):
     assert isinstance(dot_buildinfo1, DotBuildinfoFile)
 
- at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
+ at skip_unless_module_exists('debian.deb822')
 def test_dot_buildinfo_invalid(tmpdir):
     tmpdir.mkdir('a')
     dot_buildinfo_path = str(tmpdir.join('a/test_1.buildinfo'))
@@ -234,11 +234,11 @@ def dot_buildinfo_differences(dot_buildinfo1, dot_buildinfo2):
     difference = dot_buildinfo1.compare(dot_buildinfo2)
     return difference.details
 
- at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
+ at 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'
 
- at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
+ at skip_unless_module_exists('debian.deb822')
 def test_dot_buildinfo_compare_non_existing(monkeypatch, dot_buildinfo1):
     assert_non_existing(monkeypatch, dot_buildinfo1)
 
diff --git a/tests/comparators/test_elf.py b/tests/comparators/test_elf.py
index dd62f3a..a75d04e 100644
--- a/tests/comparators/test_elf.py
+++ b/tests/comparators/test_elf.py
@@ -29,14 +29,7 @@ from diffoscope.comparators.utils.specialize import specialize
 
 from utils.data import data, load_fixture, get_data
 from utils.tools import skip_unless_tools_exist, \
-    skip_if_binutils_does_not_support_x86
-
-
-try:
-    import diffoscope.comparators.debian # noqa
-    miss_debian_module = False
-except ImportError:
-    miss_debian_module = True
+    skip_if_binutils_does_not_support_x86, skip_unless_module_exists
 
 obj1 = load_fixture('test1.o')
 obj2 = load_fixture('test2.o')
@@ -127,7 +120,7 @@ def dbgsym_differences(dbgsym_dir1, dbgsym_dir2):
 
 @skip_unless_tools_exist('readelf', 'objdump', 'objcopy')
 @skip_if_binutils_does_not_support_x86()
- at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
+ at skip_unless_module_exists('debian.deb822')
 def test_differences_with_dbgsym(dbgsym_differences):
     assert dbgsym_differences.details[2].source1 == 'data.tar.xz'
     bin_details = dbgsym_differences.details[2].details[0].details[0]
@@ -137,7 +130,7 @@ def test_differences_with_dbgsym(dbgsym_differences):
 
 @skip_unless_tools_exist('readelf', 'objdump', 'objcopy')
 @skip_if_binutils_does_not_support_x86()
- at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
+ at skip_unless_module_exists('debian.deb822')
 def test_original_gnu_debuglink(dbgsym_differences):
     bin_details = dbgsym_differences.details[2].details[0].details[0]
     assert '.gnu_debuglink' in bin_details.details[2].source1
diff --git a/tests/comparators/test_fsimage.py b/tests/comparators/test_fsimage.py
index a4656b8..104300e 100644
--- a/tests/comparators/test_fsimage.py
+++ b/tests/comparators/test_fsimage.py
@@ -24,20 +24,15 @@ from diffoscope.comparators.missing_file import MissingFile
 from diffoscope.comparators.fsimage import FsImageFile
 
 from utils.data import load_fixture, get_data
-from utils.tools import skip_unless_tools_exist
-
-
-try:
-    import guestfs
-    miss_guestfs = False
-except ImportError:
-    miss_guestfs = True
+from utils.tools import skip_unless_tools_exist, skip_unless_module_exists
 
 img1 = load_fixture('test1.ext4')
 img2 = load_fixture('test2.ext4')
 
 def guestfs_working():
-    if miss_guestfs:
+    try:
+        import guestfs
+    except ImportError:
         return False
     g = guestfs.GuestFS (python_return_dict=True)
     g.add_drive_opts("/dev/null", format="raw", readonly=1)
@@ -52,7 +47,7 @@ def test_identification(img1):
 
 @pytest.mark.skipif(not guestfs_working(), reason='guestfs not working on the system')
 @skip_unless_tools_exist('qemu-img')
- at pytest.mark.skipif(miss_guestfs, reason='guestfs is missing')
+ at skip_unless_module_exists('guestfs')
 def test_no_differences(img1):
     difference = img1.compare(img1)
     assert difference is None
@@ -63,7 +58,7 @@ def differences(img1, img2):
 
 @pytest.mark.skipif(not guestfs_working(), reason='guestfs not working on the system')
 @skip_unless_tools_exist('qemu-img')
- at pytest.mark.skipif(miss_guestfs, reason='guestfs is missing')
+ at skip_unless_module_exists('guestfs')
 def test_differences(differences):
     assert differences[0].source1 == 'test1.ext4.tar'
     tarinfo = differences[0].details[0]
@@ -81,7 +76,7 @@ def test_differences(differences):
 
 @pytest.mark.skipif(not guestfs_working(), reason='guestfs not working on the system')
 @skip_unless_tools_exist('qemu-img')
- at pytest.mark.skipif(miss_guestfs, reason='guestfs is missing')
+ at skip_unless_module_exists('guestfs')
 def test_compare_non_existing(monkeypatch, img1):
     monkeypatch.setattr(Config(), 'new_file', True)
     difference = img1.compare(MissingFile('/nonexisting', img1))
diff --git a/tests/comparators/test_rpm.py b/tests/comparators/test_rpm.py
index 0cb538a..d2724ed 100644
--- a/tests/comparators/test_rpm.py
+++ b/tests/comparators/test_rpm.py
@@ -24,16 +24,14 @@ from diffoscope.comparators.binary import FilesystemFile
 from diffoscope.comparators.utils.specialize import specialize
 
 from utils.data import load_fixture, data, get_data
-from utils.tools import skip_unless_tools_exist
+from utils.tools import skip_unless_tools_exist, skip_unless_module_exists
 from utils.nonexisting import assert_non_existing
 
 
 try:
     from diffoscope.comparators.rpm import RpmFile
-    miss_rpm_module = False
 except ImportError:
     from diffoscope.comparators.rpm_fallback import RpmFile
-    miss_rpm_module = True
 
 rpm1 = load_fixture('test1.rpm')
 rpm2 = load_fixture('test2.rpm')
@@ -41,7 +39,7 @@ rpm2 = load_fixture('test2.rpm')
 def test_identification(rpm1):
     assert isinstance(rpm1, RpmFile)
 
- at pytest.mark.skipif(miss_rpm_module, reason='rpm module is not installed')
+ at skip_unless_module_exists('rpm')
 def test_no_differences(rpm1):
     difference = rpm1.compare(rpm1)
     assert difference is None
@@ -50,14 +48,14 @@ def test_no_differences(rpm1):
 def differences(rpm1, rpm2):
     return rpm1.compare(rpm2).details
 
- at pytest.mark.skipif(miss_rpm_module, reason='rpm module is not installed')
+ at skip_unless_module_exists('rpm')
 @skip_unless_tools_exist('rpm2cpio')
 def test_header(differences):
     assert differences[0].source1 == 'header'
     expected_diff = get_data('rpm_header_expected_diff')
     assert differences[0].unified_diff == expected_diff
 
- at pytest.mark.skipif(miss_rpm_module, reason='rpm module is not installed')
+ at skip_unless_module_exists('rpm')
 @skip_unless_tools_exist('rpm2cpio')
 def test_listing(differences):
     assert differences[1].source1 == 'content'
@@ -65,7 +63,7 @@ def test_listing(differences):
     expected_diff = get_data('rpm_listing_expected_diff')
     assert differences[1].details[0].unified_diff == expected_diff
 
- at pytest.mark.skipif(miss_rpm_module, reason='rpm module is not installed')
+ at skip_unless_module_exists('rpm')
 @skip_unless_tools_exist('rpm2cpio')
 def test_content(differences):
     assert differences[1].source1 == 'content'
@@ -73,7 +71,7 @@ def test_content(differences):
     expected_diff = get_data('text_ascii_expected_diff')
     assert differences[1].details[1].unified_diff == expected_diff
 
- at pytest.mark.skipif(miss_rpm_module, reason='rpm module is not installed')
+ at skip_unless_module_exists('rpm')
 @skip_unless_tools_exist('rpm2cpio')
 def test_compare_non_existing(monkeypatch, rpm1):
     assert_non_existing(monkeypatch, rpm1)
diff --git a/tests/comparators/test_utils.py b/tests/comparators/test_utils.py
index 88033b4..c25ec26 100644
--- a/tests/comparators/test_utils.py
+++ b/tests/comparators/test_utils.py
@@ -25,13 +25,8 @@ from diffoscope.difference import Difference
 from diffoscope.comparators.utils.command import Command
 
 from utils.data import data, load_fixture
-from utils.tools import tools_missing, skip_unless_tools_exist
-
-try:
-    import tlsh # noqa
-    miss_tlsh = False
-except ImportError:
-    miss_tlsh = True
+from utils.tools import tools_missing, skip_unless_tools_exist, \
+    skip_unless_module_exists
 
 
 fuzzy_tar1 = load_fixture('fuzzy1.tar')
@@ -62,7 +57,7 @@ def skip_unless_tool_is_at_least():
         return '4.3-git'
     assert func('cat', version, '4.3').args[0] is False
 
- at pytest.mark.skipif(miss_tlsh, reason='tlsh is missing')
+ at skip_unless_module_exists('tlsh')
 def test_fuzzy_matching(fuzzy_tar1, fuzzy_tar2):
     differences = fuzzy_tar1.compare(fuzzy_tar2).details
     expected_diff = codecs.open(data('text_iso8859_expected_diff'), encoding='utf-8').read()
@@ -71,7 +66,7 @@ def test_fuzzy_matching(fuzzy_tar1, fuzzy_tar2):
     assert 'similar' in differences[1].comment
     assert differences[1].unified_diff == expected_diff
 
- at pytest.mark.skipif(miss_tlsh, reason='tlsh is missing')
+ at skip_unless_module_exists('tlsh')
 def test_fuzzy_matching_only_once(fuzzy_tar1, fuzzy_tar3):
     differences = fuzzy_tar1.compare(fuzzy_tar3).details
     assert len(differences) == 2
@@ -79,14 +74,14 @@ 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')
 
- at pytest.mark.skipif(miss_tlsh, reason='tlsh is missing')
+ at 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)
     difference = fuzzy_tar_in_tar1.compare(fuzzy_tar_in_tar2)
     assert len(difference.details) == 1
     assert difference.details[0].source1 == 'file list'
 
- at pytest.mark.skipif(miss_tlsh, reason='tlsh is missing')
+ at 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)
     monkeypatch.setattr(Config(), 'new_file', True)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list