[Git][reproducible-builds/diffoscope][master] 3 commits: uImage: adapt test output to file-5.41

Chris Lamb (@lamby) gitlab at salsa.debian.org
Wed Oct 27 09:34:22 UTC 2021



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
74a59a8f by Sergei Trofimovich at 2021-10-27T07:13:17+01:00
uImage: adapt test output to file-5.41

File-5.40->5.41 upgrade brought uImage printing change
which removed 0x prefixes in a few places:
  https://github.com/file/file/commit/905ca555b0e2bdcf9d2985bcc7c1c22e2229b088

This caused test faiure:
  E       AssertionError: assert '@@ -1 +1 @@\... 0XC63C4A06\n' == '@@ -1 +1 @@\... 0xC63C4A06\n'
  E         Skipping 127 identical leading characters in diff, use -v to show
  E         - Address: 0x00000000, Entry Point: 0x00000000, Header CRC: 0xF87AD200, Data CRC: 0x347161A5
  E         ?          --                       --                       ^                     ^
  E         + Address: 00000000, Entry Point: 00000000, Header CRC: 0XF87AD200, Data CRC: 0X347161A5
  E         ?                                                        ^                     ^

The change adds new variant of expected output.

- - - - -
daf549e4 by Chris Lamb at 2021-10-27T10:26:44+01:00
Split out a custom call to assert_diff for a .startswith equivalent.

- - - - -
970d21a2 by Chris Lamb at 2021-10-27T10:33:41+01:00
Use "file_version_is_lt" instead of literally accepting both versions of uimage expected diff.

- - - - -


5 changed files:

- tests/comparators/test_python.py
- tests/comparators/test_uimage.py
- tests/data/uimage_expected_diff
- + tests/data/uimage_expected_diff_pre_5_41
- tests/utils/data.py


Changes:

=====================================
tests/comparators/test_python.py
=====================================
@@ -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),
     )


=====================================
tests/comparators/test_uimage.py
=====================================
@@ -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")


=====================================
tests/data/uimage_expected_diff
=====================================
@@ -1,3 +1,3 @@
 @@ -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


=====================================
tests/data/uimage_expected_diff_pre_5_41
=====================================
@@ -0,0 +1,3 @@
+@@ -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


=====================================
tests/utils/data.py
=====================================
@@ -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



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/8cbe1ab6c3e30259bdd2bd9f0768d6e8c1573209...970d21a2decdb78a2a765115de6eae4cc9a9f141

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/8cbe1ab6c3e30259bdd2bd9f0768d6e8c1573209...970d21a2decdb78a2a765115de6eae4cc9a9f141
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20211027/1f85c116/attachment.htm>


More information about the rb-commits mailing list