From 62d86b932f05d6ea39fc1dba94598dd947a2b6c4 Mon Sep 17 00:00:00 2001 From: Hugh Daschbach Date: Thu, 12 Sep 2024 23:06:26 -0700 Subject: [PATCH 1/2] Fix marshaling tests on big endian systems. Fix about 16 marshaling error similar to: =============================================================================== [FAIL] Traceback (most recent call last): File "/usr/lib/python3.11/unittest/case.py", line 57, in testPartExecutor yield File "/usr/lib/python3.11/unittest/case.py", line 623, in run self._callTestMethod(testMethod) File "/usr/lib/python3.11/unittest/case.py", line 579, in _callTestMethod if method() is not None: File "/home/hugh/txdbus/tests/test_marshal.py", line 240, in test_byte self.check('ay', [[1, 2, 3, 4]], pack('iBBBB', 4, 1, 2, 3, 4)) File "/home/hugh/txdbus/tests/test_marshal.py", line 143, in check self.assertEqual( File "/usr/lib/python3.11/unittest/case.py", line 873, in assertEqual assertion_func(first, second, msg=msg) File "/usr/lib/python3.11/unittest/case.py", line 866, in _baseAssertEqual raise self.failureException(msg) builtins.AssertionError: b'\x04\x00\x00\x00\x01\x02\x03\x04' != b'\x00\x00\x00\x04\x01\x02\x03\x04' : Binary encoding differs from expected value tests.test_marshal.TestArrayMarshal.test_byte =============================================================================== --- tests/test_marshal.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_marshal.py b/tests/test_marshal.py index 580faaf..0f482c9 100644 --- a/tests/test_marshal.py +++ b/tests/test_marshal.py @@ -1,3 +1,4 @@ +import sys import unittest from struct import pack @@ -125,7 +126,7 @@ def test_array_of_dict(self): class TestMarshal(unittest.TestCase): - def check(self, sig, var_list, expected_encoding, little_endian=True): + def check(self, sig, var_list, expected_encoding, little_endian = sys.byteorder == 'little'): if not isinstance(var_list, list): var_list = [var_list] nbytes, chunks = m.marshal(sig, var_list, 0, little_endian) From 22f693436d9be6579e98d6429279eb875835d8b4 Mon Sep 17 00:00:00 2001 From: Hugh Daschbach Date: Fri, 13 Sep 2024 01:37:34 -0700 Subject: [PATCH 2/2] Fix unmarshaling tests on big endian systems. Fix about eight unmarshaling error similar to: =============================================================================== [ERROR] Traceback (most recent call last): File "/usr/lib/python3.11/unittest/case.py", line 57, in testPartExecutor yield File "/usr/lib/python3.11/unittest/case.py", line 623, in run self._callTestMethod(testMethod) File "/usr/lib/python3.11/unittest/case.py", line 579, in _callTestMethod if method() is not None: File "/home/hugh/txdbus/tests/test_marshal.py", line 487, in test_bad_length self.assertRaises( File "/usr/lib/python3.11/unittest/case.py", line 766, in assertRaises return context.handle('assertRaises', args, kwargs) File "/usr/lib/python3.11/unittest/case.py", line 237, in handle callable_obj(*args, **kwargs) File "/home/hugh/txdbus/tests/test_marshal.py", line 352, in check nbytes, value = m.unmarshal(sig, encoding, 0) File "/home/hugh/txdbus/txdbus/marshal.py", line 887, in unmarshal nbytes, value = unmarshallers[tcode](ct, data, offset, lendian, oobFDs) File "/home/hugh/txdbus/txdbus/marshal.py", line 789, in unmarshal_array nbytes, value = unmarshallers[tcode]( File "/home/hugh/txdbus/txdbus/marshal.py", line 812, in unmarshal_struct return unmarshal(ct[1:-1], data, offset, lendian, oobFDs) File "/home/hugh/txdbus/txdbus/marshal.py", line 887, in unmarshal nbytes, value = unmarshallers[tcode](ct, data, offset, lendian, oobFDs) File "/home/hugh/txdbus/txdbus/marshal.py", line 706, in unmarshal_int32 return 4, struct.unpack_from(lendian and 'i', data, offset)[0] struct.error: unpack_from requires a buffer of at least 28 bytes for unpacking 4 bytes at offset 24 (actual buffer size is 24) tests.test_marshal.TestArrayUnmarshal.test_bad_length =============================================================================== --- tests/test_marshal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_marshal.py b/tests/test_marshal.py index 0f482c9..43ce940 100644 --- a/tests/test_marshal.py +++ b/tests/test_marshal.py @@ -349,7 +349,7 @@ def check_dict(a, b): class TestUnmarshal(unittest.TestCase): def check(self, sig, expected_value, encoding): - nbytes, value = m.unmarshal(sig, encoding, 0) + nbytes, value = m.unmarshal(sig, encoding, 0, sys.byteorder == 'little') self.assertEqual( nbytes, len(encoding),