From 0861be05da6e91efb13b8bf4d6ee01b53dc94a6b Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Sat, 25 Feb 2017 16:43:01 -0500 Subject: [PATCH] Fix numpy tests for big endian architectures Fixes some numpy tests failures on ppc64 in big-endian mode due to little-endian assumptions. Fixes #694. --- tests/test_numpy_array.py | 7 ++++--- tests/test_numpy_dtypes.py | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/test_numpy_array.py b/tests/test_numpy_array.py index 2ff2fc3c3..365f4e375 100644 --- a/tests/test_numpy_array.py +++ b/tests/test_numpy_array.py @@ -8,7 +8,7 @@ with pytest.suppress(ImportError): @pytest.fixture(scope='function') def arr(): - return np.array([[1, 2, 3], [4, 5, 6]], '' + return ("{{'names':['bool_','uint_','float_','ldbl_']," + " 'formats':['?','" + e + "u4','" + e + "f4','" + e + "f{}']," " 'offsets':[0,4,8,{}], 'itemsize':{}}}") @@ -32,8 +35,9 @@ def simple_dtype_fmt(): def packed_dtype_fmt(): - return "[('bool_', '?'), ('uint_', '') def partial_ld_offset(): @@ -89,6 +93,8 @@ def test_format_descriptors(): def test_dtype(simple_dtype): from pybind11_tests import (print_dtypes, test_dtype_ctors, test_dtype_methods, trailing_padding_dtype, buffer_to_dtype) + from sys import byteorder + e = '<' if byteorder == 'little' else '>' assert print_dtypes() == [ simple_dtype_fmt(), @@ -97,8 +103,8 @@ def test_dtype(simple_dtype): partial_dtype_fmt(), partial_nested_fmt(), "[('a', 'S3'), ('b', 'S3')]", - "[('e1', '' arr = create_enum_array(3) dtype = arr.dtype - assert dtype == np.dtype([('e1', '