code: def test_natural_earth_downloader(tmp_path):
      # downloads a file to a temporary location, and uses that temporary
      # location, then:
      #   * Checks that the file is only downloaded once even when calling
      #     multiple times
      #   * Checks that shapefiles have all the necessary files when downloaded
      #   * Checks that providing a path in a download item gets used rather
      #     than triggering another download
      shp_path_template = str(
          tmp_path / "{category}_{resolution}_{name}.shp"
      )
  
      # picking a small-ish file to speed up download times, the file itself
      # isn't important - it is the download mechanism that is.
      format_dict = {
          "category": "physical",
          "name": "rivers_lake_centerlines",
          "resolution": "110m",
      }
  
      dnld_item = NEShpDownloader(
          target_path_template=shp_path_template
      )
  
      # check that the file gets downloaded the first time path is called
      with mock.patch.object(
          dnld_item,
          "acquire_resource",
          wraps=dnld_item.acquire_resource,
      ) as counter:
          with pytest.warns(
              cartopy.io.DownloadWarning, match="Downloading:"
          ):
              shp_path = dnld_item.path(format_dict)
      counter.assert_called_once()
  
      assert shp_path_template.format(**format_dict) == str(shp_path)
  
      # check that calling path again doesn't try re-downloading
      with mock.patch.object(
          dnld_item,
          "acquire_resource",
          wraps=dnld_item.acquire_resource,
      ) as counter:
          assert dnld_item.path(format_dict) == shp_path
      counter.assert_not_called()
  
      # check that we have the shp and the shx
      exts = [".shp", ".shx"]
      for ext in exts:
          fname = shp_path.with_suffix(ext)
          assert (
              fname.exists()
          ), f"Shapefile's {ext} file doesn't exist in {fname}"
  
      # check that providing a pre downloaded path actually works
      pre_dnld = NEShpDownloader(
          target_path_template="/not/a/real/file.txt",
          pre_downloaded_path_template=str(shp_path),
      )
  
      # check that the pre_dnld downloader doesn't re-download, but instead
      # uses the path of the previously downloaded item
      with mock.patch.object(
          pre_dnld, "acquire_resource", wraps=pre_dnld.acquire_resource
      ) as counter:
          assert pre_dnld.path(format_dict) == shp_path
      counter.assert_not_called()
  
file_path: cartopy/lib/cartopy/tests/io/test_downloaders.py
imports: import contextlib
  from pathlib import Path
  from unittest import mock
  import pytest
  import cartopy
  import cartopy.io
  from cartopy.io.shapereader import NEShpDownloader
label_desc: Use image node_id 6 for calling a global function with example usage: test_natural_earth_downloader(tmp_path) without return types