code: def test_filename_save():
      # This is to test the logic in the load and save routines, relating
      # extensions to filetypes
      # Tuples of class, ext, loadedclass
      inklass_ext_loadklasses = (
          (Nifti1Image, ".nii", Nifti1Image),
          (Nifti2Image, ".nii", Nifti2Image),
          (Nifti1Pair, ".nii", Nifti1Image),
          (Nifti2Pair, ".nii", Nifti2Image),
          (Nifti1Image, ".img", Nifti1Pair),
          (Nifti2Image, ".img", Nifti2Pair),
          (Nifti1Pair, ".img", Nifti1Pair),
          (Nifti2Pair, ".img", Nifti2Pair),
          (Nifti1Image, ".hdr", Nifti1Pair),
          (Nifti2Image, ".hdr", Nifti2Pair),
          (Nifti1Pair, ".hdr", Nifti1Pair),
          (Nifti2Pair, ".hdr", Nifti2Pair),
          (Minc1Image, ".nii", Nifti1Image),
          (Minc1Image, ".img", Nifti1Pair),
          (Spm2AnalyzeImage, ".nii", Nifti1Image),
          (Spm2AnalyzeImage, ".img", Spm2AnalyzeImage),
          (Spm99AnalyzeImage, ".nii", Nifti1Image),
          (Spm99AnalyzeImage, ".img", Spm2AnalyzeImage),
          (AnalyzeImage, ".nii", Nifti1Image),
          (AnalyzeImage, ".img", Spm2AnalyzeImage),
      )
      shape = (2, 4, 6)
      affine = np.diag([1, 2, 3, 1])
      data = np.arange(np.prod(shape), dtype="f4").reshape(shape)
      for inklass, out_ext, loadklass in inklass_ext_loadklasses:
          if not have_scipy:
              # We can't load a SPM analyze type without scipy.  These types have
              # a 'mat' file (the type we can't load)
              if ("mat", ".mat") in loadklass.files_types:
                  continue
          img = inklass(data, affine)
          try:
              pth = mkdtemp()
              fname = pjoin(pth, "image" + out_ext)
              for path in (fname, pathlib.Path(fname)):
                  nils.save(img, path)
                  rt_img = nils.load(path)
                  assert_array_almost_equal(rt_img.get_fdata(), data)
                  assert type(rt_img) is loadklass
                  # delete image to allow file close.  Otherwise windows
                  # raises an error when trying to delete the directory
                  del rt_img
          finally:
              shutil.rmtree(pth)
  
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 7 for calling a global function with example usage: test_filename_save() without return types