code: def _unittest_image_comparison(
      baseline_images,
      tol,
      remove_text,
  ):
      """
      Decorate function with image comparison for unittest.
      This function creates a decorator that wraps a figure-generating function
      with image comparison code.
      """
  
      def decorator(func):
          old_sig = inspect.signature(func)
  
          # This saves us to lift name, docstring, etc.
          # NOTE: not super sure why we need this additional layer of wrapping
          # seems to have to do with stripping arguments from the test function
          # probably redundant in this adaptation
          @functools.wraps(func)
          def wrapper(*args, **kwargs):
              # Three steps:
              # 1. run the function and store the results
              figs = func(*args, **kwargs)
              if isinstance(figs, plotly.graph_objects.Figure):
                  figs = [figs]
  
              # Store images (used to bootstrap new tests)
              for fig, image_file in zip(figs, baseline_images):
                  _store_result_image(fig, image_file)
  
              assert len(baseline_images) == len(
                  figs
              ), "Test generated {} images but there are {} baseline images".format(
                  len(figs), len(baseline_images)
              )
  
              # 2. load the control images
              baselines = _load_baseline_images(baseline_images)
  
              # 3. compare them one by one
              for i, (baseline, fig) in enumerate(zip(baselines, figs)):
                  if remove_text:
                      # TODO
                      pass
  
                  # FIXME: what does tolerance mean for json?
                  res = compare_image(baseline, fig, tol)
                  assert (
                      res
                  ), f"Image {i} does not match the corresponding baseline"
  
          parameters = list(old_sig.parameters.values())
          new_sig = old_sig.replace(parameters=parameters)
          wrapper.__signature__ = new_sig
  
          return wrapper
  
      return decorator
  
file_path: python-igraph/tests/drawing/plotly/utils.py
imports: from pathlib import Path
  import sys
  import inspect
  import functools
label_desc: Use image node_id 8 for calling a global function with example usage: _unittest_image_comparison(baseline_images, tol, remove_text) and returns: decorator, wrapper