Skip to content

Commit 0699aae

Browse files
authored
Update VRT window-clamp tests to match post-#1697 reject contract (#1731)
PRs #1692 and #1698 raced through main with conflicting expectations for out-of-bounds window=. #1692's tests were written against the pre-#1697 contract that silently clamped windows to the VRT extent (returning a smaller array). #1698 replaced that contract with the validator-rejects-up-front behaviour from #1634 / #1669 so all three backends (local, HTTP, VRT) raise ValueError on out-of-bounds windows. Update both clamp-assertion tests to use pytest.raises(ValueError) and rename them to reflect the new contract. The "negative offsets clamp to 0" path is also gone -- negative offsets now raise.
1 parent 1624d13 commit 0699aae

1 file changed

Lines changed: 18 additions & 23 deletions

File tree

xrspatial/geotiff/tests/test_kwarg_behaviour_2026_05_12_v2.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -460,39 +460,34 @@ def test_window_full_raster_matches_no_window(self, tmp_path):
460460

461461
np.testing.assert_array_equal(windowed, full)
462462

463-
def test_window_clamps_to_raster_bounds(self, tmp_path):
464-
"""Window extending past raster bounds is clipped, not an error.
465-
466-
Mirrors the ``r1 = min(vrt.height, r1)`` / ``c1 = min(...)``
467-
clamp in ``_vrt.read_vrt``. Without the clamp, the assembled
468-
``out_h``/``out_w`` would over-allocate and the result shape
469-
would not match the VRT's intersection with the request.
463+
def test_window_outside_raster_bounds_rejected(self, tmp_path):
464+
"""Window extending past raster bounds raises ``ValueError``.
465+
466+
``read_vrt`` used to silently clamp out-of-bounds windows. That
467+
masked caller bugs (typo'd coords, off-by-one extents) and made
468+
the returned shape disagree with the caller's coord arrays. As
469+
of #1697 / #1698 the validator rejects such windows up front
470+
with a typed ``ValueError`` instead.
470471
"""
471472
arr = np.arange(4 * 4, dtype=np.float32).reshape(4, 4)
472473
vrt = _make_single_tile_vrt(tmp_path, arr)
473474

474-
result = read_vrt(vrt, window=(0, 0, 100, 100))
475-
476-
# Output clamps to the VRT's own (4, 4) extent
477-
assert result.shape == (4, 4)
478-
np.testing.assert_array_equal(result.values, arr)
475+
with pytest.raises(ValueError, match="outside the VRT extent"):
476+
read_vrt(vrt, window=(0, 0, 100, 100))
479477

480-
def test_window_clamps_negative_offsets(self, tmp_path):
481-
"""Negative start offsets are clamped to 0.
478+
def test_window_negative_offsets_rejected(self, tmp_path):
479+
"""Negative start offsets raise ``ValueError``.
482480
483-
Matches the ``r0 = max(0, r0)`` / ``c0 = max(0, c0)`` guard
484-
inside ``_vrt.read_vrt``. Without this clamp, a caller passing
485-
a negative offset would either index off the start of the
486-
output buffer or hit an opaque shape error.
481+
Per the post-#1697 contract, ``read_vrt`` validates the window
482+
against the VRT extent. Negative offsets are rejected the same
483+
way an over-large window is, rather than being silently clamped
484+
to zero.
487485
"""
488486
arr = np.arange(4 * 4, dtype=np.float32).reshape(4, 4)
489487
vrt = _make_single_tile_vrt(tmp_path, arr)
490488

491-
# (-1, -2, 3, 4) clamps to (0, 0, 3, 4)
492-
result = read_vrt(vrt, window=(-1, -2, 3, 4))
493-
494-
assert result.shape == (3, 4)
495-
np.testing.assert_array_equal(result.values, arr[0:3, 0:4])
489+
with pytest.raises(ValueError, match="outside the VRT extent"):
490+
read_vrt(vrt, window=(-1, -2, 3, 4))
496491

497492
def test_window_across_mosaic_seam(self, tmp_path):
498493
"""Window straddling a multi-source seam reads both sources.

0 commit comments

Comments
 (0)