1import pytest 2 3import numpy as np 4from h5py import File 5from .common import TestCase 6from .data_files import get_data_file_path 7 8 9def test_vlen_big_endian(): 10 with File(get_data_file_path("vlen_string_s390x.h5")) as f: 11 assert f.attrs["created_on_s390x"] == 1 12 13 dset = f["DSvariable"] 14 assert dset[0] == b"Parting" 15 assert dset[1] == b"is such" 16 assert dset[2] == b"sweet" 17 assert dset[3] == b"sorrow..." 18 19 dset = f["DSLEfloat"] 20 assert dset[0] == 3.14 21 assert dset[1] == 1.61 22 assert dset[2] == 2.71 23 assert dset[3] == 2.41 24 assert dset[4] == 1.2 25 assert dset.dtype == "<f8" 26 27 # Same float values with big endianess 28 assert f["DSBEfloat"][0] == 3.14 29 assert f["DSBEfloat"].dtype == ">f8" 30 31 assert f["DSLEint"][0] == 1 32 assert f["DSLEint"].dtype == "<u8" 33 34 # Same int values with big endianess 35 assert f["DSBEint"][0] == 1 36 assert f["DSBEint"].dtype == ">i8" 37 38 39class TestEndianess(TestCase): 40 def test_simple_int_be(self): 41 fname = self.mktemp() 42 43 arr = np.ndarray(shape=(1,), dtype=">i4", buffer=bytearray([0, 1, 3, 2])) 44 be_number = 0 * 256 ** 3 + 1 * 256 ** 2 + 3 * 256 ** 1 + 2 * 256 ** 0 45 46 with File(fname, mode="w") as f: 47 f.create_dataset("int", data=arr) 48 49 with File(fname, mode="r") as f: 50 assert f["int"][()][0] == be_number 51