code: def test_plot_surf_avg_method(rng):
      mesh = generate_surf()
      # Plot with avg_method
      # Test all built-in methods and check
      mapp = rng.standard_normal(size=mesh[0].shape[0])
      mesh_ = load_surf_mesh(mesh)
      _, faces = mesh_[0], mesh_[1]
  
      for method in ["mean", "median", "min", "max"]:
          display = plot_surf(
              mesh,
              surf_map=mapp,
              avg_method=method,
              engine="matplotlib",
          )
          if method == "mean":
              agg_faces = np.mean(mapp[faces], axis=1)
          elif method == "median":
              agg_faces = np.median(mapp[faces], axis=1)
          elif method == "min":
              agg_faces = np.min(mapp[faces], axis=1)
          elif method == "max":
              agg_faces = np.max(mapp[faces], axis=1)
          vmin = np.min(agg_faces)
          vmax = np.max(agg_faces)
          agg_faces -= vmin
          agg_faces /= vmax - vmin
          cmap = plt.get_cmap(plt.rcParamsDefault["image.cmap"])
          assert_array_equal(
              cmap(agg_faces),
              display._axstack.as_list()[0].collections[0]._facecolors,
          )
  
      #  Try custom avg_method
      def custom_avg_function(vertices):
          return vertices[0] * vertices[1] * vertices[2]
  
      plot_surf(
          mesh,
          surf_map=rng.standard_normal(size=mesh[0].shape[0]),
          avg_method=custom_avg_function,
          engine="matplotlib",
      )
      # Save execution time and memory
      plt.close()
  
imports: import re
  import tempfile
  import unittest.mock
  import matplotlib.pyplot
  import numpy
  import pytest
  from matplotlib.figure import Figure
  from numpy.testing import assert_array_equal
  from nilearn._utils.helpers import is_kaleido_installed, is_plotly_installed
  from nilearn.conftest import _rng
  from nilearn.datasets import fetch_surf_fsaverage
  from nilearn.plotting.displays import PlotlySurfaceFigure
  from nilearn.plotting.surf_plotting import VALID_HEMISPHERES, VALID_VIEWS, _compute_facecolors_matplotlib, _get_ticks_matplotlib, _get_view_plot_surf_matplotlib, _get_view_plot_surf_plotly, plot_img_on_surf, plot_surf, plot_surf_contours, plot_surf_roi, plot_surf_stat_map
  from nilearn.surface import load_surf_data, load_surf_mesh
  from nilearn.surface.tests._testing import generate_surf
label_desc: Use image node_id 19 for calling a global function with example usage: test_plot_surf_avg_method(rng) and returns: unknown