Commit e670a3cb authored by Chris Lamb's avatar Chris Lamb 💬

Improve the displayed comment when falling back to a binary diff to include...

Improve the displayed comment when falling back to a binary diff to include the file type. (Closes: #49)
parent a671bfba
......@@ -421,15 +421,19 @@ class File(object, metaclass=abc.ABCMeta):
difference = self.compare_bytes(other, source=source)
if difference is None:
return None
try:
infix = type(self).DESCRIPTION
except AttributeError:
infix = 'this file format'
suffix = ''
if self.magic_file_type != 'data':
suffix = ' ({})'.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
suffix = ' file(1) reports: {}'.format(
self.magic_file_type
)
difference.add_comment(
"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
......
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