code: def test_filenames():
      types_exts = (("image", ".img"), ("header", ".hdr"))
      for t_fname in ("test.img", "test.hdr", "test", "test."):
          tfns = types_filenames(t_fname, types_exts)
          assert tfns == {"image": "test.img", "header": "test.hdr"}
      # enforcing extensions raises an error for bad extension
      with pytest.raises(TypesFilenamesError):
          types_filenames("test.funny", types_exts)
      # If not enforcing extensions, it does the best job it can,
      # assuming the passed filename is for the first type (in this case
      # 'image')
      tfns = types_filenames(
          "test.funny", types_exts, enforce_extensions=False
      )
      assert tfns == {"header": "test.hdr", "image": "test.funny"}
      # .gz and .bz2 suffixes to extensions, by default, are removed
      # before extension checking etc, and then put back onto every
      # returned filename.
      tfns = types_filenames("test.img.gz", types_exts)
      assert tfns == {"header": "test.hdr.gz", "image": "test.img.gz"}
      tfns = types_filenames("test.img.bz2", types_exts)
      assert tfns == {"header": "test.hdr.bz2", "image": "test.img.bz2"}
      # of course, if we don't know about e.g. gz, and enforce_extensions
      # is on, we get an error
      with pytest.raises(TypesFilenamesError):
          types_filenames("test.img.gz", types_exts, ())
      # if we don't know about .gz extension, and not enforcing, then we
      # get something a bit odd
      tfns = types_filenames(
          "test.img.gz",
          types_exts,
          trailing_suffixes=(),
          enforce_extensions=False,
      )
      assert tfns == {"header": "test.img.hdr", "image": "test.img.gz"}
      # the suffixes we remove and replaces can be any suffixes.
      tfns = types_filenames("test.img.bzr", types_exts, (".bzr",))
      assert tfns == {"header": "test.hdr.bzr", "image": "test.img.bzr"}
      # If we specifically pass the remove / replace suffixes, then we
      # don't remove / replace the .gz and .bz2, unless they are passed
      # specifically.
      tfns = types_filenames(
          "test.img.bzr",
          types_exts,
          trailing_suffixes=(".bzr",),
          enforce_extensions=False,
      )
      assert tfns == {"header": "test.hdr.bzr", "image": "test.img.bzr"}
      # but, just .gz or .bz2 as extension gives an error, if enforcing is on
      with pytest.raises(TypesFilenamesError):
          types_filenames("test.gz", types_exts)
      with pytest.raises(TypesFilenamesError):
          types_filenames("test.bz2", types_exts)
      # if enforcing is off, it tries to work out what the other files
      # should be assuming the passed filename is of the first input type
      tfns = types_filenames(
          "test.gz", types_exts, enforce_extensions=False
      )
      assert tfns == {"image": "test.gz", "header": "test.hdr.gz"}
      # case (in)sensitivity, and effect of uppercase, lowercase
      tfns = types_filenames("test.IMG", types_exts)
      assert tfns == {"image": "test.IMG", "header": "test.HDR"}
      tfns = types_filenames(
          "test.img", (("image", ".IMG"), ("header", ".HDR"))
      )
      assert tfns == {"header": "test.hdr", "image": "test.img"}
      tfns = types_filenames("test.IMG.Gz", types_exts)
      assert tfns == {"image": "test.IMG.Gz", "header": "test.HDR.Gz"}
  
imports: import pathlib
  import pytest
  from ..filename_parser import TypesFilenamesError, _stringify_path, parse_filename, splitext_addext, types_filenames
label_desc: Use image node_id 1 for calling a global function with example usage: test_filenames() without return types