code: def test_read_data():
      class CHeader(SpatialHeader):
          data_layout = "C"
  
      for klass, order in ((SpatialHeader, "F"), (CHeader, "C")):
          hdr = klass(np.int32, shape=(1, 2, 3), zooms=(3.0, 2.0, 1.0))
          fobj = BytesIO()
          data = np.arange(6).reshape((1, 2, 3))
          hdr.data_to_fileobj(data, fobj)
          assert fobj.getvalue() == data.astype(np.int32).tobytes(
              order=order
          )
          # data_to_fileobj accepts kwarg 'rescale', but no effect in this case
          fobj.seek(0)
          hdr.data_to_fileobj(data, fobj, rescale=True)
          assert fobj.getvalue() == data.astype(np.int32).tobytes(
              order=order
          )
          # data_to_fileobj can be a list
          fobj.seek(0)
          hdr.data_to_fileobj(data.tolist(), fobj, rescale=True)
          assert fobj.getvalue() == data.astype(np.int32).tobytes(
              order=order
          )
          # Read data back again
          fobj.seek(0)
          data2 = hdr.data_from_fileobj(fobj)
          assert (data == data2).all()
  
imports: from io import BytesIO
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal
  from ..None import load
  from ..imageclasses import spatial_axes_first
  from ..spatialimages import HeaderDataError, SpatialHeader, SpatialImage
  from ..testing import bytesio_round_trip, expires, memmap_after_ufunc
  from ..tmpdirs import InTemporaryDirectory
label_desc: Use image node_id 8 for calling a global function with example usage: test_read_data() without return types