Skip to content

Commit 9a38037

Browse files
committed
update tests
1 parent 21a97f5 commit 9a38037

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

src/async_geotiff/_windows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Window:
4242
def __post_init__(self) -> None:
4343
"""Validate window dimensions."""
4444
if self.col_off < 0 or self.row_off < 0:
45-
raise IndexError(
45+
raise WindowError(
4646
f"Window start indices must be non-negative, "
4747
f"got col_off={self.col_off}, row_off={self.row_off}",
4848
)

tests/test_read.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from rasterio.windows import Window
1010

1111
import async_geotiff
12+
from async_geotiff.exceptions import WindowError
1213

1314
if TYPE_CHECKING:
1415
from .conftest import LoadGeoTIFF, LoadRasterio, Variant
@@ -34,7 +35,7 @@ async def test_read_single_tile(
3435
geotiff = await load_geotiff(file_name, variant=variant)
3536

3637
# Read a small region within the first tile
37-
window = async_geotiff.Window(0, 0, 32, 32)
38+
window = async_geotiff.Window(col_off=0, row_off=0, width=32, height=32)
3839
result = await geotiff.read(window=window)
3940

4041
rasterio_window = Window(0, 0, 32, 32)
@@ -76,7 +77,12 @@ async def test_read_spanning_tiles(
7677
row_start = tile_height // 2
7778
row_stop = min(tile_height + tile_height // 2, geotiff.height)
7879

79-
window = ((row_start, row_stop), (col_start, col_stop))
80+
window = async_geotiff.Window(
81+
col_off=col_start,
82+
row_off=row_start,
83+
width=col_stop - col_start,
84+
height=row_stop - row_start,
85+
)
8086
result = await geotiff.read(window=window)
8187

8288
rasterio_window = Window(
@@ -110,7 +116,7 @@ async def test_read_overview(
110116
geotiff = await load_geotiff(file_name, variant=variant)
111117
overview = geotiff.overviews[0]
112118

113-
window = ((0, 32), (0, 32))
119+
window = async_geotiff.Window(col_off=0, row_off=0, width=32, height=32)
114120
result = await overview.read(window=window)
115121

116122
rasterio_window = Window(0, 0, 32, 32)
@@ -126,17 +132,28 @@ async def test_read_overview(
126132
async def test_read_bounds_validation(
127133
load_geotiff: LoadGeoTIFF,
128134
) -> None:
129-
"""Test that read raises IndexError for out-of-bounds windows."""
135+
"""Test that read raises WindowError for invalid windows."""
130136
geotiff = await load_geotiff("uint8_rgb_deflate_block64_cog", variant="rasterio")
131137

132138
# Negative start index
133-
with pytest.raises(IndexError, match="non-negative"):
134-
await geotiff.read(window=((-1, 10), (0, 10)))
139+
with pytest.raises(WindowError, match="non-negative"):
140+
await geotiff.read(
141+
window=async_geotiff.Window(col_off=-1, row_off=0, width=10, height=10),
142+
)
135143

136144
# Window extends past image bounds
137-
with pytest.raises(IndexError, match="outside image bounds"):
138-
await geotiff.read(window=((0, geotiff.height + 1), (0, 10)))
145+
with pytest.raises(WindowError, match="outside image bounds"):
146+
await geotiff.read(
147+
window=async_geotiff.Window(
148+
col_off=0,
149+
row_off=0,
150+
width=10,
151+
height=geotiff.height + 1,
152+
),
153+
)
139154

140155
# Zero-size window
141-
with pytest.raises(Exception, match="positive"):
142-
await geotiff.read(window=((10, 10), (0, 10)))
156+
with pytest.raises(WindowError, match="positive"):
157+
await geotiff.read(
158+
window=async_geotiff.Window(col_off=0, row_off=0, width=0, height=10),
159+
)

tests/test_windows.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def test_create_window(self) -> None:
2020
assert w.height == 50
2121

2222
def test_negative_offset_raises(self) -> None:
23-
"""Test that negative offsets raise IndexError."""
24-
with pytest.raises(IndexError, match="non-negative"):
23+
"""Test that negative offsets raise WindowError."""
24+
with pytest.raises(WindowError, match="non-negative"):
2525
Window(col_off=-1, row_off=0, width=10, height=10)
2626

2727
def test_negative_width_raises(self) -> None:

0 commit comments

Comments
 (0)