Skip to content

Commit

Permalink
fix tests for big-endian platforms
Browse files Browse the repository at this point in the history
On powerpc and powerpc64 one test fails as:

```
  $ py.test -v
  ...
  test_umsgpack.py::TestUmsgpack::test_pack_ext_handler FAILED
  test_umsgpack.py::TestUmsgpack::test_unpack_ext_handler FAILED
  ...

  self = <test_umsgpack.TestUmsgpack testMethod=test_pack_ext_handler>

    def test_pack_ext_handler(self):
        for (name, obj, data) in ext_handlers_test_vectors:
            obj_repr = repr(obj)
            print("\tTesting %s: object %s" %
                  (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] + "..."))
            packed = umsgpack.packb(obj, ext_handlers=ext_handlers)
  >           self.assertEqual(packed, data)
  E           AssertionError: b'\xd7 ?\x80\x00\x00@\x00\x00\x00' != b'\xd7 \x00\x00\x80?\x00\x00\x00@'

  test_umsgpack.py:484: AssertionError
```

The problem here is in 'struct.pack' output:
it uses native endianness format but test hardcodes little-endian output.

The change forces 'struct.pack' into little-endian format.
That way all tests pass:.

Signed-off-by: Sergei Trofimovich <[email protected]>
Signed-off-by: Vanya A. Sergeev <[email protected]>
  • Loading branch information
Sergei Trofimovich authored and vsergeev committed Nov 20, 2017
1 parent 38c7125 commit 16510e9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test_umsgpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@
CustomType = namedtuple('CustomType', ['x', 'y', 'z'])

ext_handlers = {
complex: lambda obj: umsgpack.Ext(0x20, struct.pack("ff", obj.real, obj.imag)),
complex: lambda obj: umsgpack.Ext(0x20, struct.pack("<ff", obj.real, obj.imag)),
CustomType: lambda obj: umsgpack.Ext(0x30, umsgpack.packb(list(obj))),
0x20: lambda ext: complex(*struct.unpack("ff", ext.data)),
0x20: lambda ext: complex(*struct.unpack("<ff", ext.data)),
0x30: lambda ext: CustomType(*umsgpack.unpackb(ext.data)),
}

Expand Down

0 comments on commit 16510e9

Please sign in to comment.