[Reproducible-commits] [diffoscope] 09/21: Call xxd like other commands

Joachim Breitner nomeata at moszumanska.debian.org
Thu Dec 3 15:05:05 UTC 2015


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

nomeata pushed a commit to branch pu/parallel2
in repository diffoscope.

commit 7851e89896b1c488c94385068f982e6cd786ef5a
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Wed Nov 18 16:50:46 2015 +0000

    Call xxd like other commands
---
 diffoscope/comparators/binary.py | 17 ++---------------
 diffoscope/comparators/utils.py  |  6 ++++++
 tests/comparators/test_binary.py |  5 +++--
 3 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/diffoscope/comparators/binary.py b/diffoscope/comparators/binary.py
index 00ca599..c1920c0 100644
--- a/diffoscope/comparators/binary.py
+++ b/diffoscope/comparators/binary.py
@@ -39,19 +39,6 @@ from diffoscope.difference import Difference
 from diffoscope import tool_required, RequiredToolNotFound, logger
 
 
- at contextmanager
- at tool_required('xxd')
-def xxd(path):
-    p = subprocess.Popen(['xxd', path], shell=False, stdout=subprocess.PIPE,
-                         stderr=subprocess.PIPE, close_fds=True)
-    yield p.stdout
-    p.stdout.close()
-    p.stderr.close()
-    if p.poll() is None:
-        p.terminate()
-    p.wait()
-
-
 def hexdump_fallback(path):
     hexdump = StringIO()
     with open(path, 'rb') as f:
@@ -61,9 +48,9 @@ def hexdump_fallback(path):
 
 
 def compare_binary_files(file1, file2, source=None):
+    import diffoscope.comparators.utils
     try:
-        with xxd(file1.path) as xxd1, xxd(file2.path) as xxd2:
-            return Difference.from_raw_readers(xxd1, xxd2, file1.name, file2.name, source)
+        return Difference.from_command(diffoscope.comparators.utils.Xxd, file1.path, file2.path, source=[file1.name, file2.name])
     except RequiredToolNotFound:
         hexdump1 = hexdump_fallback(file1.path)
         hexdump2 = hexdump_fallback(file2.path)
diff --git a/diffoscope/comparators/utils.py b/diffoscope/comparators/utils.py
index 543168e..063d283 100644
--- a/diffoscope/comparators/utils.py
+++ b/diffoscope/comparators/utils.py
@@ -309,3 +309,9 @@ class NonExistingArchive(Archive):
     @property
     def path(self):
         return '/dev/null'
+
+
+class Xxd(Command):
+    @tool_required('xxd')
+    def cmdline(self):
+        return ['xxd', self.path]
diff --git a/tests/comparators/test_binary.py b/tests/comparators/test_binary.py
index ce93873..ed9fd20 100644
--- a/tests/comparators/test_binary.py
+++ b/tests/comparators/test_binary.py
@@ -75,13 +75,14 @@ def test_compare_with_xxd(binary1, binary2):
 
 def test_compare_non_existing_with_xxd(binary1):
     difference = binary1.compare_bytes(NonExistingFile('/nonexisting', binary1))
+    output_text(difference, print_func=print)
     assert difference.source2 == '/nonexisting'
 
 @pytest.fixture
 def xxd_not_found(monkeypatch):
-    def mock_xxd(path):
+    def mock_cmdline(self):
         raise RequiredToolNotFound('xxd')
-    monkeypatch.setattr(diffoscope.comparators.binary, 'xxd', mock_xxd)
+    monkeypatch.setattr(diffoscope.comparators.utils.Xxd, 'cmdline', mock_cmdline)
 
 def test_no_differences_without_xxd(xxd_not_found, binary1):
     difference = binary1.compare_bytes(binary1)

-- 
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