[diffoscope] 04/04: Fix CI tests using python 3.6

Ximin Luo infinity0 at debian.org
Fri Jun 30 19:12:28 CEST 2017


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

infinity0 pushed a commit to branch master
in repository diffoscope.

commit 26a4360e1ba94f540308d4a7104cd8d3727edff0
Author: Ximin Luo <infinity0 at debian.org>
Date:   Fri Jun 30 19:11:21 2017 +0200

    Fix CI tests using python 3.6
    
    3.6 is not yet default so some existing modules e.g. rpm are missing their
    compiled components.
---
 diffoscope/comparators/rpm_fallback.py |  2 +-
 tests/utils/tools.py                   | 24 +++++++++++++++---------
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/diffoscope/comparators/rpm_fallback.py b/diffoscope/comparators/rpm_fallback.py
index dfc7187..481d54d 100644
--- a/diffoscope/comparators/rpm_fallback.py
+++ b/diffoscope/comparators/rpm_fallback.py
@@ -30,5 +30,5 @@ class RpmFile(AbstractRpmFile):
         difference = self.compare_bytes(other)
         if not difference:
             return None
-        difference.add_comment('Unable to find Python rpm module. Falling back to binary comparison.')
+        difference.add_comment('Unable to import Python rpm module. Falling back to binary comparison.')
         return difference
diff --git a/tests/utils/tools.py b/tests/utils/tools.py
index 8e84365..4b96405 100644
--- a/tests/utils/tools.py
+++ b/tests/utils/tools.py
@@ -20,7 +20,7 @@
 
 import pytest
 import functools
-import importlib
+import importlib.util
 import subprocess
 
 from distutils.spawn import find_executable
@@ -61,16 +61,22 @@ def get_supported_elf_formats():
         ('objdump', '--info'),
     ).decode('utf-8').splitlines())
 
-def skip_unless_module_exists(name):
-    def module_does_not_exist(x):
-        try:
-            return importlib.util.find_spec(x) is None
-        except ImportError:
-            # Probing for submodules (eg. ``debian.deb822``) will attempt to
-            # import ``debian`` so we must handle that failing.
+def module_is_not_importable(x):
+    try:
+        if importlib.util.find_spec(x) is None:
             return True
+        # an existent module is not necessarily importable, e.g. if its child
+        # modules are not available, e.g. if we are running diffoscope using a
+        # non-default version of python, and the module uses extension modules
+        # that haven't been compiled for this version
+        __import__(x)
+    except ImportError:
+        # Probing for submodules (eg. ``debian.deb822``) will attempt to
+        # import ``debian`` so we must handle that failing.
+        return True
 
+def skip_unless_module_exists(name):
     return pytest.mark.skipif(
-        module_does_not_exist(name),
+        module_is_not_importable(name),
         reason="requires {} module".format(name),
     )

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


More information about the diffoscope mailing list