code: def test_format(test_images, tmp_path):
      """Test the working of the Format class"""
  
      filename1 = test_images / "chelsea.png"
      filename2 = tmp_path / "chelsea.out"
  
      # Test basic format creation
      F = Format("testname", "test description", "foo bar spam")
      assert F.name == "TESTNAME"
      assert F.description == "test description"
      assert F.name in repr(F)
      assert F.name in F.doc
      assert str(F) == F.doc
      assert set(F.extensions) == {".foo", ".bar", ".spam"}
  
      # Test setting extensions
      F1 = Format("test", "", "foo bar spam")
      F2 = Format("test", "", "foo, bar,spam")
      F3 = Format("test", "", ["foo", "bar", "spam"])
      F4 = Format("test", "", ".foo .bar .spam")
      for F in (F1, F2, F3, F4):
          assert set(F.extensions) == {".foo", ".bar", ".spam"}
      # Fail
      raises(ValueError, Format, "test", "", 3)  # not valid ext
      raises(ValueError, Format, "test", "", "", 3)  # not valid mode
      raises(ValueError, Format, "test", "", "", "x")  # not valid mode
  
      # Test subclassing
      F = MyFormat("test", "", modes="i")
      assert "TEST DOCS" in F.doc
  
      # Get and check reader and write classes
      R = F.get_reader(Request(filename1, "ri"))
      W = F.get_writer(Request(filename2, "wi"))
      assert isinstance(R, MyFormat.Reader)
      assert isinstance(W, MyFormat.Writer)
      assert R.format is F
      assert W.format is F
      assert Path(R.request.filename) == filename1
      assert Path(W.request.filename) == filename2
      # Fail
      raises(RuntimeError, F.get_reader, Request(filename1, "rI"))
      raises(RuntimeError, F.get_writer, Request(filename2, "wI"))
  
      # Use as context manager
      with R:
          pass
      with W:
          pass
      # Objects are now closed, cannot be used
      assert R.closed
      assert W.closed
      #
      raises(RuntimeError, R.__enter__)
      raises(RuntimeError, W.__enter__)
      #
      raises(RuntimeError, R.get_data, 0)
      raises(RuntimeError, W.append_data, np.zeros((10, 10)))
  
      # Test __del__
      R = F.get_reader(Request(filename1, "ri"))
      W = F.get_writer(Request(filename2, "wi"))
      ids = id(R), id(W)
      F._closed[:] = []
      del R
      del W
      gc.collect()  # Invoke __del__
      assert set(ids) == set(F._closed)
  
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 2 for calling a global function with example usage: test_format(test_images, tmp_path) without return types