code: def test_conversion_spatialimages(caplog):
      shape = (2, 4, 6)
      affine = np.diag([1, 2, 3, 1])
      klasses = [
          klass
          for klass in all_image_classes
          if klass.rw and issubclass(klass, SpatialImage)
      ]
      for npt in np.float32, np.int16:
          data = np.arange(np.prod(shape), dtype=npt).reshape(shape)
          for r_class in klasses:
              if not r_class.makeable:
                  continue
              img = r_class(data, affine)
              img.set_data_dtype(npt)
              for w_class in klasses:
                  if not w_class.makeable:
                      continue
                  # Suppress header field mismatch reports
                  with caplog.at_level(logging.CRITICAL):
                      img2 = w_class.from_image(img)
                  assert_array_equal(img2.get_fdata(), data)
                  assert_array_equal(img2.affine, affine)
  
imports: import logging
  import pathlib
  import shutil
  from io import BytesIO
  from os.path import dirname
  from os.path import join
  from tempfile import mkdtemp
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from ..None import AnalyzeImage, MGHImage, Minc1Image, Minc2Image, Nifti1Header, Nifti1Image, Nifti1Pair, Nifti2Image, Nifti2Pair, Spm2AnalyzeImage, Spm99AnalyzeImage, all_image_classes
  from ..None import analyze
  from ..None import loadsave
  from ..None import nifti1
  from ..None import spm2analyze
  from ..None import spm99analyze
  from ..optpkg import optional_package
  from ..spatialimages import SpatialImage
  from ..testing import expires
  from ..tmpdirs import InTemporaryDirectory
  from ..volumeutils import native_code, swapped_code
label_desc: Use image node_id 2 for calling a global function with example usage: test_conversion_spatialimages(caplog) without return types