[Reproducible-commits] [diffoscope] 07/15: XXX
Jérémy Bobbio
lunar at moszumanska.debian.org
Thu Dec 3 11:07:59 UTC 2015
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch pu/parallel2
in repository diffoscope.
commit 80d657fe267392faaab55a891e6576bdaddcedd4
Author: Jérémy Bobbio <lunar at debian.org>
Date: Fri Oct 9 13:10:17 2015 +0000
XXX
---
diffoscope/comparators/__init__.py | 4 ++--
diffoscope/comparators/binary.py | 26 ++++++++++----------------
diffoscope/comparators/deb.py | 2 +-
diffoscope/comparators/directory.py | 6 +++---
diffoscope/comparators/text.py | 4 ++--
diffoscope/difference.py | 36 +++++++++++++++++++-----------------
tests/comparators/test_binary.py | 10 ++++++----
tests/comparators/test_bzip2.py | 2 +-
tests/comparators/test_cpio.py | 2 +-
tests/comparators/test_deb.py | 2 +-
tests/comparators/test_debian.py | 2 +-
tests/comparators/test_directory.py | 4 ++--
tests/comparators/test_elf.py | 4 ++--
tests/comparators/test_fonts.py | 2 +-
tests/comparators/test_gettext.py | 2 +-
tests/comparators/test_gzip.py | 2 +-
tests/comparators/test_ipk.py | 2 +-
tests/comparators/test_iso9660.py | 2 +-
tests/comparators/test_java.py | 2 +-
tests/comparators/test_mono.py | 2 +-
tests/comparators/test_pdf.py | 2 +-
tests/comparators/test_png.py | 2 +-
tests/comparators/test_rpm.py | 2 +-
tests/comparators/test_sqlite.py | 2 +-
tests/comparators/test_squashfs.py | 2 +-
tests/comparators/test_tar.py | 2 +-
tests/comparators/test_text.py | 4 ++--
tests/comparators/test_xz.py | 2 +-
tests/comparators/test_zip.py | 2 +-
29 files changed, 68 insertions(+), 70 deletions(-)
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index c6777e2..ea2aa5f 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -107,8 +107,8 @@ def compare_files(file1, file2, source=None):
def compare_commented_files(file1, file2, comment=None, source=None):
difference = compare_files(file1, file2, source=source)
if comment:
- if difference is None:
- difference = Difference(None, file1.name, file2.name)
+ if not difference:
+ difference = Difference(file1.name, file2.name)
difference.add_comment(comment)
return difference
diff --git a/diffoscope/comparators/binary.py b/diffoscope/comparators/binary.py
index 6af63e4..3f24bf2 100644
--- a/diffoscope/comparators/binary.py
+++ b/diffoscope/comparators/binary.py
@@ -179,9 +179,6 @@ class File(object, metaclass=ABCMeta):
details.extend(self.compare_details(other, source))
if self.as_container:
details.extend(self.as_container.compare(other.as_container))
- details = list(filter(None, details))
- if len(details) == 0:
- return None
return Difference.from_details(self.name, other.name, details, source=source)
@tool_required('cmp')
@@ -204,11 +201,10 @@ class File(object, metaclass=ABCMeta):
try:
difference = self._compare_using_details(other, source)
# no differences detected inside? let's at least do a binary diff
- if difference is None:
+ if not difference:
difference = self.compare_bytes(other, source=source)
- if difference is None:
- return None
- difference.add_comment("No differences found inside, yet data differs")
+ if difference:
+ difference.add_comment("No differences found inside, yet data differs")
except subprocess.CalledProcessError as e:
difference = self.compare_bytes(other, source=source)
if e.output:
@@ -216,16 +212,14 @@ class File(object, metaclass=ABCMeta):
else:
output = '<none>'
cmd = ' '.join(e.cmd)
- if difference is None:
- return None
- difference.add_comment("Command `%s` exited with %d. Output:\n%s"
- % (cmd, e.returncode, output))
+ if difference:
+ difference.add_comment("Command `%s` exited with %d. Output:\n%s"
+ % (cmd, e.returncode, output))
except RequiredToolNotFound as e:
difference = self.compare_bytes(other, source=source)
- if difference is None:
- return None
- difference.add_comment(
- "'%s' not available in path. Falling back to binary comparison." % e.command)
+ if difference:
+ difference.add_comment(
+ "'%s' not available in path. Falling back to binary comparison." % e.command)
package = e.get_package()
if package:
difference.add_comment("Install '%s' to get a better output." % package)
@@ -295,7 +289,7 @@ class NonExistingFile(File):
# perform a meaningful comparison right here. So we are good do the comparison backward
# (where knowledge of the file format lies) and and then reverse it.
if isinstance(other, NonExistingFile):
- return Difference(None, self.name, other.name, comment='Trying to compare two non-existing files.')
+ return Difference(self.name, other.name, comment='Trying to compare two non-existing files.')
logger.debug('Performing backward comparison')
backward_diff = other.compare(self, source)
if not backward_diff:
diff --git a/diffoscope/comparators/deb.py b/diffoscope/comparators/deb.py
index 399b187..632364d 100644
--- a/diffoscope/comparators/deb.py
+++ b/diffoscope/comparators/deb.py
@@ -91,7 +91,7 @@ class Md5sumsFile(File):
same.add('./%s' % path)
self.container.source.container.source.container.source.set_files_with_same_content_in_data(same)
logger.debug('Identifed %d files as identical in data archive', len(same))
- return Difference(None, self.path, other.path, source='md5sums',
+ return Difference(self.path, other.path, source='md5sums',
comment="Files in package differs")
except ValueError as e:
difference = self.compare_bytes(other)
diff --git a/diffoscope/comparators/directory.py b/diffoscope/comparators/directory.py
index cfabff8..4f31637 100644
--- a/diffoscope/comparators/directory.py
+++ b/diffoscope/comparators/directory.py
@@ -88,7 +88,7 @@ def compare_meta(path1, path2):
differences.append(Difference.from_command(Getfacl, path1, path2))
except RequiredToolNotFound:
logger.info("Unable to find 'getfacl'.")
- return [d for d in differences if d is not None]
+ return filter(None, differences)
def compare_directories(path1, path2, source=None):
@@ -140,13 +140,13 @@ class FilesystemDirectory(object):
my_file, other_file, source=name)
meta_differences = compare_meta(my_file.name, other_file.name)
if meta_differences and not inner_difference:
- inner_difference = Difference(None, my_file.path, other_file.path)
+ inner_difference = Difference(my_file.path, other_file.path)
if inner_difference:
inner_difference.add_details(meta_differences)
differences.append(inner_difference)
if not differences:
return None
- difference = Difference(None, self.path, other.path, source)
+ difference = Difference(self.path, other.path, source)
difference.add_details(differences)
return difference
diff --git a/diffoscope/comparators/text.py b/diffoscope/comparators/text.py
index a48a50e..e4e3fd5 100644
--- a/diffoscope/comparators/text.py
+++ b/diffoscope/comparators/text.py
@@ -44,8 +44,8 @@ class TextFile(File):
codecs.open(other.path, 'r', encoding=other_encoding) as other_content:
difference = Difference.from_text_readers(my_content, other_content, self.name, other.name, source)
if my_encoding != other_encoding:
- if difference is None:
- difference = Difference(None, self.path, other.path, source)
+ if not difference:
+ difference = Difference(self.path, other.path, source)
difference.add_details([Difference.from_text(my_encoding, other_encoding, None, None, source='encoding')])
return difference
except (LookupError, UnicodeDecodeError):
diff --git a/diffoscope/difference.py b/diffoscope/difference.py
index a3b993b..8edb6ae 100644
--- a/diffoscope/difference.py
+++ b/diffoscope/difference.py
@@ -270,14 +270,14 @@ def diff(feeder1, feeder2):
class Difference(object):
- def __init__(self, unified_diff, path1, path2, source=None, comment=None):
+ def __init__(self, path1, path2, source=None, comment=None):
self._comments = []
if comment:
if type(comment) is list:
self._comments.extend(comment)
else:
self._comments.append(comment)
- self._unified_diff = unified_diff
+ self._unified_diff = None
# allow to override declared file paths, useful when comparing
# tempfiles
if source:
@@ -294,19 +294,19 @@ class Difference(object):
def __repr__(self):
return '<Difference %s -- %s %s>' % (self._source1, self._source2, self._details)
+ def __bool__(self):
+ return self._unified_diff is not None or len(self._comments) > 0 or len(self._details) > 0
+
@staticmethod
def from_feeder(feeder1, feeder2, path1, path2, source=None, comment=None):
+ difference = Difference(path1, path2, source)
try:
- unified_diff = diff(feeder1, feeder2)
- if not unified_diff:
- return None
- return Difference(unified_diff, path1, path2, source, comment)
+ difference.unified_diff = diff(feeder1, feeder2)
except RequiredToolNotFound:
- difference = Difference(None, path1, path2, source)
difference.add_comment('diff is not available!')
- if comment:
- difference.add_comment(comment)
- return difference
+ if difference.unified_diff and comment:
+ difference.add_comment(comment)
+ return difference
@staticmethod
def from_text(content1, content2, *args, **kwargs):
@@ -362,7 +362,7 @@ class Difference(object):
@staticmethod
def from_details(path1, path2, details, source=None):
- d = Difference(None, path1, path2, source)
+ d = Difference(path1, path2, source)
d.add_details(details)
return d
@@ -390,22 +390,24 @@ class Difference(object):
def unified_diff(self):
return self._unified_diff
+ @unified_diff.setter
+ def unified_diff(self, value):
+ self._unified_diff = value
+
@property
def details(self):
return self._details
def add_details(self, differences):
- if len([d for d in differences if type(d) is not Difference]) > 0:
- raise TypeError("'differences' must contains Difference objects'")
- self._details.extend(differences)
+ self._details.extend(filter(None, differences))
def get_reverse(self):
+ difference = Difference(None, None, source=[self._source2, self._source1], comment=self._comments)
if self._unified_diff is None:
- unified_diff = None
+ difference.unified_diff = None
else:
- unified_diff = reverse_unified_diff(self._unified_diff)
+ difference.unified_diff = reverse_unified_diff(self._unified_diff)
logger.debug('reverse orig %s %s', self._source1, self._source2)
- difference = Difference(unified_diff, None, None, source=[self._source2, self._source1], comment=self._comments)
difference.add_details([d.get_reverse() for d in self._details])
return difference
diff --git a/tests/comparators/test_binary.py b/tests/comparators/test_binary.py
index 1174465..b00d663 100644
--- a/tests/comparators/test_binary.py
+++ b/tests/comparators/test_binary.py
@@ -24,6 +24,7 @@ from diffoscope.comparators import specialize
import diffoscope.comparators.binary
from diffoscope.comparators.binary import File, FilesystemFile, NonExistingFile
from diffoscope.difference import Difference
+from diffoscope.presenters.text import output_text
from diffoscope import RequiredToolNotFound, tool_required
from conftest import tool_missing
@@ -64,7 +65,7 @@ def test_guess_encoding_iso8859():
def test_no_differences_with_xxd(binary1):
difference = binary1.compare_bytes(binary1)
- assert difference is None
+ assert not difference
@pytest.mark.skipif(tool_missing('xxd'), reason='missing xxd')
def test_compare_with_xxd(binary1, binary2):
@@ -84,7 +85,7 @@ def xxd_not_found(monkeypatch):
def test_no_differences_without_xxd(xxd_not_found, binary1):
difference = binary1.compare_bytes(binary1)
- assert difference is None
+ assert not difference
def test_compare_without_xxd(xxd_not_found, binary1, binary2):
difference = binary1.compare(binary2)
@@ -92,11 +93,12 @@ def test_compare_without_xxd(xxd_not_found, binary1, binary2):
assert difference.unified_diff == expected_diff
def test_with_compare_details():
- d = Difference('diff', TEST_FILE1_PATH, TEST_FILE2_PATH, source='source')
+ d = Difference(TEST_FILE1_PATH, TEST_FILE2_PATH, source='source', comment='mock')
class MockFile(FilesystemFile):
def compare_details(self, other, source=None):
return [d]
difference = MockFile(TEST_FILE1_PATH).compare(MockFile(TEST_FILE2_PATH), source='source')
+ output_text(difference, print_func=print)
assert difference.details[0] == d
@pytest.mark.skipif(tool_missing('xxd'), reason='missing xxd')
@@ -114,7 +116,7 @@ def test_with_compare_details_and_no_actual_differences():
def compare_details(self, other, source=None):
return []
difference = MockFile(TEST_FILE1_PATH).compare(MockFile(TEST_FILE1_PATH))
- assert difference is None
+ assert not difference
@pytest.mark.skipif(tool_missing('xxd'), reason='missing xxd')
def test_with_compare_details_and_failed_process():
diff --git a/tests/comparators/test_bzip2.py b/tests/comparators/test_bzip2.py
index 6b0a9c2..946b444 100644
--- a/tests/comparators/test_bzip2.py
+++ b/tests/comparators/test_bzip2.py
@@ -44,7 +44,7 @@ def test_identification(bzip1):
def test_no_differences(bzip1):
difference = bzip1.compare(bzip1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(bzip1, bzip2):
diff --git a/tests/comparators/test_cpio.py b/tests/comparators/test_cpio.py
index 8430955..5421da0 100644
--- a/tests/comparators/test_cpio.py
+++ b/tests/comparators/test_cpio.py
@@ -42,7 +42,7 @@ def test_identification(cpio1):
def test_no_differences(cpio1):
difference = cpio1.compare(cpio1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(cpio1, cpio2):
diff --git a/tests/comparators/test_deb.py b/tests/comparators/test_deb.py
index b0a5790..aa8d779 100644
--- a/tests/comparators/test_deb.py
+++ b/tests/comparators/test_deb.py
@@ -42,7 +42,7 @@ def test_identification(deb1):
def test_no_differences(deb1):
difference = deb1.compare(deb1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(deb1, deb2):
diff --git a/tests/comparators/test_debian.py b/tests/comparators/test_debian.py
index f839930..b9b3526 100644
--- a/tests/comparators/test_debian.py
+++ b/tests/comparators/test_debian.py
@@ -66,7 +66,7 @@ def test_dot_changes_invalid(tmpdir):
def test_dot_changes_no_differences(dot_changes1):
difference = dot_changes1.compare(dot_changes1)
- assert difference is None
+ assert not difference
@pytest.fixture
def dot_changes_differences(dot_changes1, dot_changes2):
diff --git a/tests/comparators/test_directory.py b/tests/comparators/test_directory.py
index d1008f7..3eb9503 100644
--- a/tests/comparators/test_directory.py
+++ b/tests/comparators/test_directory.py
@@ -29,11 +29,11 @@ TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/text_ascii2')
def test_no_differences():
difference = compare_directories(os.path.dirname(__file__), os.path.dirname(__file__))
- assert difference is None
+ assert not difference
def test_no_differences_with_extra_slash():
difference = compare_directories(os.path.dirname(__file__) + '/', os.path.dirname(__file__))
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(tmpdir):
diff --git a/tests/comparators/test_elf.py b/tests/comparators/test_elf.py
index 33d6261..a8ca280 100644
--- a/tests/comparators/test_elf.py
+++ b/tests/comparators/test_elf.py
@@ -41,7 +41,7 @@ def test_obj_identification(obj1):
def test_obj_no_differences(obj1):
difference = obj1.compare(obj1)
- assert difference is None
+ assert not difference
@pytest.fixture
def obj_differences(obj1, obj2):
@@ -75,7 +75,7 @@ def test_lib_identification(lib1):
def test_lib_no_differences(lib1):
difference = lib1.compare(lib1)
- assert difference is None
+ assert not difference
@pytest.fixture
def lib_differences(lib1, lib2):
diff --git a/tests/comparators/test_fonts.py b/tests/comparators/test_fonts.py
index 317eb82..9b9de87 100644
--- a/tests/comparators/test_fonts.py
+++ b/tests/comparators/test_fonts.py
@@ -41,7 +41,7 @@ def test_identification(ttf1):
def test_no_differences(ttf1):
difference = ttf1.compare(ttf1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(ttf1, ttf2):
diff --git a/tests/comparators/test_gettext.py b/tests/comparators/test_gettext.py
index e6fa8b7..32e4654 100644
--- a/tests/comparators/test_gettext.py
+++ b/tests/comparators/test_gettext.py
@@ -42,7 +42,7 @@ def test_identification(mo1):
def test_no_differences(mo1):
difference = mo1.compare(mo1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(mo1, mo2):
diff --git a/tests/comparators/test_gzip.py b/tests/comparators/test_gzip.py
index 038398f..b6aab9b 100644
--- a/tests/comparators/test_gzip.py
+++ b/tests/comparators/test_gzip.py
@@ -41,7 +41,7 @@ def test_identification(gzip1):
def test_no_differences(gzip1):
difference = gzip1.compare(gzip1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(gzip1, gzip2):
diff --git a/tests/comparators/test_ipk.py b/tests/comparators/test_ipk.py
index 1cf6c12..276fe56 100644
--- a/tests/comparators/test_ipk.py
+++ b/tests/comparators/test_ipk.py
@@ -40,7 +40,7 @@ def test_identification(ipk1):
def test_no_differences(ipk1):
difference = ipk1.compare(ipk1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(ipk1, ipk2):
diff --git a/tests/comparators/test_iso9660.py b/tests/comparators/test_iso9660.py
index 5d5fa6d..07dcb12 100644
--- a/tests/comparators/test_iso9660.py
+++ b/tests/comparators/test_iso9660.py
@@ -41,7 +41,7 @@ def test_identification(iso1):
def test_no_differences(iso1):
difference = iso1.compare(iso1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(iso1, iso2):
diff --git a/tests/comparators/test_java.py b/tests/comparators/test_java.py
index 29f5949..3b46585 100644
--- a/tests/comparators/test_java.py
+++ b/tests/comparators/test_java.py
@@ -41,7 +41,7 @@ def test_identification(class1):
def test_no_differences(class1):
difference = class1.compare(class1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(class1, class2):
diff --git a/tests/comparators/test_mono.py b/tests/comparators/test_mono.py
index d7933c9..04680fd 100644
--- a/tests/comparators/test_mono.py
+++ b/tests/comparators/test_mono.py
@@ -46,7 +46,7 @@ def test_identification(exe1):
def test_no_differences(exe1):
difference = exe1.compare(exe1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(exe1, exe2):
diff --git a/tests/comparators/test_pdf.py b/tests/comparators/test_pdf.py
index 1dc3972..67f1af3 100644
--- a/tests/comparators/test_pdf.py
+++ b/tests/comparators/test_pdf.py
@@ -41,7 +41,7 @@ def test_identification(pdf1):
def test_no_differences(pdf1):
difference = pdf1.compare(pdf1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(pdf1, pdf2):
diff --git a/tests/comparators/test_png.py b/tests/comparators/test_png.py
index 6cf4089..d3051b2 100644
--- a/tests/comparators/test_png.py
+++ b/tests/comparators/test_png.py
@@ -41,7 +41,7 @@ def test_identification(png1):
def test_no_differences(png1):
difference = png1.compare(png1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(png1, png2):
diff --git a/tests/comparators/test_rpm.py b/tests/comparators/test_rpm.py
index 5e9a715..501ce85 100644
--- a/tests/comparators/test_rpm.py
+++ b/tests/comparators/test_rpm.py
@@ -47,7 +47,7 @@ def test_identification(rpm1):
@pytest.mark.skipif(miss_rpm_module, reason='rpm module is not installed')
def test_no_differences(rpm1):
difference = rpm1.compare(rpm1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(rpm1, rpm2):
diff --git a/tests/comparators/test_sqlite.py b/tests/comparators/test_sqlite.py
index 4ff3a63..1076cc8 100644
--- a/tests/comparators/test_sqlite.py
+++ b/tests/comparators/test_sqlite.py
@@ -41,7 +41,7 @@ def test_identification(sqlite3db1):
def test_no_differences(sqlite3db1):
difference = sqlite3db1.compare(sqlite3db1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(sqlite3db1, sqlite3db2):
diff --git a/tests/comparators/test_squashfs.py b/tests/comparators/test_squashfs.py
index 25a3fc8..c735c0d 100644
--- a/tests/comparators/test_squashfs.py
+++ b/tests/comparators/test_squashfs.py
@@ -42,7 +42,7 @@ def test_identification(squashfs1):
def test_no_differences(squashfs1):
difference = squashfs1.compare(squashfs1)
- assert difference is None
+ assert not difference
def test_no_warnings(capfd, squashfs1, squashfs2):
_ = squashfs1.compare(squashfs2)
diff --git a/tests/comparators/test_tar.py b/tests/comparators/test_tar.py
index 78a7ff6..e432cce 100644
--- a/tests/comparators/test_tar.py
+++ b/tests/comparators/test_tar.py
@@ -40,7 +40,7 @@ def test_identification(tar1):
def test_no_differences(tar1):
difference = tar1.compare(tar1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(tar1, tar2):
diff --git a/tests/comparators/test_text.py b/tests/comparators/test_text.py
index 147a906..ab47045 100644
--- a/tests/comparators/test_text.py
+++ b/tests/comparators/test_text.py
@@ -34,11 +34,11 @@ def ascii2():
def test_no_differences(ascii1):
difference = ascii1.compare(ascii1)
- assert difference is None
+ assert not difference
def test_difference_in_ascii(ascii1, ascii2):
difference = ascii1.compare(ascii2)
- assert difference is not None
+ assert difference
expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
assert difference.unified_diff == expected_diff
assert not difference.comments
diff --git a/tests/comparators/test_xz.py b/tests/comparators/test_xz.py
index a940ffd..494cc33 100644
--- a/tests/comparators/test_xz.py
+++ b/tests/comparators/test_xz.py
@@ -42,7 +42,7 @@ def test_identification(xz1):
def test_no_differences(xz1):
difference = xz1.compare(xz1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(xz1, xz2):
diff --git a/tests/comparators/test_zip.py b/tests/comparators/test_zip.py
index d921b79..3396037 100644
--- a/tests/comparators/test_zip.py
+++ b/tests/comparators/test_zip.py
@@ -41,7 +41,7 @@ def test_identification(zip1):
def test_no_differences(zip1):
difference = zip1.compare(zip1)
- assert difference is None
+ assert not difference
@pytest.fixture
def differences(zip1, zip2):
--
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