From 7602c7c08ba3abc783e89fc32ef8e356a3303efc Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 20 Feb 2023 21:13:04 +0100 Subject: [PATCH 1/2] autotest/utilities: use pytest.mark.require_driver() (refs #4487) --- autotest/utilities/test_gdal_create.py | 8 +- autotest/utilities/test_gdal_grid.py | 86 ++----- autotest/utilities/test_gdal_rasterize.py | 39 +-- autotest/utilities/test_gdal_translate.py | 28 +- autotest/utilities/test_gdal_translate_lib.py | 4 +- autotest/utilities/test_gdaldem.py | 24 +- autotest/utilities/test_gdaldem_lib.py | 4 +- autotest/utilities/test_gdalinfo.py | 20 +- autotest/utilities/test_gdalinfo_lib.py | 4 +- autotest/utilities/test_gdalmdiminfo_lib.py | 4 +- autotest/utilities/test_gdalwarp.py | 24 +- autotest/utilities/test_gdalwarp_lib.py | 24 +- autotest/utilities/test_ogr2ogr.py | 243 ++++++------------ autotest/utilities/test_ogr2ogr_lib.py | 56 +--- autotest/utilities/test_ogrinfo.py | 15 +- 15 files changed, 164 insertions(+), 419 deletions(-) diff --git a/autotest/utilities/test_gdal_create.py b/autotest/utilities/test_gdal_create.py index 26fad5b31155..10e828d19812 100755 --- a/autotest/utilities/test_gdal_create.py +++ b/autotest/utilities/test_gdal_create.py @@ -76,11 +76,9 @@ def test_gdal_create_pdf_tif(): ############################################################################### +@pytest.mark.require_driver("PNG") def test_gdal_create_pdf_no_direct_write_capabilities(): - if gdal.GetDriverByName("PNG") is None: - pytest.skip("PNG driver missing") - if get_gdal_create_path() is None: pytest.skip() @@ -144,11 +142,9 @@ def test_gdal_create_pdf_composition(): ############################################################################### +@pytest.mark.require_driver("TGA") def test_gdal_create_not_write_driver(): - if gdal.GetDriverByName("TGA") is None: - pytest.skip("TGA driver missing") - if get_gdal_create_path() is None: pytest.skip() diff --git a/autotest/utilities/test_gdal_grid.py b/autotest/utilities/test_gdal_grid.py index dae1595d5ade..c7cfeb073eb1 100755 --- a/autotest/utilities/test_gdal_grid.py +++ b/autotest/utilities/test_gdal_grid.py @@ -129,13 +129,13 @@ def test_gdal_grid_1(): ############################################################################### # Test Nearest Neighbour gridding algorithm + + +@pytest.mark.require_driver("CSV") def test_gdal_grid_2(): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - # Open reference dataset ds_ref = gdal.Open("../gcore/data/byte.tif") checksum_ref = ds_ref.GetRasterBand(1).Checksum() @@ -193,14 +193,12 @@ def test_gdal_grid_2(): ds = None +@pytest.mark.require_driver("CSV") @pytest.mark.parametrize("use_quadtree", [True, False]) def test_gdal_grid_3(use_quadtree): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - # Open reference dataset ds_ref = gdal.Open("../gcore/data/byte.tif") checksum_ref = ds_ref.GetRasterBand(1).Checksum() @@ -311,13 +309,11 @@ def test_gdal_grid_3(use_quadtree): # Test Inverse Distance to a Power gridding algorithm +@pytest.mark.require_driver("CSV") def test_gdal_grid_4(): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# # Test generic implementation (no AVX, no SSE) outfiles.append("tmp/grid_invdist_generic.tif") @@ -493,13 +489,11 @@ def test_gdal_grid_4(): # Test Moving Average gridding algorithm +@pytest.mark.require_driver("CSV") def test_gdal_grid_5(): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# outfiles.append("tmp/grid_average.tif") try: @@ -552,14 +546,12 @@ def test_gdal_grid_5(): ds = None +@pytest.mark.require_driver("CSV") @pytest.mark.parametrize("use_quadtree", [True, False]) def test_gdal_grid_6(use_quadtree): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# outfiles.append("tmp/grid_average_190_190.tif") try: @@ -618,13 +610,11 @@ def test_gdal_grid_6(use_quadtree): # Test Minimum data metric +@pytest.mark.require_driver("CSV") def test_gdal_grid_7(): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# outfiles.append("tmp/grid_minimum.tif") try: @@ -680,14 +670,12 @@ def test_gdal_grid_7(): ds = None +@pytest.mark.require_driver("CSV") @pytest.mark.parametrize("use_quadtree", [True, False]) def test_gdal_grid_8(use_quadtree): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# outfiles.append("tmp/grid_minimum_180_180.tif") try: @@ -750,13 +738,11 @@ def test_gdal_grid_8(use_quadtree): # Test Maximum data metric +@pytest.mark.require_driver("CSV") def test_gdal_grid_9(): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# outfiles.append("tmp/grid_maximum.tif") try: @@ -812,14 +798,12 @@ def test_gdal_grid_9(): ds = None +@pytest.mark.require_driver("CSV") @pytest.mark.parametrize("use_quadtree", [True, False]) def test_gdal_grid_10(use_quadtree): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# outfiles.append("tmp/grid_maximum_180_180.tif") try: @@ -882,13 +866,11 @@ def test_gdal_grid_10(use_quadtree): # Test Range data metric +@pytest.mark.require_driver("CSV") def test_gdal_grid_11(): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# outfiles.append("tmp/grid_range.tif") try: @@ -917,14 +899,12 @@ def test_gdal_grid_11(): ds = None +@pytest.mark.require_driver("CSV") @pytest.mark.parametrize("use_quadtree", [True, False]) def test_gdal_grid_12(use_quadtree): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# outfiles.append("tmp/grid_range_90_90_8p.tif") try: @@ -961,14 +941,12 @@ def test_gdal_grid_12(use_quadtree): # Test Count data metric +@pytest.mark.require_driver("CSV") @pytest.mark.parametrize("use_quadtree", [True, False]) def test_gdal_grid_13(use_quadtree): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# outfiles.append("tmp/grid_count_70_70.tif") try: @@ -1029,13 +1007,11 @@ def test_gdal_grid_13(use_quadtree): # Test Average Distance data metric +@pytest.mark.require_driver("CSV") def test_gdal_grid_14(): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# outfiles.append("tmp/grid_avdist.tif") try: @@ -1063,14 +1039,12 @@ def test_gdal_grid_14(): ds_ref = None +@pytest.mark.require_driver("CSV") @pytest.mark.parametrize("use_quadtree", [True, False]) def test_gdal_grid_15(use_quadtree): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# outfiles.append("tmp/grid_avdist_150_150.tif") try: @@ -1105,13 +1079,11 @@ def test_gdal_grid_15(use_quadtree): # Test Average Distance Between Points data metric +@pytest.mark.require_driver("CSV") def test_gdal_grid_16(): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# outfiles.append("tmp/grid_avdistpts_150_50_-15.tif") try: @@ -1139,14 +1111,12 @@ def test_gdal_grid_16(): ds_ref = None +@pytest.mark.require_driver("CSV") @pytest.mark.parametrize("use_quadtree", [True, False]) def test_gdal_grid_17(use_quadtree): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# outfiles.append("tmp/grid_avdistpts_150_150.tif") try: @@ -1181,13 +1151,11 @@ def test_gdal_grid_17(use_quadtree): # Test linear +@pytest.mark.skipif(not gdal.HasTriangulation(), reason="qhull missing") def test_gdal_grid_18(): if gdal_grid is None: pytest.skip() - if not gdal.HasTriangulation(): - pytest.skip("qhull missing") - outfiles.append("tmp/n43_linear.tif") # Create a GDAL dataset from the previous generated OGR grid @@ -1216,13 +1184,11 @@ def test_gdal_grid_18(): # Test Inverse Distance to a Power with Nearest Neighbor gridding algorithm +@pytest.mark.require_driver("CSV") def test_gdal_grid_19(): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# # Test generic implementation (no AVX, no SSE) outfiles.append("tmp/grid_invdistnn_generic.tif") @@ -1303,16 +1269,12 @@ def test_gdal_grid_19(): # Test -clipsrc +@pytest.mark.require_driver("CSV") +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_gdal_grid_clipsrc(): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - - if not ogrtest.have_geos(): - pytest.skip() - ################# outfiles.append("tmp/grid_clipsrc.tif") try: @@ -1345,13 +1307,11 @@ def test_gdal_grid_clipsrc(): # Test -tr +@pytest.mark.require_driver("CSV") def test_gdal_grid_tr(): if gdal_grid is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - ################# outfiles.append("tmp/grid_count_70_70.tif") try: diff --git a/autotest/utilities/test_gdal_rasterize.py b/autotest/utilities/test_gdal_rasterize.py index 3a15137671c4..7e741ef323aa 100755 --- a/autotest/utilities/test_gdal_rasterize.py +++ b/autotest/utilities/test_gdal_rasterize.py @@ -127,14 +127,12 @@ def test_gdal_rasterize_1(): # Test rasterization with ALL_TOUCHED (adapted from alg/rasterize.py). +@pytest.mark.require_driver("CSV") def test_gdal_rasterize_2(): if test_cli_utilities.get_gdal_rasterize_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - # Create a raster to rasterize into. target_ds = gdal.GetDriverByName("GTiff").Create( @@ -269,14 +267,12 @@ def test_gdal_rasterize_4(): # Test point rasterization (#3774) +@pytest.mark.require_driver("CSV") def test_gdal_rasterize_5(): if test_cli_utilities.get_gdal_rasterize_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - f = open("tmp/test_gdal_rasterize_5.csv", "wb") f.write( """x,y,Value @@ -338,14 +334,12 @@ def test_gdal_rasterize_5(): # Test on the fly reprojection of input data +@pytest.mark.require_driver("CSV") def test_gdal_rasterize_6(): if test_cli_utilities.get_gdal_rasterize_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - f = open("tmp/test_gdal_rasterize_6.csv", "wb") f.write( """WKT,Value @@ -388,6 +382,8 @@ def test_gdal_rasterize_6(): # Test SQLITE dialect in SQL +@pytest.mark.require_driver("SQLite") +@pytest.mark.require_driver("CSV") @pytest.mark.parametrize("sql_in_file", [False, True]) def test_gdal_rasterize_7(sql_in_file): @@ -395,20 +391,13 @@ def test_gdal_rasterize_7(sql_in_file): if test_cli_utilities.get_gdal_rasterize_path() is None: pytest.skip() - drv = ogr.GetDriverByName("SQLite") - if drv is None: - pytest.skip("SQLite driver missing") - - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - - gdal.PushErrorHandler("CPLQuietErrorHandler") - ds = drv.CreateDataSource("/vsimem/foo.db", options=["SPATIALITE=YES"]) - if ds is None: - pytest.skip() - ds = None - gdal.Unlink("/vsimem/foo.db") - gdal.PopErrorHandler() + with gdaltest.error_handler(): + drv = ogr.GetDriverByName("SQLITE") + ds = drv.CreateDataSource("/vsimem/foo.db", options=["SPATIALITE=YES"]) + if ds is None: + pytest.skip("Spatialite not available") + ds = None + gdal.Unlink("/vsimem/foo.db") f = open("tmp/test_gdal_rasterize_7.csv", "wb") x = (0, 0, 50, 50, 25) @@ -457,14 +446,12 @@ def test_gdal_rasterize_7(sql_in_file): # layer, #6058. +@pytest.mark.require_driver("CSV") def test_gdal_rasterize_8(): if test_cli_utilities.get_gdal_rasterize_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver missing") - f = open("tmp/test_gdal_rasterize_8.csv", "wb") f.write("WKT,Value\n".encode("ascii")) f.write('"LINESTRING (0 0, 5 5, 10 0, 10 10)",1'.encode("ascii")) diff --git a/autotest/utilities/test_gdal_translate.py b/autotest/utilities/test_gdal_translate.py index 71f646e30c13..28a91dbe78d9 100755 --- a/autotest/utilities/test_gdal_translate.py +++ b/autotest/utilities/test_gdal_translate.py @@ -132,13 +132,11 @@ def test_gdal_translate_4(): # Test -expand option +@pytest.mark.require_driver("GIF") def test_gdal_translate_5(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() - if gdal.GetDriverByName("GIF") is None: - pytest.skip("GIF driver is missing") - gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + " -expand rgb ../gdrivers/data/gif/bug407.gif tmp/test5.tif" @@ -380,13 +378,11 @@ def test_gdal_translate_14(): # Test -sds option +@pytest.mark.require_driver("RPFTOC") def test_gdal_translate_15(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() - if gdal.GetDriverByName("RPFCTOC") is None: - pytest.skip("RPFTOC driver is missing") - gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + " -sds ../gdrivers/data/nitf/A.TOC tmp/test15.tif" @@ -423,13 +419,11 @@ def test_gdal_translate_16(): # Test -expand option to VRT +@pytest.mark.require_driver("GIF") def test_gdal_translate_17(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() - if gdal.GetDriverByName("GIF") is None: - pytest.skip("GIF driver is missing") - gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + " -of VRT -expand rgba ../gdrivers/data/gif/bug407.gif tmp/test17.vrt" @@ -469,13 +463,11 @@ def test_gdal_translate_17(): # Test translation of a VRT made of VRT +@pytest.mark.require_driver("BMP") def test_gdal_translate_18(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() - if gdal.GetDriverByName("BMP") is None: - pytest.skip("BMP driver is missing") - gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + " ../gcore/data/8bit_pal.bmp -of VRT tmp/test18_1.vrt" @@ -682,13 +674,11 @@ def test_gdal_translate_25(): # Test -a_nodata and -stats (#5463) +@pytest.mark.require_driver("XYZ") def test_gdal_translate_26(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() - if gdal.GetDriverByName("XYZ") is None: - pytest.skip("XYZ driver is missing") - f = open("tmp/test_gdal_translate_26.xyz", "wb") f.write( """X Y Z @@ -716,15 +706,13 @@ def test_gdal_translate_26(): # Test that we don't preserve statistics when we ought not. +@pytest.mark.require_driver("AAIGRID") def test_gdal_translate_27(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() if test_cli_utilities.get_gdalinfo_path() is None: pytest.skip() - if gdal.GetDriverByName("AAIGRID") is None: - pytest.skip("AAIGRID driver is missing") - f = open("tmp/test_gdal_translate_27.asc", "wb") f.write( """ncols 2 @@ -779,13 +767,11 @@ def test_gdal_translate_27(): # Test -oo +@pytest.mark.require_driver("AAIGRID") def test_gdal_translate_28(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() - if gdal.GetDriverByName("AAIGRID") is None: - pytest.skip("AAIGRID driver is missing") - gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + " ../gdrivers/data/aaigrid/float64.asc tmp/test_gdal_translate_28.tif -oo datatype=float64" diff --git a/autotest/utilities/test_gdal_translate_lib.py b/autotest/utilities/test_gdal_translate_lib.py index 8aa46d4dfd7e..50e43938e088 100755 --- a/autotest/utilities/test_gdal_translate_lib.py +++ b/autotest/utilities/test_gdal_translate_lib.py @@ -128,11 +128,9 @@ def test_gdal_translate_lib_4(): # Test rgbExpand option +@pytest.mark.require_driver("GIF") def test_gdal_translate_lib_5(): - if gdal.GetDriverByName("GIF") is None: - pytest.skip("GIF driver is missing") - ds = gdal.Open("../gdrivers/data/gif/bug407.gif") ds = gdal.Translate("tmp/test5.tif", ds, rgbExpand="rgb") assert ds is not None diff --git a/autotest/utilities/test_gdaldem.py b/autotest/utilities/test_gdaldem.py index 1191db34dd89..2592428d19c6 100755 --- a/autotest/utilities/test_gdaldem.py +++ b/autotest/utilities/test_gdaldem.py @@ -197,13 +197,11 @@ def test_gdaldem_hillshade_azimuth(): # Test gdaldem hillshade to PNG +@pytest.mark.require_driver("PNG") def test_gdaldem_hillshade_png(): if test_cli_utilities.get_gdaldem_path() is None: pytest.skip() - if gdal.GetDriverByName("PNG") is None: - pytest.skip("PNG driver is missing") - gdaltest.runexternal( test_cli_utilities.get_gdaldem_path() + " hillshade -of PNG -s 111120 -z 30 ../gdrivers/data/n43.tif tmp/n43_hillshade.png" @@ -222,13 +220,11 @@ def test_gdaldem_hillshade_png(): # Test gdaldem hillshade to PNG with -compute_edges +@pytest.mark.require_driver("PNG") def test_gdaldem_hillshade_png_compute_edges(): if test_cli_utilities.get_gdaldem_path() is None: pytest.skip() - if gdal.GetDriverByName("PNG") is None: - pytest.skip("PNG driver is missing") - gdaltest.runexternal( test_cli_utilities.get_gdaldem_path() + " hillshade -compute_edges -of PNG -s 111120 -z 30 ../gdrivers/data/n43.tif tmp/n43_hillshade_compute_edges.png" @@ -443,13 +439,11 @@ def test_gdaldem_color_relief_from_float32(): # Test gdaldem color relief to PNG +@pytest.mark.require_driver("PNG") def test_gdaldem_color_relief_png(): if test_cli_utilities.get_gdaldem_path() is None: pytest.skip() - if gdal.GetDriverByName("PNG") is None: - pytest.skip("PNG driver is missing") - gdaltest.runexternal( test_cli_utilities.get_gdaldem_path() + " color-relief -of PNG ../gdrivers/data/n43.tif data/color_file.txt tmp/n43_colorrelief.png" @@ -470,15 +464,13 @@ def test_gdaldem_color_relief_png(): # Test gdaldem color relief from a Float32 to PNG +@pytest.mark.require_driver("PNG") def test_gdaldem_color_relief_from_float32_to_png(): if test_cli_utilities.get_gdaldem_path() is None: pytest.skip() if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() - if gdal.GetDriverByName("PNG") is None: - pytest.skip("PNG driver is missing") - gdaltest.runexternal( test_cli_utilities.get_gdaldem_path() + " color-relief -of PNG tmp/n43_float32.tif data/color_file.txt tmp/n43_colorrelief_from_float32.png" @@ -547,13 +539,11 @@ def test_gdaldem_color_relief_nearest_color_entry_vrt(): # Test gdaldem color relief with a nan nodata +@pytest.mark.require_driver("AAIGRID") def test_gdaldem_color_relief_nodata_nan(): if test_cli_utilities.get_gdaldem_path() is None: pytest.skip() - if gdal.GetDriverByName("AAIGRID") is None: - pytest.skip("AAIGRID driver is missing") - f = open("tmp/nodata_nan_src.asc", "wt") f.write( """ncols 2 @@ -595,13 +585,11 @@ def test_gdaldem_color_relief_nodata_nan(): # Test gdaldem color relief with entries with repeated DEM values in the color table (#6422) +@pytest.mark.require_driver("AAIGRID") def test_gdaldem_color_relief_repeated_entry(): if test_cli_utilities.get_gdaldem_path() is None: pytest.skip() - if gdal.GetDriverByName("AAIGRID") is None: - pytest.skip("AAIGRID driver is missing") - f = open("tmp/test_gdaldem_color_relief_repeated_entry.asc", "wt") f.write( """ncols 2 diff --git a/autotest/utilities/test_gdaldem_lib.py b/autotest/utilities/test_gdaldem_lib.py index 7ad49f7028b6..841499863e04 100755 --- a/autotest/utilities/test_gdaldem_lib.py +++ b/autotest/utilities/test_gdaldem_lib.py @@ -103,11 +103,9 @@ def test_gdaldem_lib_hillshade_float(): # Test gdaldem hillshade with source being floating point +@pytest.mark.require_driver("PNG") def test_gdaldem_lib_hillshade_float_png(): - if gdal.GetDriverByName("PNG") is None: - pytest.skip("PNG driver is missing") - src_ds = gdal.Translate( "", gdal.Open("../gdrivers/data/n43.tif"), diff --git a/autotest/utilities/test_gdalinfo.py b/autotest/utilities/test_gdalinfo.py index 2f185adcf0e1..e624ca902b14 100755 --- a/autotest/utilities/test_gdalinfo.py +++ b/autotest/utilities/test_gdalinfo.py @@ -92,13 +92,11 @@ def test_gdalinfo_3(): # Test -noct option +@pytest.mark.require_driver("GIF") def test_gdalinfo_4(): if test_cli_utilities.get_gdalinfo_path() is None: pytest.skip() - if gdal.GetDriverByName("GIF") is None: - pytest.skip("GIF driver is missing") - ret = gdaltest.runexternal( test_cli_utilities.get_gdalinfo_path() + " ../gdrivers/data/gif/bug407.gif" ) @@ -222,13 +220,11 @@ def test_gdalinfo_8(): # Test -mdd option +@pytest.mark.require_driver("NITF") def test_gdalinfo_9(): if test_cli_utilities.get_gdalinfo_path() is None: pytest.skip() - if gdal.GetDriverByName("NITF") is None: - pytest.skip("NITF driver is missing") - ret = gdaltest.runexternal( test_cli_utilities.get_gdalinfo_path() + " ../gdrivers/data/nitf/fake_nsif.ntf" ) @@ -536,13 +532,11 @@ def test_gdalinfo_26(): # Test -oo +@pytest.mark.require_driver("AAIGRID") def test_gdalinfo_27(): if test_cli_utilities.get_gdalinfo_path() is None: pytest.skip() - if gdal.GetDriverByName("AAIGRID") is None: - pytest.skip("AAIGRID driver is missing") - ret = gdaltest.runexternal( test_cli_utilities.get_gdalinfo_path() + " ../gdrivers/data/aaigrid/float64.asc -oo datatype=float64", @@ -609,13 +603,11 @@ def test_gdalinfo_30(): # Test -json -noct option +@pytest.mark.require_driver("GIF") def test_gdalinfo_31(): if test_cli_utilities.get_gdalinfo_path() is None: pytest.skip() - if gdal.GetDriverByName("GIF") is None: - pytest.skip("GIF driver is missing") - ret = gdaltest.runexternal( test_cli_utilities.get_gdalinfo_path() + " -json ../gdrivers/data/gif/bug407.gif" @@ -994,13 +986,11 @@ def test_gdalinfo_35(): # Test -mdd option +@pytest.mark.require_driver("NITF") def test_gdalinfo_36(): if test_cli_utilities.get_gdalinfo_path() is None: pytest.skip() - if gdal.GetDriverByName("NITF") is None: - pytest.skip("NITF driver is missing") - ret = gdaltest.runexternal( test_cli_utilities.get_gdalinfo_path() + " -json ../gdrivers/data/nitf/fake_nsif.ntf" diff --git a/autotest/utilities/test_gdalinfo_lib.py b/autotest/utilities/test_gdalinfo_lib.py index 70bf3c20c23a..9d0cfa82514c 100755 --- a/autotest/utilities/test_gdalinfo_lib.py +++ b/autotest/utilities/test_gdalinfo_lib.py @@ -86,11 +86,9 @@ def test_gdalinfo_lib_2(): # Test extraMDDomains() +@pytest.mark.require_driver("NITF") def test_gdalinfo_lib_3(): - if gdal.GetDriverByName("NITF") is None: - pytest.skip("NITF driver is missing") - ds = gdal.Open("../gdrivers/data/nitf/fake_nsif.ntf") ret = gdal.Info(ds, format="json") diff --git a/autotest/utilities/test_gdalmdiminfo_lib.py b/autotest/utilities/test_gdalmdiminfo_lib.py index 107e0daa92b4..14be494275a9 100755 --- a/autotest/utilities/test_gdalmdiminfo_lib.py +++ b/autotest/utilities/test_gdalmdiminfo_lib.py @@ -272,11 +272,9 @@ def test_gdalmdiminfo_lib_mem_dataset(): # Test arrayoption +@pytest.mark.require_driver("netCDF") def test_gdalmdiminfo_lib_arrayoption(): - if gdal.GetDriverByName("netCDF") is None: - pytest.skip("netCDF driver not enabled") - ret = gdal.MultiDimInfo("../gdrivers/data/netcdf/with_bounds.nc") assert len(ret["arrays"]) == 2 diff --git a/autotest/utilities/test_gdalwarp.py b/autotest/utilities/test_gdalwarp.py index 71de5b0c2b1d..eb0708afee3d 100755 --- a/autotest/utilities/test_gdalwarp.py +++ b/autotest/utilities/test_gdalwarp.py @@ -499,13 +499,11 @@ def test_gdalwarp_20(): # Test cutline from OGR datasource. +@pytest.mark.require_driver("CSV") def test_gdalwarp_21(): if test_cli_utilities.get_gdalwarp_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - gdaltest.runexternal( test_cli_utilities.get_gdalwarp_path() + " ../gcore/data/utmsmall.tif tmp/testgdalwarp21.tif -cutline data/cutline.vrt -cl cutline" @@ -523,13 +521,11 @@ def test_gdalwarp_21(): # Test with a cutline and an output at a different resolution. +@pytest.mark.require_driver("CSV") def test_gdalwarp_22(): if test_cli_utilities.get_gdalwarp_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - gdaltest.runexternal( test_cli_utilities.get_gdalwarp_path() + " ../gcore/data/utmsmall.tif tmp/testgdalwarp22.tif -cutline data/cutline.vrt -cl cutline -tr 30 30" @@ -547,13 +543,11 @@ def test_gdalwarp_22(): # Test cutline with ALL_TOUCHED enabled. +@pytest.mark.require_driver("CSV") def test_gdalwarp_23(): if test_cli_utilities.get_gdalwarp_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - gdaltest.runexternal( test_cli_utilities.get_gdalwarp_path() + " -wo CUTLINE_ALL_TOUCHED=TRUE ../gcore/data/utmsmall.tif tmp/testgdalwarp23.tif -cutline data/cutline.vrt -cl cutline" @@ -1125,13 +1119,11 @@ def test_gdalwarp_37(): # Test implicit nodata setting (#5675) +@pytest.mark.require_driver("AAIGRID") def test_gdalwarp_38(): if test_cli_utilities.get_gdalwarp_path() is None: pytest.skip() - if gdal.GetDriverByName("AAIGRID") is None: - pytest.skip("AAIGRID driver is missing") - gdaltest.runexternal( test_cli_utilities.get_gdalwarp_path() + " data/withnodata.asc tmp/testgdalwarp38.tif" @@ -1147,13 +1139,11 @@ def test_gdalwarp_38(): # Test -oo +@pytest.mark.require_driver("AAIGRID") def test_gdalwarp_39(): if test_cli_utilities.get_gdalwarp_path() is None: pytest.skip() - if gdal.GetDriverByName("AAIGRID") is None: - pytest.skip("AAIGRID driver is missing") - gdaltest.runexternal( test_cli_utilities.get_gdalwarp_path() + " ../gdrivers/data/aaigrid/float64.asc tmp/test_gdalwarp_39.tif -oo DATATYPE=Float64 -overwrite" @@ -1602,15 +1592,13 @@ def test_gdalwarp_45(): # Test -crop_to_cutline +@pytest.mark.require_driver("CSV") def test_gdalwarp_46(): if test_cli_utilities.get_gdalwarp_path() is None: pytest.skip() if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - gdaltest.runexternal( test_cli_utilities.get_gdalwarp_path() + " ../gcore/data/utmsmall.tif tmp/test_gdalwarp_46.tif -cutline data/cutline.vrt -crop_to_cutline -overwrite" diff --git a/autotest/utilities/test_gdalwarp_lib.py b/autotest/utilities/test_gdalwarp_lib.py index b751c9654843..356bd2e60faf 100755 --- a/autotest/utilities/test_gdalwarp_lib.py +++ b/autotest/utilities/test_gdalwarp_lib.py @@ -446,11 +446,9 @@ def test_gdalwarp_lib_19(): # Test cutline from OGR datasource. +@pytest.mark.require_driver("CSV") def test_gdalwarp_lib_21(): - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - ds = gdal.Warp( "", "../gcore/data/utmsmall.tif", @@ -509,11 +507,9 @@ def test_gdalwarp_lib_cutline_larger_source_dataset(options): # Test cutline with ALL_TOUCHED enabled. +@pytest.mark.require_driver("CSV") def test_gdalwarp_lib_23(): - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - ds = gdal.Warp( "", "../gcore/data/utmsmall.tif", @@ -612,11 +608,9 @@ def test_gdalwarp_lib_45(): # Test -crop_to_cutline +@pytest.mark.require_driver("CSV") def test_gdalwarp_lib_46(): - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - ds = gdal.Warp( "", ["../gcore/data/utmsmall.tif"], @@ -758,11 +752,9 @@ def test_gdalwarp_lib_cutline_all_touched_single_pixel(): # (#7226)s +@pytest.mark.require_driver("CSV") def test_gdalwarp_lib_crop_to_cutline_slightly_shifted_wrt_pixel_boundaries(): - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - cutlineDSName = ( "/vsimem/test_gdalwarp_lib_crop_to_cutline_close_to_pixel_boundaries.json" ) @@ -977,11 +969,9 @@ def test_gdalwarp_lib_110(): # Test cutline SQL +@pytest.mark.require_driver("CSV") def test_gdalwarp_lib_111(): - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - ds = gdal.Warp( "", "../gcore/data/utmsmall.tif", @@ -1705,11 +1695,9 @@ def test_gdalwarp_lib_134(): # Test vertical datum shift +@pytest.mark.require_driver("GTX") def test_gdalwarp_lib_135(): - if gdal.GetDriverByName("GTX") is None: - pytest.skip("GTX driver is missing") - src_ds = gdal.GetDriverByName("MEM").Create("", 1, 1) src_ds.SetGeoTransform([500000, 1, 0, 4000000, 0, -1]) src_ds.GetRasterBand(1).Fill(100) diff --git a/autotest/utilities/test_ogr2ogr.py b/autotest/utilities/test_ogr2ogr.py index ee147fdb6892..bb750d1c0356 100755 --- a/autotest/utilities/test_ogr2ogr.py +++ b/autotest/utilities/test_ogr2ogr.py @@ -592,14 +592,12 @@ def test_ogr2ogr_17(): # Test -wrapdateline +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_18(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if not ogrtest.have_geos(): - pytest.skip() - try: os.stat("tmp/wrapdateline_src.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource( @@ -663,14 +661,12 @@ def test_ogr2ogr_18(): # at line of constant easting. +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_polygon_splitting(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if not ogrtest.have_geos(): - pytest.skip() - try: os.stat("tmp/wrapdateline_src.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource( @@ -723,13 +719,11 @@ def test_ogr2ogr_polygon_splitting(): # Test -clipsrc +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_19(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if not ogrtest.have_geos(): - pytest.skip() - try: os.stat("tmp/poly.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource("tmp/poly.shp") @@ -762,13 +756,11 @@ def test_ogr2ogr_19(): # FIXME: Any field is skipped if a subsequent field with same name is found. +@pytest.mark.require_driver("CSV") def test_ogr2ogr_20(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - expected_fields = [ "a", "A_1", @@ -849,13 +841,12 @@ def test_ogr2ogr_20(): # at dataset creation (#3247) +@pytest.mark.require_driver("GPX") +@pytest.mark.require_driver("CSV") def test_ogr2ogr_21(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("GPX") is None: - pytest.skip("GPX driver is missing") - try: os.remove("tmp/testogr2ogr21.gpx") except OSError: @@ -874,16 +865,12 @@ def test_ogr2ogr_21(): # Test ogr2ogr when the output driver delays the destination layer defn creation (#3384) +@pytest.mark.require_driver("MapInfo File") +@pytest.mark.require_driver("CSV") def test_ogr2ogr_22(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("MapInfo File") is None: - pytest.skip("MapInfo File driver is missing") - - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - gdaltest.runexternal( test_cli_utilities.get_ogr2ogr_path() + ' -f "MapInfo File" tmp/testogr2ogr22.mif data/dataforogr2ogr21.csv ' @@ -912,16 +899,12 @@ def test_ogr2ogr_22(): # Same as previous but with -select +@pytest.mark.require_driver("MapInfo File") +@pytest.mark.require_driver("CSV") def test_ogr2ogr_23(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("MapInfo File") is None: - pytest.skip("MapInfo File driver is missing") - - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - gdaltest.runexternal( test_cli_utilities.get_ogr2ogr_path() + ' -f "MapInfo File" tmp/testogr2ogr23.mif data/dataforogr2ogr21.csv ' @@ -950,13 +933,11 @@ def test_ogr2ogr_23(): # Test -clipsrc with WKT geometry (#3530) +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_24(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if not ogrtest.have_geos(): - pytest.skip() - try: os.stat("tmp/poly.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource("tmp/poly.shp") @@ -987,16 +968,12 @@ def test_ogr2ogr_24(): # Test -clipsrc with clip from external datasource +@pytest.mark.require_driver("CSV") +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_25(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if not ogrtest.have_geos(): - pytest.skip() - - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - try: os.stat("tmp/poly.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource("tmp/poly.shp") @@ -1035,13 +1012,11 @@ def test_ogr2ogr_25(): # Test -clipdst with WKT geometry (#3530) +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_26(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if not ogrtest.have_geos(): - pytest.skip() - try: os.stat("tmp/poly.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource("tmp/poly.shp") @@ -1072,16 +1047,12 @@ def test_ogr2ogr_26(): # Test -clipdst with clip from external datasource +@pytest.mark.require_driver("CSV") +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_27(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if not ogrtest.have_geos(): - pytest.skip() - - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - try: os.stat("tmp/poly.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource("tmp/poly.shp") @@ -1181,14 +1152,12 @@ def test_ogr2ogr_28(): # Test -wrapdateline on polygons +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_29(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if not ogrtest.have_geos(): - pytest.skip() - for i in range(2): try: os.stat("tmp/wrapdateline_src.shp") @@ -1372,14 +1341,12 @@ def test_ogr2ogr_32(): # Test -explodecollections +@pytest.mark.require_driver("CSV") def test_ogr2ogr_33(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - try: os.stat("tmp/test_ogr2ogr_33_src.csv") ogr.GetDriverByName("CSV").DeleteDataSource("tmp/test_ogr2ogr_33_src.csv") @@ -1705,15 +1672,12 @@ def test_ogr2ogr_39(): # Test 'ogr2ogr -update asqlite.db asqlite.db layersrc -nln layerdst' (#4270) +@pytest.mark.require_driver("SQLite") def test_ogr2ogr_40(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - drv = ogr.GetDriverByName("SQLite") - if drv is None: - pytest.skip() - try: ogr.GetDriverByName("SQLite").DeleteDataSource("tmp/test_ogr2ogr_40.db") except AttributeError: @@ -1862,14 +1826,12 @@ def test_ogr2ogr_43(): # Test -nlt PROMOTE_TO_MULTI for polygon/multipolygon +@pytest.mark.require_driver("GML") def test_ogr2ogr_44(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("GML") is None: - pytest.skip("GML driver is missing") - try: os.stat("tmp/test_ogr2ogr_44_src.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource( @@ -1928,14 +1890,12 @@ def test_ogr2ogr_44(): # Test -nlt PROMOTE_TO_MULTI for linestring/multilinestring +@pytest.mark.require_driver("GML") def test_ogr2ogr_45(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("GML") is None: - pytest.skip("GML driver is missing") - try: os.stat("tmp/test_ogr2ogr_45_src.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource( @@ -1994,14 +1954,12 @@ def test_ogr2ogr_45(): # Test -gcp (#4604) +@pytest.mark.require_driver("GML") def test_ogr2ogr_46(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("GML") is None: - pytest.skip("GML driver is missing") - try: os.stat("tmp/test_ogr2ogr_46_src.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource( @@ -2127,13 +2085,11 @@ def test_ogr2ogr_47(): # Test fieldmap option +@pytest.mark.require_driver("CSV") def test_ogr2ogr_48(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - gdaltest.runexternal(test_cli_utilities.get_ogr2ogr_path() + " tmp data/Fields.csv") gdaltest.runexternal( test_cli_utilities.get_ogr2ogr_path() @@ -2188,13 +2144,11 @@ def test_ogr2ogr_48(): # in target layer +@pytest.mark.require_driver("CSV") def test_ogr2ogr_49(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - gdaltest.runexternal( test_cli_utilities.get_ogr2ogr_path() + " -f CSV tmp/test_ogr2ogr_49.csv data/duplicatedfields.csv" @@ -2215,16 +2169,12 @@ def test_ogr2ogr_49(): # Test detection of duplicated field names is case insensitive (#5208) +@pytest.mark.require_driver("CSV") +@pytest.mark.require_driver("KML") def test_ogr2ogr_49_bis(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - - if gdal.GetDriverByName("KML") is None: - pytest.skip("KML driver is missing") - gdaltest.runexternal( test_cli_utilities.get_ogr2ogr_path() + ' -f KML tmp/test_ogr2ogr_49_bis.kml data/grid.csv -sql "SELECT field_1 AS name FROM grid WHERE fid = 1"' @@ -2256,13 +2206,11 @@ def test_ogr2ogr_49_bis(): # Test -addfields +@pytest.mark.require_driver("CSV") def test_ogr2ogr_50(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - f = open("tmp/test_ogr2ogr_50_1.csv", "wt") f.write("id,field1\n") f.write("1,foo\n") @@ -2304,13 +2252,11 @@ def test_ogr2ogr_50(): # Test RFC 41 support +@pytest.mark.require_driver("CSV") def test_ogr2ogr_51(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - f = open("tmp/test_ogr2ogr_51_src.csv", "wt") f.write("id,_WKTgeom1_EPSG_4326,foo,_WKTgeom2_EPSG_32631\n") f.write('1,"POINT(1 2)","bar","POINT(3 4)"\n') @@ -2413,13 +2359,11 @@ def test_ogr2ogr_51(): # Test -nlt CONVERT_TO_LINEAR and -nlt CONVERT_TO_CURVE +@pytest.mark.require_driver("CSV") def test_ogr2ogr_52(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - f = open("tmp/test_ogr2ogr_52_src.csv", "wt") f.write("id,WKT\n") f.write('1,"CIRCULARSTRING(0 0,1 0,0 0)"\n') @@ -2456,15 +2400,12 @@ def test_ogr2ogr_52(): # Test -mapFieldType and 64 bit integers +@pytest.mark.require_driver("CSV") +@pytest.mark.require_driver("KML") def test_ogr2ogr_53(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - if gdal.GetDriverByName("KML") is None: - pytest.skip("KML driver is missing") - f = open("tmp/test_ogr2ogr_53.csv", "wt") f.write("id,i64,b,WKT\n") f.write('1,123456789012,true,"POINT(0 0)"\n') @@ -2530,15 +2471,12 @@ def test_ogr2ogr_53(): # Test behaviour with nullable fields +@pytest.mark.require_driver("CSV") +@pytest.mark.require_driver("GML") def test_ogr2ogr_54(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - if gdal.GetDriverByName("GML") is None: - pytest.skip("GML driver is missing") - f = open("tmp/test_ogr2ogr_54.csv", "wt") f.write("fld1,fld2,WKT\n") f.write('1,2,"POINT(0 0)"\n') @@ -2611,15 +2549,12 @@ def test_ogr2ogr_54(): # Test behaviour with default values +@pytest.mark.require_driver("CSV") +@pytest.mark.require_driver("GML") def test_ogr2ogr_55(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - if gdal.GetDriverByName("GML") is None: - pytest.skip("GML driver is missing") - f = open("tmp/test_ogr2ogr_55.csv", "wt") f.write("fld1,fld2,WKT\n") f.write('1,,"POINT(0 0)"\n') @@ -2683,15 +2618,12 @@ def test_ogr2ogr_55(): # Test behaviour when creating a field with same name as FID column. +@pytest.mark.require_driver("CSV") +@pytest.mark.require_driver("PGDump") def test_ogr2ogr_56(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - if gdal.GetDriverByName("PGDump") is None: - pytest.skip("PGDump driver is missing") - f = open("tmp/test_ogr2ogr_56.csv", "wt") f.write("str,myid,WKT\n") f.write('aaa,10,"POINT(0 0)"\n') @@ -2725,15 +2657,12 @@ def test_ogr2ogr_56(): # Test default propagation of FID column name and values, and -unsetFid +@pytest.mark.require_driver("CSV") +@pytest.mark.require_driver("PGDump") def test_ogr2ogr_57(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - if gdal.GetDriverByName("PGDump") is None: - pytest.skip("PGDump driver is missing") - f = open("tmp/test_ogr2ogr_57.csv", "wt") f.write("id,str,WKT\n") f.write('10,a,"POINT(0 0)"\n') @@ -2805,11 +2734,10 @@ def test_ogr2ogr_57(): # Test datasource transactions +@pytest.mark.require_driver("SQLite") def test_ogr2ogr_58(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if ogr.GetDriverByName("SQLite") is None: - pytest.skip() gdaltest.runexternal( test_cli_utilities.get_ogr2ogr_path() @@ -2828,11 +2756,10 @@ def test_ogr2ogr_58(): # Test metadata support +@pytest.mark.require_driver("GPKG") def test_ogr2ogr_59(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if ogr.GetDriverByName("GPKG") is None: - pytest.skip() ds = ogr.GetDriverByName("GPKG").CreateDataSource("tmp/test_ogr2ogr_59_src.gpkg") ds.SetMetadataItem("FOO", "BAR") @@ -2876,15 +2803,14 @@ def test_ogr2ogr_59(): # Test forced datasource transactions +@pytest.mark.require_driver("OpenFileGDB") def test_ogr2ogr_60(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if ogr.GetDriverByName("FileGDB") is None: - pytest.skip() gdaltest.runexternal( test_cli_utilities.get_ogr2ogr_path() - + " -ds_transaction -f FileGDB tmp/test_ogr2ogr_60.gdb ../ogr/data/poly.shp -mapFieldType Integer64=Integer" + + " -ds_transaction -f OpenFileGDB tmp/test_ogr2ogr_60.gdb ../ogr/data/poly.shp -mapFieldType Integer64=Integer" ) ds = ogr.Open("tmp/test_ogr2ogr_60.gdb") @@ -2892,20 +2818,18 @@ def test_ogr2ogr_60(): assert lyr.GetFeatureCount() == 10 ds = None - ogr.GetDriverByName("FileGDB").DeleteDataSource("tmp/test_ogr2ogr_60.gdb") + ogr.GetDriverByName("OpenFileGDB").DeleteDataSource("tmp/test_ogr2ogr_60.gdb") ############################################################################### # Test -spat_srs +@pytest.mark.require_driver("CSV") def test_ogr2ogr_61(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - f = open("tmp/test_ogr2ogr_61.csv", "wt") f.write("foo,WKT\n") f.write('1,"POINT(2 49)"\n') @@ -3002,13 +2926,11 @@ def test_ogr2ogr_63(): # Test appending multiple layers, whose one already exists (#6345) +@pytest.mark.require_driver("CSV") def test_ogr2ogr_64(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - try: shutil.rmtree("tmp/in_csv") except OSError: @@ -3049,13 +2971,11 @@ def test_ogr2ogr_64(): # Test detection of extension +@pytest.mark.require_driver("CSV") def test_ogr2ogr_65(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - gdaltest.runexternal( test_cli_utilities.get_ogr2ogr_path() + " tmp/out.csv ../ogr/data/poly.shp" ) @@ -3095,15 +3015,19 @@ def hexify_double(val): return val.rstrip("L").lstrip("0x").zfill(16).upper() -def check_identity_transformation(x, y, srid): +############################################################################### +# Test coordinates values are preserved for identity transformations + +# The x value is such that x * k * (1/k) != x with k the common factor used in degrees unit definition +# If the coordinates are converted to radians and back to degrees the value of x will be altered +@pytest.mark.parametrize("x,y,srid", [(float.fromhex("0x1.5EB3ED959A307p6"), 0, 4326)]) +@pytest.mark.require_driver("CSV") +def test_ogr2ogr_check_identity_transformation(x, y, srid): import struct if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - shape_drv = ogr.GetDriverByName("ESRI Shapefile") for output_shp in ["tmp/output_point.shp", "tmp/output_point2.shp"]: try: @@ -3135,45 +3059,26 @@ def check_identity_transformation(x, y, srid): ds = ogr.Open("tmp/output_point.shp") feat = ds.GetLayer(0).GetNextFeature() - ok = feat.GetGeometryRef().GetX() == x and feat.GetGeometryRef().GetY() == y - feat.Destroy() - ds.Destroy() + try: + assert feat.GetGeometryRef().GetX() == x and feat.GetGeometryRef().GetY() == y + finally: + feat.Destroy() + ds.Destroy() + os.remove("tmp/input_point.csv") - if ok: - # Now, transforming SHP to SHP will have a different definition of the SRS (EPSG:srid) which comes from the previously saved .prj file - # For angular units in degrees the .prj is saved with greater precision than the internally used value. - # We perform this additional transformation to exercise the case of units defined with different precision - gdaltest.runexternal( - test_cli_utilities.get_ogr2ogr_path() - + " tmp/output_point2.shp tmp/output_point.shp -t_srs EPSG:%(srid)d" - % locals() - ) - ds = ogr.Open("tmp/output_point2.shp") - feat = ds.GetLayer(0).GetNextFeature() - ok = feat.GetGeometryRef().GetX() == x and feat.GetGeometryRef().GetY() == y + # Now, transforming SHP to SHP will have a different definition of the SRS (EPSG:srid) which comes from the previously saved .prj file + # For angular units in degrees the .prj is saved with greater precision than the internally used value. + # We perform this additional transformation to exercise the case of units defined with different precision + gdaltest.runexternal( + test_cli_utilities.get_ogr2ogr_path() + + " tmp/output_point2.shp tmp/output_point.shp -t_srs EPSG:%(srid)d" % locals() + ) + ds = ogr.Open("tmp/output_point2.shp") + feat = ds.GetLayer(0).GetNextFeature() + try: + assert feat.GetGeometryRef().GetX() == x and feat.GetGeometryRef().GetY() == y + finally: feat.Destroy() ds.Destroy() + shape_drv.DeleteDataSource("tmp/output_point.shp") shape_drv.DeleteDataSource("tmp/output_point2.shp") - - shape_drv.DeleteDataSource("tmp/output_point.shp") - os.remove("tmp/input_point.csv") - - assert ok - - -############################################################################### -# Test coordinates values are preserved for identity transformations - - -def test_ogr2ogr_67(): - - # Test coordinates - # The x value is such that x * k * (1/k) != x with k the common factor used in degrees unit definition - # If the coordinates are converted to radians and back to degrees the value of x will be altered - x = float.fromhex("0x1.5EB3ED959A307p6") - y = 0.0 - - # Now we will check the value of x is preserved in a transformation with same target and source SRS, - # both as latitutude/longitude in degrees. - ret = check_identity_transformation(x, y, 4326) - return ret diff --git a/autotest/utilities/test_ogr2ogr_lib.py b/autotest/utilities/test_ogr2ogr_lib.py index 4d022055d766..5a5b36c0b83d 100755 --- a/autotest/utilities/test_ogr2ogr_lib.py +++ b/autotest/utilities/test_ogr2ogr_lib.py @@ -420,11 +420,9 @@ def test_ogr2ogr_lib_19(): # Test preservation of source geometry field name +@pytest.mark.require_driver("GPKG") def test_ogr2ogr_lib_20(): - if ogr.GetDriverByName("GPKG") is None: - pytest.skip() - src_ds = gdal.GetDriverByName("Memory").Create("", 0, 0, 0) lyr = src_ds.CreateLayer("layer", geom_type=ogr.wkbNone) lyr.CreateGeomField(ogr.GeomFieldDefn("foo")) @@ -480,14 +478,10 @@ def test_ogr2ogr_lib_21(): ############################################################################### +@pytest.mark.require_driver("CSV") +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_clipsrc_wkt_no_dst_geom(): - if not ogrtest.have_geos(): - pytest.skip() - - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - tmpfilename = "/vsimem/out.csv" wkt = "POLYGON ((479461 4764494,479461 4764196,480012 4764196,480012 4764494,479461 4764494))" ds = gdal.VectorTranslate( @@ -645,11 +639,9 @@ def test_ogr2ogr_lib_convert_to_linear_promote_to_multi(geometryType): # Test -makevalid +@pytest.mark.require_driver("CSV") def test_ogr2ogr_lib_makevalid(): - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - # Check if MakeValid() is available g = ogr.CreateGeometryFromWkt("POLYGON ((0 0,10 10,0 10,10 0,0 0))") with gdaltest.error_handler(): @@ -898,11 +890,9 @@ def test_ogr2ogr_t_coord_epoch(): # Test laundering of geometry column name when outputting to PostgreSQL (#6261) +@pytest.mark.require_driver("PGDump") def test_ogr2ogr_launder_geometry_column_name(): - if gdal.GetDriverByName("PGDump") is None: - pytest.skip("PGDump driver not available") - srcDS = gdal.GetDriverByName("Memory").Create("", 0, 0, 0, gdal.GDT_Unknown) lyr = srcDS.CreateLayer("test", geom_type=ogr.wkbNone) lyr.CreateGeomField(ogr.GeomFieldDefn("SHAPE", ogr.wkbPoint)) @@ -997,11 +987,9 @@ def create_mem_file(): # Test -t_srs to a driver that automatically reprojects to WGS 84 +@pytest.mark.require_driver("GeoJSONSeq") def test_ogr2ogr_lib_t_srs_ignored(): - if gdal.GetDriverByName("GeoJSONSeq") is None: - pytest.skip("GeoJSONSeq driver is not available") - srcDS = gdal.GetDriverByName("Memory").Create("", 0, 0, 0, gdal.GDT_Unknown) srs = osr.SpatialReference() srs.ImportFromEPSG(4326) @@ -1039,14 +1027,12 @@ def my_handler(errorClass, errno, msg): # Test spatSRS +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_lib_spat_srs_projected(): # Check that we densify spatial filter geometry when not expressed in # the layer CRS - if not ogrtest.have_geos(): - pytest.skip("GEOS is not available") - srcDS = gdal.GetDriverByName("Memory").Create("", 0, 0, 0, gdal.GDT_Unknown) srs = osr.SpatialReference() srs.ImportFromEPSG(4326) @@ -1076,14 +1062,12 @@ def test_ogr2ogr_lib_spat_srs_projected(): # Test spatSRS +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_lib_spat_srs_geographic(): # Check that we densify spatial filter geometry when not expressed in # the layer CRS - if not ogrtest.have_geos(): - pytest.skip("GEOS is not available") - srcDS = gdal.GetDriverByName("Memory").Create("", 0, 0, 0, gdal.GDT_Unknown) srs = osr.SpatialReference() srs.ImportFromEPSG(32661) @@ -1106,9 +1090,7 @@ def test_ogr2ogr_lib_spat_srs_geographic(): # Test -clipsrc with a clip datasource -@pytest.mark.skipif( - ogr.GetDriverByName("GPKG") is None, reason="GPKG driver not available" -) +@pytest.mark.require_driver("GPKG") @pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS is not available") def test_ogr2ogr_lib_clipsrc_datasource(): @@ -1187,11 +1169,9 @@ def test_ogr2ogr_lib_clipsrc_datasource(): # Test -clipsrc and intersection being of a lower dimensionality +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_lib_clipsrc_discard_lower_dimensionality(): - if not ogrtest.have_geos(): - pytest.skip("GEOS is not available") - srcDS = gdal.GetDriverByName("Memory").Create("", 0, 0, 0, gdal.GDT_Unknown) srs = osr.SpatialReference() srs.ImportFromEPSG(4326) @@ -1211,9 +1191,7 @@ def test_ogr2ogr_lib_clipsrc_discard_lower_dimensionality(): # Test -clipdst with a clip datasource -@pytest.mark.skipif( - ogr.GetDriverByName("GPKG") is None, reason="GPKG driver not available" -) +@pytest.mark.require_driver("GPKG") @pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS is not available") def test_ogr2ogr_lib_clipdst_datasource(): @@ -1292,11 +1270,9 @@ def test_ogr2ogr_lib_clipdst_datasource(): # Test -clipdst and intersection being of a lower dimensionality +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_lib_clipdst_discard_lower_dimensionality(): - if not ogrtest.have_geos(): - pytest.skip("GEOS is not available") - srcDS = gdal.GetDriverByName("Memory").Create("", 0, 0, 0, gdal.GDT_Unknown) srs = osr.SpatialReference() srs.ImportFromEPSG(4326) @@ -1389,11 +1365,9 @@ def test_ogr2ogr_lib_explodecollections(): # Test converting a layer with a fid string to GPKG +@pytest.mark.require_driver("GPKG") def test_ogr2ogr_lib_fid_string_to_gpkg(): - if ogr.GetDriverByName("GPKG") is None: - pytest.skip("GPKG driver not available") - srcDS = gdal.GetDriverByName("Memory").Create("", 0, 0, 0, gdal.GDT_Unknown) srcLayer = srcDS.CreateLayer("test") srcLayer.CreateField(ogr.FieldDefn("fid")) @@ -1477,9 +1451,7 @@ def test_ogr2ogr_lib_simplify(): # Test using transactionSize -@pytest.mark.skipif( - ogr.GetDriverByName("GPKG") is None, reason="GPKG driver not available" -) +@pytest.mark.require_driver("GPKG") @pytest.mark.parametrize("transaction_size", [0, 10, "unlimited"]) def test_ogr2ogr_lib_transaction_size(transaction_size): diff --git a/autotest/utilities/test_ogrinfo.py b/autotest/utilities/test_ogrinfo.py index 3c28e2c0074f..7c9c2de51476 100755 --- a/autotest/utilities/test_ogrinfo.py +++ b/autotest/utilities/test_ogrinfo.py @@ -380,13 +380,11 @@ def test_ogrinfo_21(): # Test RFC 41 support +@pytest.mark.require_driver("CSV") def test_ogrinfo_22(): if test_cli_utilities.get_ogrinfo_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - f = open("tmp/test_ogrinfo_22.csv", "wt") f.write("_WKTgeom1_EPSG_4326,_WKTgeom2_EPSG_32631\n") f.write('"POINT(1 2)","POINT(3 4)"\n') @@ -472,13 +470,11 @@ def test_ogrinfo_22(): # Test -geomfield (RFC 41) support +@pytest.mark.require_driver("CSV") def test_ogrinfo_23(): if test_cli_utilities.get_ogrinfo_path() is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - f = open("tmp/test_ogrinfo_23.csv", "wt") f.write("_WKTgeom1_EPSG_4326,_WKTgeom2_EPSG_32631\n") f.write('"POINT(1 2)","POINT(3 4)"\n') @@ -673,11 +669,10 @@ def test_ogrinfo_nogeomtype(): # Test field domains +@pytest.mark.require_driver("GPKG") def test_ogrinfo_fielddomains(): if test_cli_utilities.get_ogrinfo_path() is None: pytest.skip() - if gdal.GetDriverByName("GPKG") is None: - pytest.skip("GPKG driver missing") (ret, err) = gdaltest.runexternal_out_and_err( test_cli_utilities.get_ogrinfo_path() + " -al ../ogr/data/gpkg/domains.gpkg" @@ -762,13 +757,11 @@ def test_ogrinfo_fielddomains(): # Test hiearchical presentation of layers +@pytest.mark.require_driver("OpenFileGDB") def test_ogrinfo_hiearchical(): if test_cli_utilities.get_ogrinfo_path() is None: pytest.skip() - if gdal.GetDriverByName("OpenFileGDB") is None: - pytest.skip("OpenFileGDB driver is missing") - (ret, err) = gdaltest.runexternal_out_and_err( test_cli_utilities.get_ogrinfo_path() + " ../ogr/data/filegdb/featuredataset.gdb" From 0d60cc552b78ddd2a418dea8be4471ac675fb3a5 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 20 Feb 2023 21:39:57 +0100 Subject: [PATCH 2/2] pyscripts/utilities: use pytest.mark.require_driver() (refs #4487) --- autotest/pyscripts/test_gdal2tiles.py | 52 +++++------------- autotest/pyscripts/test_gdal_ls_py.py | 29 ++-------- autotest/pyscripts/test_gdal_polygonize.py | 15 ++--- autotest/pyscripts/test_gdal_retile.py | 4 +- autotest/pyscripts/test_gdal_sieve.py | 4 +- autotest/pyscripts/test_gdalinfo_py.py | 10 +--- autotest/pyscripts/test_ogr2ogr_py.py | 64 ++++++---------------- autotest/pyscripts/test_ogrinfo_py.py | 10 +--- autotest/pyscripts/test_ogrmerge.py | 12 +--- 9 files changed, 46 insertions(+), 154 deletions(-) diff --git a/autotest/pyscripts/test_gdal2tiles.py b/autotest/pyscripts/test_gdal2tiles.py index 96c66f13b3c8..21e12b19fc1f 100755 --- a/autotest/pyscripts/test_gdal2tiles.py +++ b/autotest/pyscripts/test_gdal2tiles.py @@ -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", @@ -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 @@ -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", @@ -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", @@ -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, @@ -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", @@ -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: @@ -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) @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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 diff --git a/autotest/pyscripts/test_gdal_ls_py.py b/autotest/pyscripts/test_gdal_ls_py.py index ea1c10a492b1..3fb5455a2c3e 100755 --- a/autotest/pyscripts/test_gdal_ls_py.py +++ b/autotest/pyscripts/test_gdal_ls_py.py @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/autotest/pyscripts/test_gdal_polygonize.py b/autotest/pyscripts/test_gdal_polygonize.py index 83685f724fc5..c3969bf10e17 100755 --- a/autotest/pyscripts/test_gdal_polygonize.py +++ b/autotest/pyscripts/test_gdal_polygonize.py @@ -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") @@ -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) @@ -169,6 +165,7 @@ 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") @@ -176,8 +173,6 @@ def test_gdal_polygonize_3(): pytest.skip() drv = ogr.GetDriverByName("GPKG") - if drv is None: - pytest.skip() outfilename = "tmp/out.gpkg" if os.path.exists(outfilename): drv.DeleteDataSource(outfilename) @@ -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( diff --git a/autotest/pyscripts/test_gdal_retile.py b/autotest/pyscripts/test_gdal_retile.py index 7d7f707d79eb..f3d3588cbae5 100755 --- a/autotest/pyscripts/test_gdal_retile.py +++ b/autotest/pyscripts/test_gdal_retile.py @@ -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() diff --git a/autotest/pyscripts/test_gdal_sieve.py b/autotest/pyscripts/test_gdal_sieve.py index 2794a593e2fe..9595bb2bf242 100755 --- a/autotest/pyscripts/test_gdal_sieve.py +++ b/autotest/pyscripts/test_gdal_sieve.py @@ -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 diff --git a/autotest/pyscripts/test_gdalinfo_py.py b/autotest/pyscripts/test_gdalinfo_py.py index bb92c271d5a6..1ef0367c892e 100755 --- a/autotest/pyscripts/test_gdalinfo_py.py +++ b/autotest/pyscripts/test_gdalinfo_py.py @@ -34,8 +34,6 @@ import pytest import test_py_scripts -from osgeo import gdal - ############################################################################### # Simple test @@ -95,14 +93,12 @@ def test_gdalinfo_py_3(): # Test -noct option +@pytest.mark.require_driver("GIF") def test_gdalinfo_py_4(): script_path = test_py_scripts.get_py_script("gdalinfo") if script_path is None: pytest.skip() - if gdal.GetDriverByName("GIF") is None: - pytest.skip("GIF driver is missing") - ret = test_py_scripts.run_py_script( script_path, "gdalinfo", @@ -228,14 +224,12 @@ def test_gdalinfo_py_8(): # Test -mdd option +@pytest.mark.require_driver("NITF") def test_gdalinfo_py_9(): script_path = test_py_scripts.get_py_script("gdalinfo") if script_path is None: pytest.skip() - if gdal.GetDriverByName("NITF") is None: - pytest.skip("NITF driver is missing") - ret = test_py_scripts.run_py_script( script_path, "gdalinfo", diff --git a/autotest/pyscripts/test_ogr2ogr_py.py b/autotest/pyscripts/test_ogr2ogr_py.py index c240f7bfa482..0f4b919a8185 100755 --- a/autotest/pyscripts/test_ogr2ogr_py.py +++ b/autotest/pyscripts/test_ogr2ogr_py.py @@ -758,14 +758,12 @@ def test_ogr2ogr_py_19(): # FIXME: Any field is skipped if a subsequent field with same name is found. +@pytest.mark.require_driver("CSV") def test_ogr2ogr_py_20(): script_path = test_py_scripts.get_py_script("ogr2ogr") if script_path is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - try: os.remove("tmp/Fields.dbf") except OSError: @@ -855,14 +853,12 @@ def test_ogr2ogr_py_20(): # at dataset creation (#3247) +@pytest.mark.require_driver("GPX") def test_ogr2ogr_py_21(): script_path = test_py_scripts.get_py_script("ogr2ogr") if script_path is None: pytest.skip() - if ogr.GetDriverByName("GPX") is None: - pytest.skip() - try: os.remove("tmp/testogr2ogr21.gpx") except OSError: @@ -884,17 +880,13 @@ def test_ogr2ogr_py_21(): # Test ogr2ogr when the output driver delays the destination layer defn creation (#3384) +@pytest.mark.require_driver("MapInfo File") +@pytest.mark.require_driver("CSV") def test_ogr2ogr_py_22(): script_path = test_py_scripts.get_py_script("ogr2ogr") if script_path is None: pytest.skip() - if gdal.GetDriverByName("MapInfo File") is None: - pytest.skip("MapInfo File driver is missing") - - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - test_py_scripts.run_py_script( script_path, "ogr2ogr", @@ -926,6 +918,8 @@ def test_ogr2ogr_py_22(): # Same as previous but with -select +@pytest.mark.require_driver("MapInfo File") +@pytest.mark.require_driver("CSV") def test_ogr2ogr_py_23(): script_path = test_py_scripts.get_py_script("ogr2ogr") if script_path is None: @@ -933,12 +927,6 @@ def test_ogr2ogr_py_23(): if test_cli_utilities.get_ogr2ogr_path() is None: pytest.skip() - if gdal.GetDriverByName("MapInfo File") is None: - pytest.skip("MapInfo File driver is missing") - - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - gdaltest.runexternal( test_cli_utilities.get_ogr2ogr_path() + ' -f "MapInfo File" tmp/testogr2ogr23.mif ' @@ -969,14 +957,12 @@ def test_ogr2ogr_py_23(): # Test -clipsrc with WKT geometry (#3530) +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_py_24(): script_path = test_py_scripts.get_py_script("ogr2ogr") if script_path is None: pytest.skip() - if not ogrtest.have_geos(): - pytest.skip() - try: os.stat("tmp/poly.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource("tmp/poly.shp") @@ -1010,17 +996,13 @@ def test_ogr2ogr_py_24(): # Test -clipsrc with clip from external datasource +@pytest.mark.require_driver("CSV") +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_py_25(): script_path = test_py_scripts.get_py_script("ogr2ogr") if script_path is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - - if not ogrtest.have_geos(): - pytest.skip() - try: os.stat("tmp/poly.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource("tmp/poly.shp") @@ -1062,14 +1044,12 @@ def test_ogr2ogr_py_25(): # Test -clipdst with WKT geometry (#3530) +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_py_26(): script_path = test_py_scripts.get_py_script("ogr2ogr") if script_path is None: pytest.skip() - if not ogrtest.have_geos(): - pytest.skip() - try: os.stat("tmp/poly.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource("tmp/poly.shp") @@ -1103,17 +1083,13 @@ def test_ogr2ogr_py_26(): # Test -clipdst with clip from external datasource +@pytest.mark.require_driver("CSV") +@pytest.mark.skipif(not ogrtest.have_geos(), reason="GEOS missing") def test_ogr2ogr_py_27(): script_path = test_py_scripts.get_py_script("ogr2ogr") if script_path is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - - if not ogrtest.have_geos(): - pytest.skip() - try: os.stat("tmp/poly.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource("tmp/poly.shp") @@ -1236,15 +1212,13 @@ def test_ogr2ogr_py_32(): # Test -explodecollections +@pytest.mark.require_driver("CSV") def test_ogr2ogr_py_33(): script_path = test_py_scripts.get_py_script("ogr2ogr") if script_path is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - try: os.stat("tmp/test_ogr2ogr_33_src.csv") ogr.GetDriverByName("CSV").DeleteDataSource("tmp/test_ogr2ogr_33_src.csv") @@ -1685,15 +1659,13 @@ def test_ogr2ogr_py_43(): # Test -nlt PROMOTE_TO_MULTI for polygon/multipolygon +@pytest.mark.require_driver("GML") def test_ogr2ogr_py_44(): script_path = test_py_scripts.get_py_script("ogr2ogr") if script_path is None: pytest.skip() - if gdal.GetDriverByName("GML") is None: - pytest.skip("GML driver is missing") - try: os.stat("tmp/test_ogr2ogr_44_src.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource( @@ -1755,15 +1727,13 @@ def test_ogr2ogr_py_44(): # Test -nlt PROMOTE_TO_MULTI for polygon/multipolygon +@pytest.mark.require_driver("GML") def test_ogr2ogr_py_45(): script_path = test_py_scripts.get_py_script("ogr2ogr") if script_path is None: pytest.skip() - if gdal.GetDriverByName("GML") is None: - pytest.skip("GML driver is missing") - try: os.stat("tmp/test_ogr2ogr_44_src.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource( @@ -1825,15 +1795,13 @@ def test_ogr2ogr_py_45(): # Test -nlt PROMOTE_TO_MULTI for linestring/multilinestring +@pytest.mark.require_driver("CSV") def test_ogr2ogr_py_46(): script_path = test_py_scripts.get_py_script("ogr2ogr") if script_path is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - try: os.stat("tmp/test_ogr2ogr_45_src.shp") ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource( diff --git a/autotest/pyscripts/test_ogrinfo_py.py b/autotest/pyscripts/test_ogrinfo_py.py index 39a0eea021cb..f3cd4e7725f3 100755 --- a/autotest/pyscripts/test_ogrinfo_py.py +++ b/autotest/pyscripts/test_ogrinfo_py.py @@ -34,8 +34,6 @@ import pytest import test_py_scripts -from osgeo import gdal - ############################################################################### # Simple test @@ -233,14 +231,12 @@ def test_ogrinfo_py_11(): # Test RFC 41 support +@pytest.mark.require_driver("CSV") def test_ogrinfo_py_22(): script_path = test_py_scripts.get_py_script("ogrinfo") if script_path is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - f = open("tmp/test_ogrinfo_22.csv", "wt") f.write("_WKTgeom1_EPSG_4326,_WKTgeom2_EPSG_32631\n") f.write('"POINT(1 2)","POINT(3 4)"\n') @@ -321,14 +317,12 @@ def test_ogrinfo_py_22(): # Test -geomfield (RFC 41) support +@pytest.mark.require_driver("CSV") def test_ogrinfo_py_23(): script_path = test_py_scripts.get_py_script("ogrinfo") if script_path is None: pytest.skip() - if gdal.GetDriverByName("CSV") is None: - pytest.skip("CSV driver is missing") - f = open("tmp/test_ogrinfo_23.csv", "wt") f.write("_WKTgeom1_EPSG_4326,_WKTgeom2_EPSG_32631\n") f.write('"POINT(1 2)","POINT(3 4)"\n') diff --git a/autotest/pyscripts/test_ogrmerge.py b/autotest/pyscripts/test_ogrmerge.py index 821c946ad245..4389044d0654 100755 --- a/autotest/pyscripts/test_ogrmerge.py +++ b/autotest/pyscripts/test_ogrmerge.py @@ -476,6 +476,7 @@ def _validate_check(filename): # Test GPKG optimization +@pytest.mark.require_driver("GPKG") @pytest.mark.parametrize( "src_has_spatial_index,dst_has_spatial_index,has_progress,a_srs,s_srs,t_srs", [ @@ -501,9 +502,6 @@ def test_ogrmerge_gpkg( if script_path is None: pytest.skip() - if gdal.GetDriverByName("GPKG") is None: - pytest.skip("GPKG driver missing") - lco = [] if src_has_spatial_index else ["SPATIAL_INDEX=NO"] gdal.VectorTranslate( "tmp/in.gpkg", @@ -575,15 +573,13 @@ def test_ogrmerge_gpkg( # Test GPKG optimization for non-spatial layers +@pytest.mark.require_driver("GPKG") @pytest.mark.parametrize("has_progress", [True, False]) def test_ogrmerge_gpkg_non_spatial(has_progress): script_path = test_py_scripts.get_py_script("ogrmerge") if script_path is None: pytest.skip() - if gdal.GetDriverByName("GPKG") is None: - pytest.skip("GPKG driver missing") - src_ds = gdal.VectorTranslate( "tmp/in.gpkg", test_py_scripts.get_data_path("ogr") + "idlink.dbf" ) @@ -624,14 +620,12 @@ def test_ogrmerge_gpkg_non_spatial(has_progress): # Test GPKG optimization when a curve geometry is in a GEOMETRY typed column +@pytest.mark.require_driver("GPKG") def test_ogrmerge_gpkg_curve_geom_in_generic_layer(): script_path = test_py_scripts.get_py_script("ogrmerge") if script_path is None: pytest.skip() - if gdal.GetDriverByName("GPKG") is None: - pytest.skip("GPKG driver missing") - gdal.Unlink("tmp/out.gpkg") gdal.Unlink("tmp/in.gpkg")