@@ -1823,7 +1823,8 @@ def test_area_to_cover_all_nan_bounds(self, geos_src_area, create_test_area):
18231823 with pytest .raises (NotImplementedError ):
18241824 area_def .get_area_slices (area_to_cover )
18251825
1826- def test_area_slices_caching (self , create_test_area , tmp_path ):
1826+ @pytest .mark .parametrize ("cache_slices" , [False , True ])
1827+ def test_area_slices_caching (self , create_test_area , tmp_path , cache_slices ):
18271828 """Check that area slices can be cached."""
18281829 src_area = create_test_area (dict (proj = "utm" , zone = 33 ),
18291830 10980 , 10980 ,
@@ -1832,21 +1833,49 @@ def test_area_slices_caching(self, create_test_area, tmp_path):
18321833 100 , 100 ,
18331834 (15.9689 , 58.5284 , 16.4346 , 58.6995 ))
18341835 cache_glob = str (tmp_path / "geometry_slices_v1" / "*.json" )
1835- with pyresample .config .set (cache_dir = tmp_path , cache_geom_slices = False ):
1836+ with pyresample .config .set (cache_dir = tmp_path , cache_geom_slices = cache_slices ):
18361837 assert len (glob (cache_glob )) == 0
18371838 slice_x , slice_y = src_area .get_area_slices (crop_area )
1838- assert len (glob (cache_glob )) == 0
1839- with pyresample .config .set (cache_dir = tmp_path , cache_geom_slices = True ):
1840- assert len (glob (cache_glob )) == 0
1841- slice_x , slice_y = src_area .get_area_slices (crop_area )
1842- assert len (glob (cache_glob )) == 1
1839+ assert len (glob (cache_glob )) == int (cache_slices )
18431840 assert slice_x == slice (5630 , 8339 )
18441841 assert slice_y == slice (9261 , 10980 )
18451842
1843+ if cache_slices :
1844+ from pyresample .future .geometry ._subset import get_area_slices
1845+ with pyresample .config .set (cache_dir = tmp_path ):
1846+ get_area_slices .cache_clear ()
1847+ assert len (glob (cache_glob )) == 0
1848+
1849+ def test_area_slices_caching_no_swaths (self , tmp_path , create_test_area , create_test_swath ):
1850+ """Test that swath inputs produce a warning when tried to use in caching."""
1851+ from pyresample .future .geometry ._subset import get_area_slices
1852+ from pyresample .test .utils import create_test_latitude , create_test_longitude
1853+ area = create_test_area (dict (proj = "utm" , zone = 33 ),
1854+ 10980 , 10980 ,
1855+ (499980.0 , 6490200.0 , 609780.0 , 6600000.0 ))
1856+ lons = create_test_longitude (- 95.0 , - 75.0 , shape = (1000 , 500 ))
1857+ lats = create_test_latitude (25.0 , 35.0 , shape = (1000 , 500 ))
1858+ swath = create_test_swath (lons , lats )
1859+
1860+ with pyresample .config .set (cache_dir = tmp_path , cache_geom_slices = True ), pytest .raises (NotImplementedError ):
1861+ with pytest .warns (UserWarning , match = "unhashable" ):
1862+ get_area_slices (swath , area , None )
1863+
1864+ @pytest .mark .parametrize ("swath_as_src" , [False , True ])
1865+ def test_unsupported_slice_inputs (self , create_test_area , create_test_swath , swath_as_src ):
1866+ """Test that swath inputs produce an error."""
18461867 from pyresample .future .geometry ._subset import get_area_slices
1847- with pyresample .config .set (cache_dir = tmp_path ):
1848- get_area_slices .cache_clear ()
1849- assert len (glob (cache_glob )) == 0
1868+ from pyresample .test .utils import create_test_latitude , create_test_longitude
1869+ area = create_test_area (dict (proj = "utm" , zone = 33 ),
1870+ 10980 , 10980 ,
1871+ (499980.0 , 6490200.0 , 609780.0 , 6600000.0 ))
1872+ lons = create_test_longitude (- 95.0 , - 75.0 , shape = (1000 , 500 ))
1873+ lats = create_test_latitude (25.0 , 35.0 , shape = (1000 , 500 ))
1874+ swath = create_test_swath (lons , lats )
1875+
1876+ with pytest .raises (NotImplementedError ):
1877+ args = (swath , area ) if swath_as_src else (area , swath )
1878+ get_area_slices (* args , None )
18501879
18511880
18521881class TestBoundary :
0 commit comments