code: def _compare_animation(anim, expected, format_, nframes, tol):
      # generate images from the animation
      base_dir, filename = split(
          join("tests", "baseline_images", expected)
      )
      out_dir = split(join("tests", "output_images", expected))[0]
  
      if not os.path.exists(out_dir):
          os.makedirs(out_dir)
  
      anim.save(
          os.path.join(out_dir, (filename + format_)),
          writer=BunchOFiles(),
      )
  
      for i in range(nframes):
          image_name = "%s%d%s" % (filename, i, format_)
          expected_name = os.path.join(base_dir, image_name)
          actual_name = os.path.join(out_dir, image_name)
  
          err = compare_images(
              expected_name, actual_name, tol, in_decorator=True
          )
  
          if not os.path.exists(expected_name):
              raise ImageComparisonFailure(
                  "image does not exist: %s" % expected_name
              )
  
          if err:
              for key in ["actual", "expected"]:
                  err[key] = os.path.relpath(err[key])
              raise ImageComparisonFailure(
                  "images not close (RMS %(rms).3f):\n\t%(actual)s\n\t%(expected)s "
                  % err
              )
  
file_path: animatplot/tests/tools.py
imports: import os
  from os.path import join, split
  import functools
  import pytest
  import matplotlib.pyplot
  from matplotlib.animation import FileMovieWriter
  from matplotlib.testing.compare import compare_images
  from matplotlib.testing.decorators import remove_ticks_and_titles
  from matplotlib.testing.exceptions import ImageComparisonFailure
label_desc: Use image node_id 1 for calling a global function with example usage: _compare_animation(anim, expected, format_, nframes, tol) without return types