[Reproducible-commits] [diffoscope] 04/06: Call xxd like other commands
Jérémy Bobbio
lunar at moszumanska.debian.org
Sat Dec 5 23:18:58 UTC 2015
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository diffoscope.
commit 4585b1363d17d827aef7ca921c6f32903336934f
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 | 4 ++--
3 files changed, 10 insertions(+), 17 deletions(-)
diff --git a/diffoscope/comparators/binary.py b/diffoscope/comparators/binary.py
index aa74277..583ad67 100644
--- a/diffoscope/comparators/binary.py
+++ b/diffoscope/comparators/binary.py
@@ -38,19 +38,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:
@@ -60,9 +47,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 ee1b18e..59b2961 100644
--- a/diffoscope/comparators/utils.py
+++ b/diffoscope/comparators/utils.py
@@ -312,3 +312,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 1174465..34031b2 100644
--- a/tests/comparators/test_binary.py
+++ b/tests/comparators/test_binary.py
@@ -78,9 +78,9 @@ def test_compare_non_existing_with_xxd(binary1):
@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