code: def test_shapefile_transform_cache():
      # a5caae040ee11e72a62a53100fe5edc355304419 added shapefile mpl
      # geometry caching based on geometry object id. This test ensures
      # it is working.
      coastline_path = cartopy.io.shapereader.natural_earth(
          resolution="110m", category="physical", name="coastline"
      )
      geoms = cartopy.io.shapereader.Reader(coastline_path).geometries()
      # Use the first 10 of them.
      geoms = tuple(geoms)[:10]
      n_geom = len(geoms)
  
      fig = plt.figure()
      ax = plt.axes(projection=ccrs.Robinson())
  
      # Empty the cache.
      FeatureArtist._geom_key_to_geometry_cache.clear()
      FeatureArtist._geom_key_to_path_cache.clear()
      assert len(FeatureArtist._geom_key_to_geometry_cache) == 0
      assert len(FeatureArtist._geom_key_to_path_cache) == 0
  
      with mock.patch.object(
          ax.projection,
          "project_geometry",
          wraps=ax.projection.project_geometry,
      ) as counter:
          ax.add_geometries(geoms, ccrs.PlateCarree())
          ax.add_geometries(geoms, ccrs.PlateCarree())
          ax.add_geometries(geoms[:], ccrs.PlateCarree())
          fig.canvas.draw()
  
      # Without caching the count would have been
      # n_calls * n_geom, but should now be just n_geom.
      assert counter.call_count == n_geom, (
          f"The given geometry was transformed too many times (expected: "
          f"{n_geom}; got {counter.call_count}) - the caching is not working."
      )
  
      # Check the cache has an entry for each geometry.
      assert len(FeatureArtist._geom_key_to_geometry_cache) == n_geom
      assert len(FeatureArtist._geom_key_to_path_cache) == n_geom
  
      # Check that the cache is empty again once we've dropped all references
      # to the source paths.
      fig.clf()
      del geoms, counter
      gc.collect()
      assert len(FeatureArtist._geom_key_to_geometry_cache) == 0
      assert len(FeatureArtist._geom_key_to_path_cache) == 0
  
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 3 for calling a global function with example usage: test_shapefile_transform_cache() without return types