Skip to content

Commit

Permalink
autotest: daas.py: use tmp_vsimem fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Oct 3, 2023
1 parent 438a28a commit 1d0f874
Showing 1 changed file with 20 additions and 40 deletions.
60 changes: 20 additions & 40 deletions autotest/gdrivers/daas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,11 +1520,26 @@ def test_daas_getbuffer_raw():
###############################################################################


def _daas_getbuffer(pixel_encoding, drv_name, drv_options, mime_type):
@pytest.mark.parametrize(
"pixel_encoding,drv_name,drv_options,mime_type",
[
(
"JPEG2000",
"JP2OPENJPEG",
["QUALITY=100", "REVERSIBLE=YES", "RESOLUTIONS=1", "CODEC=JP2"],
"image/jp2",
),
("JPEG2000", "JP2KAK", ["QUALITY=100", "CODEC=JP2"], "image/jp2"),
("JPEG", "JPEG", ["QUALITY=100"], "image/jpeg"),
("PNG", "PNG", [], "image/png"),
],
ids=("jpeg2000_jp2openjpeg", "jpeg2000_jp2kak", "jpeg", "png"),
)
def test_daas_getbuffer(tmp_vsimem, pixel_encoding, drv_name, drv_options, mime_type):

drv = gdal.GetDriverByName(drv_name)
if drv is None:
pytest.skip()
pytest.skip(f"Driver {drv_name} not available")

handler = webserver.SequentialHandler()
handler.add(
Expand Down Expand Up @@ -1580,7 +1595,7 @@ def _daas_getbuffer(pixel_encoding, drv_name, drv_options, mime_type):
src_ds.GetRasterBand(1).WriteRaster(0, 0, 100, 100, "A", buf_xsize=1, buf_ysize=1)
src_ds.GetRasterBand(2).WriteRaster(0, 0, 100, 100, "B", buf_xsize=1, buf_ysize=1)
src_ds.GetRasterBand(3).WriteRaster(0, 0, 100, 100, "C", buf_xsize=1, buf_ysize=1)
tmpfile = "/vsimem/tmp"
tmpfile = tmp_vsimem / "tmp"
drv.CreateCopy(tmpfile, src_ds, options=drv_options)
f = gdal.VSIFOpenL(tmpfile, "rb")
content = gdal.VSIFReadL(1, 10000, f)
Expand Down Expand Up @@ -1634,41 +1649,6 @@ def _daas_getbuffer(pixel_encoding, drv_name, drv_options, mime_type):
###############################################################################


def test_daas_getbuffer_png():
_daas_getbuffer("PNG", "PNG", [], "image/png")


###############################################################################


def test_daas_getbuffer_jpeg():
_daas_getbuffer("JPEG", "JPEG", ["QUALITY=100"], "image/jpeg")


###############################################################################


def test_daas_getbuffer_jpeg2000_jp2kak():

_daas_getbuffer("JPEG2000", "JP2KAK", ["QUALITY=100", "CODEC=JP2"], "image/jp2")


###############################################################################


def test_daas_getbuffer_jpeg2000_jp2openjpeg():

_daas_getbuffer(
"JPEG2000",
"JP2OPENJPEG",
["QUALITY=100", "REVERSIBLE=YES", "RESOLUTIONS=1", "CODEC=JP2"],
"image/jp2",
)


###############################################################################


def test_daas_getbuffer_overview():

handler = webserver.SequentialHandler()
Expand Down Expand Up @@ -2169,7 +2149,7 @@ def test_daas_mask():
###############################################################################


def test_daas_png_response_4_bands_for_a_one_band_request():
def test_daas_png_response_4_bands_for_a_one_band_request(tmp_vsimem):

# Valid JSon but invalid height (string)
handler = webserver.SequentialHandler()
Expand Down Expand Up @@ -2228,7 +2208,7 @@ def test_daas_png_response_4_bands_for_a_one_band_request():
src_ds.GetRasterBand(2).WriteRaster(0, 0, 2, 3, "B", buf_xsize=1, buf_ysize=1)
src_ds.GetRasterBand(3).WriteRaster(0, 0, 2, 3, "C", buf_xsize=1, buf_ysize=1)
src_ds.GetRasterBand(4).WriteRaster(0, 0, 2, 3, "D", buf_xsize=1, buf_ysize=1)
tmpfile = "/vsimem/out.png"
tmpfile = tmp_vsimem / "out.png"
gdal.GetDriverByName("PNG").CreateCopy(tmpfile, src_ds)
f = gdal.VSIFOpenL(tmpfile, "rb")
png_content = gdal.VSIFReadL(1, 10000, f)
Expand Down

0 comments on commit 1d0f874

Please sign in to comment.