code: def test_reader_and_writer(test_images, tmp_path):
      # Prepare
      filename1 = test_images / "chelsea.png"
      filename2 = tmp_path / "chelsea.out"
      F = MyFormat("test", "", modes="i")
  
      # Test using reader
      n = 3
      R = F.get_reader(Request(filename1, "ri"))
      assert len(R) == n
      ims = [im for im in R]
      assert len(ims) == n
      for i in range(3):
          assert ims[i][0, 0] == i
          assert ims[i].meta["index"] == i
      for i in range(3):
          assert R.get_meta_data(i)["index"] == i
      # Read next
      assert R.get_data(0)[0, 0] == 0
      assert R.get_next_data()[0, 0] == 1
      assert R.get_next_data()[0, 0] == 2
      # Fail
      R._failmode = 1
      raises(ValueError, R.get_data, 0)
      raises(ValueError, R.get_meta_data, 0)
      R._failmode = 2
      with raises(IndexError):
          [im for im in R]
  
      # Test streaming reader
      R = F.get_reader(Request(filename1, "ri"))
      R._stream_mode = True
      assert R.get_length() == np.inf
      ims = [im for im in R]
      assert len(ims) == 5
  
      # Test using writer
      im1 = np.zeros((10, 10))
      im2 = imageio.core.Image(im1, {"foo": 1})
      W = F.get_writer(Request(filename2, "wi"))
      W.append_data(im1)
      W.append_data(im2)
      W.append_data(im1, {"bar": 1})
      W.append_data(im2, {"bar": 1})
      # Test that no data is copies (but may be different views)
      assert len(W._written_data) == 4
      for im in W._written_data:
          assert (im == im1).all()
      im1[2, 2] == 99
      for im in W._written_data:
          assert (im == im1).all()
      # Test meta
      assert W._written_meta[0] == {}
      assert W._written_meta[1] == {"foo": 1}
      assert W._written_meta[2] == {"bar": 1}
      assert W._written_meta[3] == {"foo": 1, "bar": 1}
      #
      W.set_meta_data({"spam": 1})
      assert W._meta == {"spam": 1}
      # Fail
      raises(ValueError, W.append_data, "not an array")
      raises(ValueError, W.append_data, im, "not a dict")
      raises(ValueError, W.set_meta_data, "not a dict")
  
imports: import gc
  import shutil
  from pathlib import Path
  import sys
  from typing import List
  import imageio
  import imageio
  import numpy
  import pytest
  from imageio.core import Format, FormatManager, Request
  from pytest import raises
  from conftest import deprecated_test
label_desc: Use image node_id 3 for calling a global function with example usage: test_reader_and_writer(test_images, tmp_path) without return types