Commit 0de6c1a2 authored by Ximin Luo's avatar Ximin Luo

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.
parent ae3f2f05
......@@ -383,6 +383,8 @@ def get_debug_link(path):
class ElfContainer(Container):
auto_diff_metadata = False
SECTION_FLAG_MAPPING = {
'X': ElfCodeSection,
'S': ElfStringSection,
......
......@@ -217,6 +217,8 @@ class SquashfsDevice(Device, SquashfsMember):
class SquashfsContainer(Archive):
auto_diff_metadata = False
MEMBER_CLASS = {
'd': SquashfsDirectory,
'l': SquashfsSymlink,
......
......@@ -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)
......
......@@ -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)
......
......@@ -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.'
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment