From 96dbe5507fab5efb2df8cadd9df5e0ab1d5e583a Mon Sep 17 00:00:00 2001 From: Corentin Cadiou Date: Mon, 17 Jul 2023 11:54:27 +0200 Subject: [PATCH] TST: fix fortran IO test for big-endian architectures --- yt/utilities/tests/test_cython_fortran_utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/yt/utilities/tests/test_cython_fortran_utils.py b/yt/utilities/tests/test_cython_fortran_utils.py index 023bf3652b3..e728a419d97 100644 --- a/yt/utilities/tests/test_cython_fortran_utils.py +++ b/yt/utilities/tests/test_cython_fortran_utils.py @@ -1,3 +1,5 @@ +import struct + import numpy as np import pytest @@ -12,9 +14,11 @@ def test_raise_error_when_file_does_not_exist(): def test_read(tmp_path): dummy_file = tmp_path / "test.bin" # Write a Fortran-formatted file containing one record with 4 doubles - dummy_file.write_bytes( - b" \x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x08@\x00\x00\x00\x00\x00\x00\x10@ \x00\x00\x00" - ) + # The format is a 32bit integer with value 4*sizeof(double)=32 + # followed by 4 doubles and another 32bit integer with value 32 + # Note that there is no memory alignment, hence the "=" below + buff = struct.pack("=i 4d i", 32, 1.0, 2.0, 3.0, 4.0, 32) + dummy_file.write_bytes(buff) with FortranFile(str(dummy_file)) as f: np.testing.assert_equal( f.read_vector("d"),