From e2972f3e85762fef730ad56f5e78e1e8a7b5714d Mon Sep 17 00:00:00 2001 From: Brendan Collins Date: Mon, 18 May 2026 20:31:02 -0700 Subject: [PATCH] geotiff tests: patch correct symbol and use valid tile_size (#2101) Two unrelated stale-test bugs caused 8 failures in `pytest xrspatial/geotiff/tests`: - `test_predictor2_big_endian_gpu_1517.py::_block_cpu_fallback` patched `xrspatial.geotiff.read_to_array`, a name that disappeared from the package namespace when `read_geotiff_gpu` moved into `xrspatial/geotiff/_backends/gpu.py` (PR #1885). The package now imports the symbol as `_read_to_array`, and the actual call site is the bound `_read_to_array` inside `_backends.gpu`. With `raising=True`, the monkeypatch aborted before the GPU path ran. Patch the call site instead. - `test_size_param_validation_gpu_vrt_1776.py::test_tile_size_positive_works` passed `tile_size=4`. The validator later grew a multiple-of-16 requirement (TIFF 6 spec), so 4 is no longer accepted. Use `tile_size=16`, the smallest valid value, which keeps the test's original intent. --- .../tests/test_predictor2_big_endian_gpu_1517.py | 12 +++++++----- .../tests/test_size_param_validation_gpu_vrt_1776.py | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/xrspatial/geotiff/tests/test_predictor2_big_endian_gpu_1517.py b/xrspatial/geotiff/tests/test_predictor2_big_endian_gpu_1517.py index f2fee9ac7..f03864a14 100644 --- a/xrspatial/geotiff/tests/test_predictor2_big_endian_gpu_1517.py +++ b/xrspatial/geotiff/tests/test_predictor2_big_endian_gpu_1517.py @@ -46,14 +46,16 @@ def _block_cpu_fallback(monkeypatch): ``read_geotiff_gpu`` returns a cupy-backed array even when its silent CPU fallback fires (the fallback wraps the CPU result with ``cupy.asarray``), so ``isinstance(gpu_da.data, cupy.ndarray)`` cannot distinguish the two - paths. Patching the module-bound ``read_to_array`` to raise turns any - silent fallback into a hard test failure, which is what we want when the - point of a test is to exercise the actual GPU decode kernels. + paths. ``read_geotiff_gpu`` lives in ``xrspatial.geotiff._backends.gpu`` + and calls the locally bound ``_read_to_array`` symbol there; patching + that binding to raise turns any silent fallback into a hard test failure, + which is what we want when the point of a test is to exercise the actual + GPU decode kernels. Tests that legitimately rely on the CPU fallback (e.g. stripped layouts) must not call this helper. """ - from xrspatial import geotiff as geotiff_pkg + from xrspatial.geotiff._backends import gpu as gpu_backend def _no_fallback(*args, **kwargs): raise AssertionError( @@ -62,7 +64,7 @@ def _no_fallback(*args, **kwargs): ) monkeypatch.setattr( - geotiff_pkg, 'read_to_array', _no_fallback, raising=True, + gpu_backend, '_read_to_array', _no_fallback, raising=True, ) diff --git a/xrspatial/geotiff/tests/test_size_param_validation_gpu_vrt_1776.py b/xrspatial/geotiff/tests/test_size_param_validation_gpu_vrt_1776.py index 73c67176f..5b9b13801 100644 --- a/xrspatial/geotiff/tests/test_size_param_validation_gpu_vrt_1776.py +++ b/xrspatial/geotiff/tests/test_size_param_validation_gpu_vrt_1776.py @@ -113,9 +113,10 @@ def test_tile_size_bool_false_raises(self, gpu_da, tmp_path): write_geotiff_gpu(gpu_da, out, tile_size=False) def test_tile_size_positive_works(self, gpu_da, tmp_path): - """tile_size=4 (small but valid) still round-trips.""" + """tile_size=16 (smallest valid multiple of 16 per TIFF 6) still + round-trips.""" out = os.path.join(str(tmp_path), 'out_1776.tif') - write_geotiff_gpu(gpu_da, out, tile_size=4) + write_geotiff_gpu(gpu_da, out, tile_size=16) assert os.path.exists(out) def test_tile_size_numpy_int_scalar_works(self, gpu_da, tmp_path):