code: def test_contourf_transform_path_counting():
      fig = plt.figure()
      ax = plt.axes(projection=ccrs.Robinson())
      fig.canvas.draw()
  
      # Capture the size of the cache before our test.
      gc.collect()
      initial_cache_size = len(cgeoaxes._PATH_TRANSFORM_CACHE)
  
      with mock.patch(
          "cartopy.mpl.patch.path_to_geos"
      ) as path_to_geos_counter:
          x, y, z = sample_data((30, 60))
          cs = ax.contourf(x, y, z, 5, transform=ccrs.PlateCarree())
          if not _MPL_38:
              n_geom = sum(len(c.get_paths()) for c in cs.collections)
          else:
              n_geom = len(cs.get_paths())
  
          del cs
          fig.canvas.draw()
  
      # Before the performance enhancement, the count would have been 2 * n_geom,
      # but should now be just n_geom.
      assert path_to_geos_counter.call_count == n_geom, (
          f"The given geometry was transformed too many times (expected: "
          f"{n_geom}; got {path_to_geos_counter.call_count}) - the caching is "
          f"not working."
      )
  
      # Check the cache has an entry for each geometry.
      assert (
          len(cgeoaxes._PATH_TRANSFORM_CACHE)
          == initial_cache_size + n_geom
      )
  
      # Check that the cache is empty again once we've dropped all references
      # to the source paths.
      fig.clf()
      del path_to_geos_counter
      gc.collect()
      assert len(cgeoaxes._PATH_TRANSFORM_CACHE) == initial_cache_size
  
file_path: cartopy/lib/cartopy/tests/mpl/test_caching.py
imports: import gc
  from unittest import mock
  import matplotlib.pyplot
  import numpy
  import pytest
  import cartopy.crs
  from cartopy.tests.conftest import _HAS_PYKDTREE_OR_SCIPY
  import cartopy.io.shapereader
  from cartopy.mpl import _MPL_38
  from cartopy.mpl.feature_artist import FeatureArtist
  import cartopy.mpl.geoaxes
  import cartopy.mpl.patch
label_desc: Use image node_id 4 for calling a global function with example usage: test_contourf_transform_path_counting() without return types