[Reproducible-commits] [diffoscope] 03/13: Use name and not path when doing binary comparisons

Jérémy Bobbio lunar at moszumanska.debian.org
Thu Oct 15 16:04:34 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 67f826c59c84806c308cd6ff051547d225c848a0
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Sat Sep 26 08:07:19 2015 +0000

    Use name and not path when doing binary comparisons
    
    This typically shows when we want to compare non-existing files. We want
    the name that was given on the command-line and not '/dev/null' to appear.
---
 diffoscope/comparators/binary.py | 15 +++++++--------
 tests/comparators/test_binary.py |  2 +-
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/diffoscope/comparators/binary.py b/diffoscope/comparators/binary.py
index 6cf538b..a4eb0ed 100644
--- a/diffoscope/comparators/binary.py
+++ b/diffoscope/comparators/binary.py
@@ -56,16 +56,15 @@ def hexdump_fallback(path):
     return hexdump.getvalue()
 
 
-def compare_binary_files(path1, path2, source=None):
+def compare_binary_files(file1, file2, source=None):
     try:
-        with xxd(path1) as xxd1:
-            with xxd(path2) as xxd2:
-                return Difference.from_raw_readers(xxd1, xxd2, path1, path2, source)
+        with xxd(file1.path) as xxd1, xxd(file2.path) as xxd2:
+            return Difference.from_raw_readers(xxd1, xxd2, file1.name, file2.name, source)
     except RequiredToolNotFound:
-        hexdump1 = hexdump_fallback(path1)
-        hexdump2 = hexdump_fallback(path2)
+        hexdump1 = hexdump_fallback(file1.path)
+        hexdump2 = hexdump_fallback(file2.path)
         comment = 'xxd not available in path. Falling back to Python hexlify.\n'
-        return Difference.from_text(hexdump1, hexdump2, path1, path2, source, comment)
+        return Difference.from_text(hexdump1, hexdump2, file1.name, file2.name, source, comment)
 
 SMALL_FILE_THRESHOLD = 65536 # 64 kiB
 
@@ -143,7 +142,7 @@ class File(object, metaclass=ABCMeta):
 
     @needs_content
     def compare_bytes(self, other, source=None):
-        return compare_binary_files(self.path, other.path, source)
+        return compare_binary_files(self, other, source)
 
     def _compare_using_details(self, other, source):
         details = [d for d in self.compare_details(other, source) if d is not None]
diff --git a/tests/comparators/test_binary.py b/tests/comparators/test_binary.py
index 437a469..680afe9 100644
--- a/tests/comparators/test_binary.py
+++ b/tests/comparators/test_binary.py
@@ -72,7 +72,7 @@ def test_compare_with_xxd(binary1, binary2):
 
 def test_compare_non_existing_with_xxd(binary1):
     difference = binary1.compare_bytes(NonExistingFile('/nonexisting', binary1))
-    assert difference.source2 == '/dev/null'
+    assert difference.source2 == '/nonexisting'
 
 @pytest.fixture
 def xxd_not_found(monkeypatch):

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