code: def _unittest_image_comparison(
      baseline_images,
      tol,
  ):
      """
      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):
              # This decorator is applied to unittest methods
              self = args[0]
  
              # Three steps:
              # 1. run the function
              func(*args, **kwargs)
  
              # 2. locate the control and result images
              baselines = _load_baseline_images(baseline_images)
              figs = _load_result_images(baseline_images)
  
              # 3. compare them one by one
              for _i, (baseline, fig) in enumerate(
                  zip(baselines, figs)
              ):
                  res = compare_image(baseline, fig, tol)
                  self.assertLessEqual(res, tol)
  
          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/cairo/utils.py
imports: from pathlib import Path
  import sys
  import inspect
  import functools
  from igraph.drawing import find_cairo
label_desc: Use image node_id 9 for calling a global function with example usage: _unittest_image_comparison(baseline_images, tol) and returns: decorator, wrapper