[diffoscope] 02/02: comparators/utils/file: fix the rest of the tests

Ximin Luo infinity0 at debian.org
Mon Oct 9 20:10:51 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 0de6c1a212393ec093091d3582625b77f4155bec
Author: Ximin Luo <infinity0 at debian.org>
Date:   Mon Oct 9 20:08:10 2017 +0200

    comparators/utils/file: fix the rest of the tests
    
    We edit the APK test instead of 'auto_diff_metadata = False' because the
    filetype diff contains useful info (the zip version) that isn't output
    elsewhere by the comparator.
---
 diffoscope/comparators/elf.py             |  2 ++
 diffoscope/comparators/squashfs.py        |  2 ++
 diffoscope/comparators/utils/container.py |  2 ++
 diffoscope/comparators/utils/file.py      | 13 +++++++------
 tests/comparators/test_apk.py             |  6 +++---
 tests/comparators/test_gzip.py            |  4 ++--
 tests/comparators/test_ipk.py             |  2 +-
 tests/data/archive12.diff.txt             |  2 +-
 8 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/diffoscope/comparators/elf.py b/diffoscope/comparators/elf.py
index 003d3dc..0a7d29b 100644
--- a/diffoscope/comparators/elf.py
+++ b/diffoscope/comparators/elf.py
@@ -383,6 +383,8 @@ def get_debug_link(path):
 
 
 class ElfContainer(Container):
+    auto_diff_metadata = False
+
     SECTION_FLAG_MAPPING = {
         'X': ElfCodeSection,
         'S': ElfStringSection,
diff --git a/diffoscope/comparators/squashfs.py b/diffoscope/comparators/squashfs.py
index fc38364..c7cf20d 100644
--- a/diffoscope/comparators/squashfs.py
+++ b/diffoscope/comparators/squashfs.py
@@ -217,6 +217,8 @@ class SquashfsDevice(Device, SquashfsMember):
 
 
 class SquashfsContainer(Archive):
+    auto_diff_metadata = False
+
     MEMBER_CLASS = {
         'd': SquashfsDirectory,
         'l': SquashfsSymlink,
diff --git a/diffoscope/comparators/utils/container.py b/diffoscope/comparators/utils/container.py
index c076813..e45faa7 100644
--- a/diffoscope/comparators/utils/container.py
+++ b/diffoscope/comparators/utils/container.py
@@ -40,6 +40,8 @@ logger = logging.getLogger(__name__)
 
 
 class Container(object, metaclass=abc.ABCMeta):
+    auto_diff_metadata = True
+
     def __new__(cls, source):
         if isinstance(source, MissingFile):
             new = super(Container, MissingContainer).__new__(MissingContainer)
diff --git a/diffoscope/comparators/utils/file.py b/diffoscope/comparators/utils/file.py
index f5653fc..54ba9f4 100644
--- a/diffoscope/comparators/utils/file.py
+++ b/diffoscope/comparators/utils/file.py
@@ -296,12 +296,13 @@ class File(object, metaclass=abc.ABCMeta):
         if hasattr(self, 'compare_details'):
             details.extend(self.compare_details(other, source))
         if self.as_container:
-            details.extend([
-                Difference.from_text(self.magic_file_type, other.magic_file_type, self, other,
-                    source='filetype from file(1)'),
-                Difference.from_text(self.__class__.__name__, other.__class__.__name__, self, other,
-                    source='filetype from diffoscope'),
-            ])
+            if self.as_container.auto_diff_metadata:
+                details.extend([
+                    Difference.from_text(self.magic_file_type, other.magic_file_type, self, other,
+                        source='filetype from file(1)'),
+                    Difference.from_text(self.__class__.__name__, other.__class__.__name__, self, other,
+                        source='filetype from diffoscope'),
+                ])
             # Don't recursve forever on archive quines, etc.
             depth = self._as_container.depth
             no_recurse = (depth >= Config().max_container_depth)
diff --git a/tests/comparators/test_apk.py b/tests/comparators/test_apk.py
index 632f272..379cbce 100644
--- a/tests/comparators/test_apk.py
+++ b/tests/comparators/test_apk.py
@@ -92,7 +92,7 @@ def test_skip_undecoded_android_manifest(differences):
 @skip_unless_tools_exist('apktool', 'zipinfo')
 def test_no_android_manifest(differences2):
     undecoded_manifest = 'AndroidManifest.xml (original / undecoded)'
-    assert differences2[1].source1 == undecoded_manifest
-    assert differences2[1].source2 == undecoded_manifest
-    assert differences2[1].comment == 'No decoded AndroidManifest.xml ' \
+    assert differences2[2].source1 == undecoded_manifest
+    assert differences2[2].source2 == undecoded_manifest
+    assert differences2[2].comment == 'No decoded AndroidManifest.xml ' \
                                       'found for one of the APK files.'
diff --git a/tests/comparators/test_gzip.py b/tests/comparators/test_gzip.py
index 57489de..9ce904e 100644
--- a/tests/comparators/test_gzip.py
+++ b/tests/comparators/test_gzip.py
@@ -57,8 +57,8 @@ def differences(gzip1, gzip2):
 
 
 def test_metadata(differences):
-    assert differences[0].source1 == 'metadata'
-    assert differences[0].source2 == 'metadata'
+    assert differences[0].source1.startswith('filetype')
+    assert differences[0].source2.startswith('filetype')
     expected_diff = get_data('gzip_metadata_expected_diff')
     assert differences[0].unified_diff == expected_diff
 
diff --git a/tests/comparators/test_ipk.py b/tests/comparators/test_ipk.py
index b16f4aa..f1b430b 100644
--- a/tests/comparators/test_ipk.py
+++ b/tests/comparators/test_ipk.py
@@ -45,7 +45,7 @@ def differences(ipk1, ipk2):
 
 
 def test_metadata(differences):
-    assert differences[0].source1 == 'metadata'
+    assert differences[0].source1.startswith('filetype')
     expected_diff = get_data('ipk_metadata_expected_diff')
     assert differences[0].unified_diff == expected_diff
 
diff --git a/tests/data/archive12.diff.txt b/tests/data/archive12.diff.txt
index 4679511..3b861ab 100644
--- a/tests/data/archive12.diff.txt
+++ b/tests/data/archive12.diff.txt
@@ -5,7 +5,7 @@
 │ --rw-r--r--   0 lamby     (1000) lamby     (1000)       22 2017-03-19 22:26:58.000000 compressed.gz
 │ +-rw-r--r--   0 lamby     (1000) lamby     (1000)       33 2017-03-19 22:27:42.000000 compressed.gz
 ├── compressed.gz
-│ ├── metadata
+│ ├── filetype from file(1)
 │ │ @@ -1 +1 @@
 │ │ -gzip compressed data, max compression, from Unix
 │ │ +gzip compressed data, was "compressed", last modified: Sun Mar 19 22:27:42 2017, max compression, from Unix

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


More information about the diffoscope mailing list