Commits (3)
......@@ -21,7 +21,7 @@ import sys
from diffoscope.comparators.python import PycFile
from ..utils.data import assert_diff, load_fixture
from ..utils.data import assert_diff_startswith, load_fixture
pyc1 = load_fixture("test1.pyc-renamed")
......@@ -47,8 +47,7 @@ def differences(pyc1, pyc2):
def test_diff(differences):
assert_diff(
assert_diff_startswith(
differences[0],
"pyc_expected_diff",
lambda haystack, needle: haystack.startswith(needle),
)
......@@ -23,8 +23,8 @@ from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.uimage import UimageFile
from diffoscope.comparators.utils.specialize import specialize
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.data import load_fixture, get_data, assert_diff
from ..utils.tools import skip_unless_tools_exist, file_version_is_lt
from ..utils.nonexisting import assert_non_existing
cpio1 = load_fixture("test1.cpio")
......@@ -98,8 +98,12 @@ def nested_differences(uboot_cpio1, uboot_cpio2):
def test_file_differences(differences):
expected_diff = get_data("uimage_expected_diff")
assert differences[0].unified_diff == expected_diff
filename = "uimage_expected_diff"
# file-5.41 slightly changed the output format by dropping leading 0x.
if file_version_is_lt("5.41"):
filename = "uimage_expected_diff_pre_5_41"
assert_diff(differences[0], filename)
@skip_unless_tools_exist("cpio")
......
@@ -1 +1 @@
-u-boot legacy uImage, , Linux/PowerPC, RAMDisk Image (Not compressed), 1024 bytes, Fri Nov 27 19:49:00 2020, Load Address: 0x00000000, Entry Point: 0x00000000, Header CRC: 0xF87AD200, Data CRC: 0x347161A5
+u-boot legacy uImage, , Linux/PowerPC, RAMDisk Image (Not compressed), 1024 bytes, Fri Nov 27 19:49:24 2020, Load Address: 0x00000000, Entry Point: 0x00000000, Header CRC: 0xE86686F7, Data CRC: 0xC63C4A06
-u-boot legacy uImage, , Linux/PowerPC, RAMDisk Image (Not compressed), 1024 bytes, Fri Nov 27 19:49:00 2020, Load Address: 00000000, Entry Point: 00000000, Header CRC: 0XF87AD200, Data CRC: 0X347161A5
+u-boot legacy uImage, , Linux/PowerPC, RAMDisk Image (Not compressed), 1024 bytes, Fri Nov 27 19:49:24 2020, Load Address: 00000000, Entry Point: 00000000, Header CRC: 0XE86686F7, Data CRC: 0XC63C4A06
@@ -1 +1 @@
-u-boot legacy uImage, , Linux/PowerPC, RAMDisk Image (Not compressed), 1024 bytes, Fri Nov 27 19:49:00 2020, Load Address: 0x00000000, Entry Point: 0x00000000, Header CRC: 0xF87AD200, Data CRC: 0x347161A5
+u-boot legacy uImage, , Linux/PowerPC, RAMDisk Image (Not compressed), 1024 bytes, Fri Nov 27 19:49:24 2020, Load Address: 0x00000000, Entry Point: 0x00000000, Header CRC: 0xE86686F7, Data CRC: 0xC63C4A06
......@@ -56,12 +56,18 @@ def get_data(filename):
return f.read()
def assert_diff(difference, filename, cmp=lambda x, y: x == y):
def assert_diff(difference, filename):
# Assign seen and expected values to local variables to improve contextual
# information in failed tests.
seen = difference.unified_diff
expected = get_data(filename)
assert cmp(seen, expected)
assert seen == expected
def assert_diff_startswith(difference, filename):
haystack = difference.unified_diff
needle = get_data(filename)
assert needle.startswith(haystack)
# https://code.activestate.com/recipes/576620-changedirectory-context-manager/#c3
......