class_docstr: Mixin for testing images that may return memory maps
class_docstr_tok: ["Mixin","for","testing","images","that","may","return","memory","maps"]
code: def test_load_mmap(self):
      # Test memory mapping when loading images
      img_klass = self.image_class
      viral_memmap = memmap_after_ufunc()
      with InTemporaryDirectory():
          img, fname, has_scaling = self.get_disk_image()
          file_map = img.file_map.copy()
          for func, param1 in (
              (img_klass.from_filename, fname),
              (img_klass.load, fname),
              (top_load, fname),
              (img_klass.from_file_map, file_map),
          ):
              for mmap, expected_mode in (
                  # mmap value, expected memmap mode
                  # mmap=None -> no mmap value
                  # expected mode=None -> no memmap returned
                  (None, "c"),
                  (True, "c"),
                  ("c", "c"),
                  ("r", "r"),
                  (False, None),
              ):
                  # If the image has scaling, then numpy 1.12 will not return
                  # a memmap, regardless of the input flags.  Previous
                  # numpies returned a memmap object, even though the array
                  # has no mmap memory backing.  See:
                  # https://github.com/numpy/numpy/pull/7406
                  if has_scaling and not viral_memmap:
                      expected_mode = None
                  kwargs = {}
                  if mmap is not None:
                      kwargs["mmap"] = mmap
                  back_img = func(param1, **kwargs)
                  back_data = np.asanyarray(back_img.dataobj)
                  if expected_mode is None:
                      assert not isinstance(
                          back_data, np.memmap
                      ), f"Should not be a {img_klass.__name__}"
                  else:
                      assert isinstance(
                          back_data, np.memmap
                      ), f"Not a {img_klass.__name__}"
                      if self.check_mmap_mode:
                          assert back_data.mode == expected_mode
                  del back_img, back_data
              # Check that mmap is keyword-only
              with pytest.raises(TypeError):
                  func(param1, True)
              # Check invalid values raise error
              with pytest.raises(ValueError):
                  func(param1, mmap="rw")
              with pytest.raises(ValueError):
                  func(param1, mmap="r+")
  
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 2 for calling the MmapImageMixin obj's underlying member method code with example usage: obj.test_load_mmap() without return types