99from rasterio .windows import Window
1010
1111import async_geotiff
12+ from async_geotiff .exceptions import WindowError
1213
1314if 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(
126132async 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+ )
0 commit comments