Skip to content
Commits on Source (3)
......@@ -354,7 +354,7 @@ class File(object, metaclass=abc.ABCMeta):
),
]
)
# Don't recursve forever on archive quines, etc.
# Don't recurse forever on archive quines, etc.
depth = self._as_container.depth
no_recurse = depth >= Config().max_container_depth
if no_recurse:
......@@ -421,17 +421,19 @@ class File(object, metaclass=abc.ABCMeta):
difference = self.compare_bytes(other, source=source)
if difference is None:
return None
suffix = (
' ({})'.format(self.magic_file_type)
if self.magic_file_type != 'data'
else ''
try:
infix = type(self).DESCRIPTION
except AttributeError:
infix = 'this file format'
suffix = ''
if self.magic_file_type != 'data':
suffix = ' file(1) reports: {}'.format(
self.magic_file_type
)
difference.add_comment(
"Format-specific differences are supported for this "
"file format, but no file-specific differences were "
"detected. Falling back to a binary diff.{}".format(
suffix
)
"Format-specific differences are supported for {} but "
"no file-specific differences were detected; falling "
"back to a binary diff.{}".format(infix, suffix)
)
except subprocess.CalledProcessError as e:
difference = self.compare_bytes(other, source=source)
......
......@@ -127,13 +127,16 @@ def test_with_compare_details():
@skip_unless_tools_exist('xxd')
def test_with_compare_details_and_fallback():
class MockFile(FilesystemFile):
DESCRIPTION = "mock files"
def compare_details(self, other, source=None):
return []
difference = MockFile(TEST_FILE1_PATH).compare(MockFile(TEST_FILE2_PATH))
expected_diff = get_data('binary_expected_diff')
assert (
'but no file-specific differences were detected' in difference.comment
'supported for mock files but no file-specific differences were detected'
in difference.comment
)
assert normalize_zeros(difference.unified_diff) == expected_diff
......