Skip to content

Commit

Permalink
Simpler test
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Apr 16, 2024
1 parent ebed89e commit a697a48
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions autotest/gcore/vsifile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,24 +1306,13 @@ def test_vsifile_win32_network_path():
def test_vsifile_eof_cache_read(tmp_path):
"""Test issue GH #9658"""

np = pytest.importorskip("numpy")
# Create an empty GTiff file
filename = f"/vsizip/{tmp_path}/test.zip/testraster.tif"
driver = gdal.GetDriverByName("GTiff")
size = 1000
ds = driver.Create(
filename, size, size, 1, gdal.GDT_Byte, options=["STREAMABLE_OUTPUT=YES"]
)
assert ds
data = np.random.randint(0, 255, size=(size, size))
band = ds.GetRasterBand(1)
assert band.WriteArray(data) == 0
ds = None

# Read past EOF
tmp_filename = str(tmp_path / "vsifile_eof_cache_read.bin")
f = gdal.VSIFOpenL(tmp_filename, "wb")
gdal.VSIFWriteL(b"x" * 100000, 100000, 1, f)
gdal.VSIFCloseL(f)
with gdal.config_option("VSI_CACHE", "YES"):
ds = gdal.Open(filename)
assert ds
b = ds.GetRasterBand(1)
# Read all
b.ReadRaster(0, 0, size, size)
f = gdal.VSIFOpenL(tmp_filename, "rb")
gdal.VSIFSeekL(f, 60000, 0)
data = gdal.VSIFReadL(1, 75000, f) # reads past end of file
gdal.VSIFCloseL(f)
assert data == b"x" * 40000

0 comments on commit a697a48

Please sign in to comment.