class_docstr: Test the bilinear resampler.
class_docstr_tok: ["Test","the","bilinear","resampler","."]
docstr: Test the bilinear resampler.
code: def test_bil_resampling(
      self, xr_resampler, create_filename, move_existing_caches
  ):
      """Test the bilinear resampler."""
      from satpy.resample import BilinearResampler
  
      (
          data,
          source_area,
          swath_data,
          source_swath,
          target_area,
      ) = get_test_data()
  
      # Test that bilinear resampling info calculation is called
      resampler = BilinearResampler(source_swath, target_area)
      resampler.precompute(mask=da.arange(5, chunks=5).astype(bool))
      resampler.resampler.load_resampling_info.assert_not_called()
      resampler.resampler.get_bil_info.assert_called_once()
      resampler.resampler.reset_mock()
  
      # Test that get_sample_from_bil_info is called properly
      fill_value = 8
      resampler.resampler.get_sample_from_bil_info.return_value = (
          xr.DataArray(da.zeros(target_area.shape), dims=("y", "x"))
      )
      new_data = resampler.compute(data, fill_value=fill_value)
      resampler.resampler.get_sample_from_bil_info.assert_called_with(
          data, fill_value=fill_value, output_shape=target_area.shape
      )
      assert "y" in new_data.coords
      assert "x" in new_data.coords
      assert "crs" in new_data.coords
      assert isinstance(new_data.coords["crs"].item(), CRS)
      assert (
          "lambert"
          in new_data.coords["crs"]
          .item()
          .coordinate_operation.method_name.lower()
      )
      assert new_data.coords["y"].attrs["units"] == "meter"
      assert new_data.coords["x"].attrs["units"] == "meter"
      assert target_area.crs == new_data.coords["crs"].item()
  
      # Test that the resampling info is tried to read from the disk
      resampler = BilinearResampler(source_swath, target_area)
      resampler.precompute(cache_dir=".")
      resampler.resampler.load_resampling_info.assert_called()
  
      # Test caching the resampling info
      try:
          the_dir = tempfile.mkdtemp()
          resampler = BilinearResampler(source_area, target_area)
          create_filename.return_value = os.path.join(
              the_dir, "test_cache.zarr"
          )
          xr_resampler.return_value.load_resampling_info.side_effect = (
              IOError
          )
  
          resampler.precompute(cache_dir=the_dir)
          resampler.resampler.save_resampling_info.assert_called()
          # assert data was saved to the on-disk cache
          resampler.resampler.save_resampling_info.assert_called_once()
  
          nbcalls = resampler.resampler.get_bil_info.call_count
          resampler.resampler.load_resampling_info.side_effect = None
  
          resampler.precompute(cache_dir=the_dir)
          # we already have things cached in-memory, no need to save again
          resampler.resampler.save_resampling_info.assert_called_once()
          # we already have things cached in-memory, don't need to load
          assert resampler.resampler.get_bil_info.call_count == nbcalls
  
          # test loading saved resampler
          resampler = BilinearResampler(source_area, target_area)
          resampler.precompute(cache_dir=the_dir)
          assert (
              resampler.resampler.load_resampling_info.call_count == 3
          )
          assert resampler.resampler.get_bil_info.call_count == nbcalls
  
          resampler = BilinearResampler(source_area, target_area)
          resampler.precompute(cache_dir=the_dir)
          resampler.save_bil_info(cache_dir=the_dir)
          zarr_file = os.path.join(the_dir, "test_cache.zarr")
          # Save again faking the cache file already exists
          with mock.patch("os.path.exists") as exists:
              exists.return_value = True
              resampler.save_bil_info(cache_dir=the_dir)
          move_existing_caches.assert_called_once_with(
              the_dir, zarr_file
          )
  
      finally:
          shutil.rmtree(the_dir)
  
imports: import os
  import shutil
  import tempfile
  import unittest
  from unittest import mock
  import dask.array
  import numpy
  import pytest
  import xarray
  from pyproj import CRS
  from satpy.resample import NativeResampler
label_desc: Use image node_id 1 for calling the TestBilinearResampler obj's underlying member method code with example usage: obj.test_bil_resampling(xr_resampler, create_filename, move_existing_caches) without return types