Skip to content

Commit

Permalink
Merge pull request #7279 from rouault/autotest_require_driver
Browse files Browse the repository at this point in the history
autotest: use pytest.mark.require_driver() in utilities/ and pyscripts/
  • Loading branch information
rouault authored Feb 21, 2023
2 parents 7545a08 + 0d60cc5 commit 9c0d353
Show file tree
Hide file tree
Showing 24 changed files with 210 additions and 573 deletions.
52 changes: 13 additions & 39 deletions autotest/pyscripts/test_gdal2tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,12 @@ def _verify_raster_band_checksums(filename, expected_cs=[]):
ds = None


@pytest.mark.require_driver("PNG")
def test_gdal2tiles_py_simple():
script_path = test_py_scripts.get_py_script("gdal2tiles")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("PNG") is None:
pytest.skip("PNG driver is missing")

shutil.copy(
test_py_scripts.get_data_path("gdrivers") + "small_world.tif",
"tmp/out_gdal2tiles_smallworld.tif",
Expand Down Expand Up @@ -93,15 +91,13 @@ def test_gdal2tiles_py_simple():
)


@pytest.mark.require_driver("PNG")
def test_gdal2tiles_py_zoom_option():

script_path = test_py_scripts.get_py_script("gdal2tiles")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("PNG") is None:
pytest.skip("PNG driver is missing")

shutil.rmtree("tmp/out_gdal2tiles_smallworld", ignore_errors=True)

# Because of multiprocessing, run as external process, to avoid issues with
Expand Down Expand Up @@ -130,15 +126,13 @@ def test_gdal2tiles_py_zoom_option():
assert ds is not None, "did not get kml"


@pytest.mark.require_driver("PNG")
def test_gdal2tiles_py_resampling_option():

script_path = test_py_scripts.get_py_script("gdal2tiles")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("PNG") is None:
pytest.skip("PNG driver is missing")

resampling_list = [
"average",
"near",
Expand Down Expand Up @@ -190,14 +184,12 @@ def test_gdal2tiles_py_resampling_option():
shutil.rmtree(out_dir, ignore_errors=True)


@pytest.mark.require_driver("PNG")
def test_gdal2tiles_py_xyz():
script_path = test_py_scripts.get_py_script("gdal2tiles")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("PNG") is None:
pytest.skip("PNG driver is missing")

try:
shutil.copy(
test_py_scripts.get_data_path("gdrivers") + "small_world.tif",
Expand Down Expand Up @@ -236,6 +228,7 @@ def test_gdal2tiles_py_xyz():
shutil.rmtree("tmp/out_gdal2tiles_smallworld_xyz")


@pytest.mark.require_driver("PNG")
def test_gdal2tiles_py_invalid_srs():
"""
Case where the input image is not georeferenced, i.e. it's missing the SRS info,
Expand All @@ -245,9 +238,6 @@ def test_gdal2tiles_py_invalid_srs():
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("PNG") is None:
pytest.skip("PNG driver is missing")

shutil.copy(
test_py_scripts.get_data_path("gdrivers") + "test_nosrs.vrt",
"tmp/out_gdal2tiles_test_nosrs.vrt",
Expand Down Expand Up @@ -335,15 +325,13 @@ def test_does_not_error_when_nothing_to_put_in_the_low_zoom_tile():
)


@pytest.mark.require_driver("PNG")
def test_handle_utf8_filename():
input_file = "data/test_utf8_漢字.vrt"
script_path = test_py_scripts.get_py_script("gdal2tiles")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("PNG") is None:
pytest.skip("PNG driver is missing")

out_folder = "tmp/utf8_test"

try:
Expand Down Expand Up @@ -376,14 +364,12 @@ def test_gdal2tiles_py_cleanup():
pass


@pytest.mark.require_driver("PNG")
def test_exclude_transparent_tiles():
script_path = test_py_scripts.get_py_script("gdal2tiles")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("PNG") is None:
pytest.skip("PNG driver is missing")

output_folder = "tmp/test_exclude_transparent_tiles"
os.makedirs(output_folder)

Expand Down Expand Up @@ -418,15 +404,13 @@ def test_exclude_transparent_tiles():
shutil.rmtree(output_folder)


@pytest.mark.require_driver("PNG")
def test_gdal2tiles_py_profile_raster():

script_path = test_py_scripts.get_py_script("gdal2tiles")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("PNG") is None:
pytest.skip("PNG driver is missing")

shutil.rmtree("tmp/out_gdal2tiles_smallworld", ignore_errors=True)

test_py_scripts.run_py_script_as_external_script(
Expand Down Expand Up @@ -460,15 +444,13 @@ def test_gdal2tiles_py_profile_raster():
shutil.rmtree("tmp/out_gdal2tiles_smallworld", ignore_errors=True)


@pytest.mark.require_driver("PNG")
def test_gdal2tiles_py_profile_raster_oversample():

script_path = test_py_scripts.get_py_script("gdal2tiles")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("PNG") is None:
pytest.skip("PNG driver is missing")

shutil.rmtree("tmp/out_gdal2tiles_smallworld", ignore_errors=True)

test_py_scripts.run_py_script_as_external_script(
Expand All @@ -492,15 +474,13 @@ def test_gdal2tiles_py_profile_raster_oversample():
shutil.rmtree("tmp/out_gdal2tiles_smallworld", ignore_errors=True)


@pytest.mark.require_driver("PNG")
def test_gdal2tiles_py_profile_raster_xyz():

script_path = test_py_scripts.get_py_script("gdal2tiles")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("PNG") is None:
pytest.skip("PNG driver is missing")

shutil.rmtree("tmp/out_gdal2tiles_smallworld", ignore_errors=True)

test_py_scripts.run_py_script_as_external_script(
Expand Down Expand Up @@ -535,15 +515,13 @@ def test_gdal2tiles_py_profile_raster_xyz():
shutil.rmtree("tmp/out_gdal2tiles_smallworld", ignore_errors=True)


@pytest.mark.require_driver("PNG")
def test_gdal2tiles_py_profile_geodetic_tmscompatible_xyz():

script_path = test_py_scripts.get_py_script("gdal2tiles")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("PNG") is None:
pytest.skip("PNG driver is missing")

shutil.rmtree("tmp/out_gdal2tiles_smallworld", ignore_errors=True)

test_py_scripts.run_py_script_as_external_script(
Expand Down Expand Up @@ -578,15 +556,13 @@ def test_gdal2tiles_py_profile_geodetic_tmscompatible_xyz():
shutil.rmtree("tmp/out_gdal2tiles_smallworld", ignore_errors=True)


@pytest.mark.require_driver("PNG")
def test_gdal2tiles_py_mapml():

script_path = test_py_scripts.get_py_script("gdal2tiles")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("PNG") is None:
pytest.skip("PNG driver is missing")

shutil.rmtree("tmp/out_gdal2tiles_mapml", ignore_errors=True)

gdal.Translate(
Expand Down Expand Up @@ -679,15 +655,13 @@ def _run_webp_test(script_path, resampling):
shutil.rmtree("tmp/out_gdal2tiles_smallworld_webp", ignore_errors=True)


@pytest.mark.require_driver("WEBP")
def test_gdal2tiles_py_webp():

script_path = test_py_scripts.get_py_script("gdal2tiles")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("WEBP") is None:
pytest.skip()

_run_webp_test(script_path, "average")
try:
import numpy
Expand Down
29 changes: 4 additions & 25 deletions autotest/pyscripts/test_gdal_ls_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,9 @@ def test_gdal_ls_py_4():
# List dir in /vsicurl/


@pytest.mark.require_driver("HTTP")
def test_gdal_ls_py_5():

drv = gdal.GetDriverByName("HTTP")
if drv is None:
pytest.skip()

if int(gdal.VersionInfo("VERSION_NUM")) < 1900:
pytest.skip("would stall for a long time")

f = gdal.VSIFOpenL(
"/vsicurl/https://raw.githubusercontent.com/OSGeo/gdal/release/3.1/autotest/ogr/data/poly.zip",
"rb",
Expand All @@ -157,12 +151,9 @@ def test_gdal_ls_py_5():
# List in a .zip in /vsicurl/


@pytest.mark.require_driver("HTTP")
def test_gdal_ls_py_6():

drv = gdal.GetDriverByName("HTTP")
if drv is None:
pytest.skip()

f = gdal.VSIFOpenL(
"/vsicurl/https://raw.githubusercontent.com/OSGeo/gdal/release/3.1/autotest/ogr/data/poly.zip",
"rb",
Expand Down Expand Up @@ -200,19 +191,13 @@ def test_gdal_ls_py_6():
# List dir in /vsicurl/ and recurse in zip


@pytest.mark.require_driver("HTTP")
def test_gdal_ls_py_7():

# Super slow on AppVeyor since a few weeks (Apr 2016)
if gdal.GetConfigOption("APPVEYOR") is not None:
pytest.skip("Slow on AppVeyor")

drv = gdal.GetDriverByName("HTTP")
if drv is None:
pytest.skip()

if int(gdal.VersionInfo("VERSION_NUM")) < 1900:
pytest.skip("would stall for a long time")

f = gdal.VSIFOpenL(
"/vsicurl/https://raw.githubusercontent.com/OSGeo/gdal/release/3.1/autotest/ogr/data/poly.zip",
"rb",
Expand All @@ -235,17 +220,11 @@ def test_gdal_ls_py_7():
# List FTP dir in /vsicurl/


@pytest.mark.require_driver("HTTP")
def test_gdal_ls_py_8():
if not gdaltest.run_slow_tests():
pytest.skip()

drv = gdal.GetDriverByName("HTTP")
if drv is None:
pytest.skip()

if int(gdal.VersionInfo("VERSION_NUM")) < 1900:
pytest.skip("would stall for a long time")

f = gdal.VSIFOpenL(
"/vsicurl/https://raw.githubusercontent.com/OSGeo/gdal/release/3.1/autotest/ogr/data/poly.zip",
"rb",
Expand Down
15 changes: 4 additions & 11 deletions autotest/pyscripts/test_gdal_polygonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@
# Test a fairly simple case, with nodata masking.


@pytest.mark.require_driver("AAIGRID")
def test_gdal_polygonize_1():

script_path = test_py_scripts.get_py_script("gdal_polygonize")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("AAIGRID") is None:
pytest.skip("AAIGRID driver is missing")

outfilename = "tmp/poly.shp"
# Create a OGR datasource to put results in.
shp_drv = ogr.GetDriverByName("ESRI Shapefile")
Expand Down Expand Up @@ -110,15 +108,13 @@ def test_gdal_polygonize_1():
# Test a simple case without masking.


@pytest.mark.require_driver("AAIGRID")
def test_gdal_polygonize_2():

script_path = test_py_scripts.get_py_script("gdal_polygonize")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("AAIGRID") is None:
pytest.skip("AAIGRID driver is missing")

outfilename = "tmp/out.geojson"
gdal.Unlink(outfilename)

Expand Down Expand Up @@ -169,15 +165,14 @@ def test_gdal_polygonize_2():
assert tr


@pytest.mark.require_driver("GPKG")
def test_gdal_polygonize_3():

script_path = test_py_scripts.get_py_script("gdal_polygonize")
if script_path is None:
pytest.skip()

drv = ogr.GetDriverByName("GPKG")
if drv is None:
pytest.skip()
outfilename = "tmp/out.gpkg"
if os.path.exists(outfilename):
drv.DeleteDataSource(outfilename)
Expand Down Expand Up @@ -215,15 +210,13 @@ def test_gdal_polygonize_3():
# Test -b mask


@pytest.mark.require_driver("GML")
def test_gdal_polygonize_4():

script_path = test_py_scripts.get_py_script("gdal_polygonize")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("GML") is None:
pytest.skip("GML driver is missing")

outfilename = "tmp/out.gml"
# Test mask syntax
test_py_scripts.run_py_script(
Expand Down
4 changes: 1 addition & 3 deletions autotest/pyscripts/test_gdal_retile.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,9 @@ def test_gdal_retile_5():
# Test gdal_retile.py


@pytest.mark.require_driver("PNG")
def test_gdal_retile_png():

if gdal.GetDriverByName("PNG") is None:
pytest.skip("PNG driver missing")

script_path = test_py_scripts.get_py_script("gdal_retile")
if script_path is None:
pytest.skip()
Expand Down
4 changes: 1 addition & 3 deletions autotest/pyscripts/test_gdal_sieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@
# Test a fairly default case.


@pytest.mark.require_driver("AAIGRID")
def test_gdal_sieve_1():

script_path = test_py_scripts.get_py_script("gdal_sieve")
if script_path is None:
pytest.skip()

if gdal.GetDriverByName("AAIGRID") is None:
pytest.skip("AAIGRID driver is missing")

drv = gdal.GetDriverByName("GTiff")
dst_ds = drv.Create("tmp/sieve_1.tif", 5, 7, 1, gdal.GDT_Byte)
dst_ds = None
Expand Down
Loading

0 comments on commit 9c0d353

Please sign in to comment.