diff --git a/autotest/pyscripts/test_gdal2tiles.py b/autotest/pyscripts/test_gdal2tiles.py index fcdeb079781d..9ab16be795a5 100755 --- a/autotest/pyscripts/test_gdal2tiles.py +++ b/autotest/pyscripts/test_gdal2tiles.py @@ -116,10 +116,14 @@ def test_gdal2tiles_py_simple(script_path, tmp_path): prev_wd = os.getcwd() try: os.chdir(tmp_path) - test_py_scripts.run_py_script(script_path, "gdal2tiles", f"-q {input_tif}") + _, err = test_py_scripts.run_py_script( + script_path, "gdal2tiles", f"-q {input_tif}", return_stderr=True + ) finally: os.chdir(prev_wd) + assert "UseExceptions" not in err + _verify_raster_band_checksums( f"{tmp_path}/out_gdal2tiles_smallworld/0/0/0.png", expected_cs=[31420, 32522, 16314, 17849], diff --git a/autotest/pyscripts/test_gdal2xyz.py b/autotest/pyscripts/test_gdal2xyz.py index 5a1a2c595f1e..41fc06b21d68 100644 --- a/autotest/pyscripts/test_gdal2xyz.py +++ b/autotest/pyscripts/test_gdal2xyz.py @@ -143,7 +143,10 @@ def test_gdal2xyz_py_2(script_path, tmp_path): arguments += " " + test_py_scripts.get_data_path("gcore") + "byte.tif " arguments += out_xyz - test_py_scripts.run_py_script(script_path, "gdal2xyz", arguments) + _, err = test_py_scripts.run_py_script( + script_path, "gdal2xyz", arguments, return_stderr=True + ) + assert "UseExceptions" not in err assert os.path.exists(out_xyz) diff --git a/autotest/pyscripts/test_gdal_calc.py b/autotest/pyscripts/test_gdal_calc.py index 85bb6a11e7bb..c7259fb2a4c5 100755 --- a/autotest/pyscripts/test_gdal_calc.py +++ b/autotest/pyscripts/test_gdal_calc.py @@ -156,9 +156,14 @@ def test_gdal_calc_py_1(script_path, tmp_path, stefan_full_rgba): test_id, test_count = 1, 3 out = make_temp_filename_list(tmp_path, test_id, test_count) - test_py_scripts.run_py_script( - script_path, "gdal_calc", f"-A {infile} --calc=A --overwrite --outfile {out[0]}" + _, err = test_py_scripts.run_py_script( + script_path, + "gdal_calc", + f"-A {infile} --calc=A --overwrite --outfile {out[0]}", + return_stderr=True, ) + assert "UseExceptions" not in err + test_py_scripts.run_py_script( script_path, "gdal_calc", diff --git a/autotest/pyscripts/test_gdal_edit.py b/autotest/pyscripts/test_gdal_edit.py index 8e90e7d6869f..4d29819a9bbe 100755 --- a/autotest/pyscripts/test_gdal_edit.py +++ b/autotest/pyscripts/test_gdal_edit.py @@ -97,7 +97,7 @@ def test_gdal_edit_py_1(script_path, tmp_path, read_only): val_encoded = val read_only_option = " -ro" if read_only else "" - test_py_scripts.run_py_script( + _, err = test_py_scripts.run_py_script( script_path, "gdal_edit", filename @@ -107,7 +107,9 @@ def test_gdal_edit_py_1(script_path, tmp_path, read_only): + val_encoded + "=UTF8" + read_only_option, + return_stderr=True, ) + assert "UseExceptions" not in err ds = gdal.Open(filename) wkt = ds.GetProjectionRef() diff --git a/autotest/pyscripts/test_gdal_fillnodata.py b/autotest/pyscripts/test_gdal_fillnodata.py index f8dcf95c3f39..84af78214693 100755 --- a/autotest/pyscripts/test_gdal_fillnodata.py +++ b/autotest/pyscripts/test_gdal_fillnodata.py @@ -76,11 +76,13 @@ def test_gdal_fillnodata_1(script_path, tmp_path): result_tif = str(tmp_path / "test_gdal_fillnodata_1.tif") - test_py_scripts.run_py_script( + _, err = test_py_scripts.run_py_script( script_path, "gdal_fillnodata", test_py_scripts.get_data_path("gcore") + f"byte.tif {result_tif}", + return_stderr=True, ) + assert "UseExceptions" not in err ds = gdal.Open(result_tif) assert ds.GetRasterBand(1).Checksum() == 4672 diff --git a/autotest/pyscripts/test_gdal_merge.py b/autotest/pyscripts/test_gdal_merge.py index 052fc5b547aa..4b1372efb3fa 100755 --- a/autotest/pyscripts/test_gdal_merge.py +++ b/autotest/pyscripts/test_gdal_merge.py @@ -113,11 +113,13 @@ def test_gdal_merge_1(script_path, tmp_path): output_tif = str(tmp_path / "test_gdal_merge_1.tif") - test_py_scripts.run_py_script( + _, err = test_py_scripts.run_py_script( script_path, "gdal_merge", f"-o {output_tif} " + test_py_scripts.get_data_path("gcore") + "byte.tif", + return_stderr=True, ) + assert "UseExceptions" not in err ds = gdal.Open(output_tif) assert ds.GetRasterBand(1).Checksum() == 4672 diff --git a/autotest/pyscripts/test_gdal_pansharpen.py b/autotest/pyscripts/test_gdal_pansharpen.py index d58303bc49c8..160b68879b94 100755 --- a/autotest/pyscripts/test_gdal_pansharpen.py +++ b/autotest/pyscripts/test_gdal_pansharpen.py @@ -99,14 +99,16 @@ def test_gdal_pansharpen_1(script_path, tmp_path, small_world_pan_tif): out_tif = str(tmp_path / "out.tif") - test_py_scripts.run_py_script( + _, err = test_py_scripts.run_py_script( script_path, "gdal_pansharpen", f" {small_world_pan_tif} " + test_py_scripts.get_data_path("gdrivers") + "small_world.tif " + out_tif, + return_stderr=True, ) + assert "UseExceptions" not in err with gdal.Open(out_tif) as ds: cs = [ds.GetRasterBand(i + 1).Checksum() for i in range(ds.RasterCount)] diff --git a/autotest/pyscripts/test_gdal_polygonize.py b/autotest/pyscripts/test_gdal_polygonize.py index e12184d1b653..d14f5f0f8a20 100755 --- a/autotest/pyscripts/test_gdal_polygonize.py +++ b/autotest/pyscripts/test_gdal_polygonize.py @@ -90,11 +90,13 @@ def test_gdal_polygonize_1(script_path, tmp_path): shp_layer.CreateField(fd) # run the algorithm. - test_py_scripts.run_py_script( + _, err = test_py_scripts.run_py_script( script_path, "gdal_polygonize", test_py_scripts.get_data_path("alg") + f"polygonize_in.grd {tmp_path} poly DN", + return_stderr=True, ) + assert "UseExceptions" not in err # Confirm we get the set of expected features in the output layer. diff --git a/autotest/pyscripts/test_gdal_proximity.py b/autotest/pyscripts/test_gdal_proximity.py index f1c51e18f36c..059e84a538a9 100755 --- a/autotest/pyscripts/test_gdal_proximity.py +++ b/autotest/pyscripts/test_gdal_proximity.py @@ -79,11 +79,13 @@ def test_gdal_proximity_1(script_path, tmp_path): dst_ds = drv.Create(output_tif, 25, 25, 1, gdal.GDT_Byte) dst_ds = None - test_py_scripts.run_py_script( + _, err = test_py_scripts.run_py_script( script_path, "gdal_proximity", test_py_scripts.get_data_path("alg") + f"pat.tif {output_tif}", + return_stderr=True, ) + assert "UseExceptions" not in err dst_ds = gdal.Open(output_tif) dst_band = dst_ds.GetRasterBand(1) diff --git a/autotest/pyscripts/test_gdal_retile.py b/autotest/pyscripts/test_gdal_retile.py index aaac7e5e415f..fc7ae087bbc4 100755 --- a/autotest/pyscripts/test_gdal_retile.py +++ b/autotest/pyscripts/test_gdal_retile.py @@ -118,13 +118,15 @@ def test_gdal_retile_2(script_path, tmp_path): out_dir = tmp_path / "outretile2" out_dir.mkdir() - test_py_scripts.run_py_script( + _, err = test_py_scripts.run_py_script( script_path, "gdal_retile", f"-v -levels 2 -r bilinear -targetDir {out_dir} " + test_py_scripts.get_data_path("gcore") + "rgba.tif", + return_stderr=True, ) + assert "UseExceptions" not in err ds = gdal.Open(f"{out_dir}/2/rgba_1_1.tif") assert ds.GetRasterBand(1).Checksum() == 35, "wrong checksum for band 1" diff --git a/autotest/pyscripts/test_gdal_sieve.py b/autotest/pyscripts/test_gdal_sieve.py index a203da5105c1..2e635a457049 100755 --- a/autotest/pyscripts/test_gdal_sieve.py +++ b/autotest/pyscripts/test_gdal_sieve.py @@ -81,13 +81,15 @@ def test_gdal_sieve_1(script_path, tmp_path): dst_ds = drv.Create(test_tif, 5, 7, 1, gdal.GDT_Byte) dst_ds = None - test_py_scripts.run_py_script( + _, err = test_py_scripts.run_py_script( script_path, "gdal_sieve", "-nomask -st 2 -4 " + test_py_scripts.get_data_path("alg") + f"sieve_src.grd {test_tif}", + return_stderr=True, ) + assert "UseExceptions" not in err dst_ds = gdal.Open(test_tif) dst_band = dst_ds.GetRasterBand(1) diff --git a/autotest/pyscripts/test_gdalattachpct.py b/autotest/pyscripts/test_gdalattachpct.py index 58806f5b9bac..d81b173eadc4 100755 --- a/autotest/pyscripts/test_gdalattachpct.py +++ b/autotest/pyscripts/test_gdalattachpct.py @@ -68,11 +68,13 @@ def test_gdalattachpct_basic(script_path, tmp_path, palette_file): out_filename = str(tmp_path / "dst.tif") - test_py_scripts.run_py_script( + _, err = test_py_scripts.run_py_script( script_path, "gdalattachpct", f" {palette_file} {src_filename} {out_filename}", + return_stderr=True, ) + assert "UseExceptions" not in err ds = gdal.Open(out_filename) assert ds.GetDriver().ShortName == "GTiff" diff --git a/autotest/pyscripts/test_gdalcompare.py b/autotest/pyscripts/test_gdalcompare.py index 64e634758e52..904e24ea8edd 100644 --- a/autotest/pyscripts/test_gdalcompare.py +++ b/autotest/pyscripts/test_gdalcompare.py @@ -97,9 +97,13 @@ def test_gdalcompare_same(script_path, tmp_path): source_filename = str(tmp_path / "src.tif") shutil.copy("../gcore/data/byte.tif", source_filename) - ret = test_py_scripts.run_py_script( - script_path, "gdalcompare", f"{source_filename} {source_filename}" + ret, err = test_py_scripts.run_py_script( + script_path, + "gdalcompare", + f"{source_filename} {source_filename}", + return_stderr=True, ) + assert "UseExceptions" not in err assert "Differences Found: 0" in ret diff --git a/autotest/pyscripts/test_gdalmove.py b/autotest/pyscripts/test_gdalmove.py index fb2dabe06435..296ebee3c08d 100755 --- a/autotest/pyscripts/test_gdalmove.py +++ b/autotest/pyscripts/test_gdalmove.py @@ -78,11 +78,13 @@ def test_gdalmove_1(script_path, tmp_path): shutil.copy(test_py_scripts.get_data_path("gcore") + "byte.tif", test_tif) - test_py_scripts.run_py_script( + _, err = test_py_scripts.run_py_script( script_path, "gdalmove", f'-s_srs "+proj=utm +zone=11 +ellps=clrk66 +towgs84=0,0,0 +no_defs" -t_srs EPSG:32611 {test_tif} -et 1', + return_stderr=True, ) + assert "UseExceptions" not in err ds = gdal.Open(test_tif) got_gt = ds.GetGeoTransform() diff --git a/autotest/pyscripts/test_ogr_layer_algebra.py b/autotest/pyscripts/test_ogr_layer_algebra.py index 823471a97066..ca6188b68da0 100644 --- a/autotest/pyscripts/test_ogr_layer_algebra.py +++ b/autotest/pyscripts/test_ogr_layer_algebra.py @@ -110,11 +110,13 @@ def test_ogr_layer_algebra_intersection(script_path, tmp_path): method_layer = None # executing script - test_py_scripts.run_py_script( + _, err = test_py_scripts.run_py_script( script_path, "ogr_layer_algebra", f"Intersection -input_ds {input_path} -output_ds {output_path} -method_ds {method_path}", + return_stderr=True, ) + assert "UseExceptions" not in err driver = ogr.GetDriverByName("ESRI Shapefile") dataSource = driver.Open(output_path, 0) diff --git a/autotest/pyscripts/test_ogrmerge.py b/autotest/pyscripts/test_ogrmerge.py index 6549b6a61f9e..b8f30feabbbf 100755 --- a/autotest/pyscripts/test_ogrmerge.py +++ b/autotest/pyscripts/test_ogrmerge.py @@ -77,7 +77,7 @@ def test_ogrmerge_1(script_path, tmp_path): out_shp = str(tmp_path / "out.shp") - test_py_scripts.run_py_script( + _, err = test_py_scripts.run_py_script( script_path, "ogrmerge", f"-single -o {out_shp} " @@ -85,7 +85,9 @@ def test_ogrmerge_1(script_path, tmp_path): + "poly.shp " + test_py_scripts.get_data_path("ogr") + "poly.shp", + return_stderr=True, ) + assert "UseExceptions" not in err ds = ogr.Open(out_shp) lyr = ds.GetLayer(0) diff --git a/autotest/pyscripts/test_pct.py b/autotest/pyscripts/test_pct.py index 018bbf36f12a..c85ab2c76c93 100755 --- a/autotest/pyscripts/test_pct.py +++ b/autotest/pyscripts/test_pct.py @@ -155,9 +155,10 @@ def test_pct2rgb_1(script_path, tmp_path, rgb2pct1_tif): output_tif = str(tmp_path / "test_pct2rgb_1.tif") - test_py_scripts.run_py_script( - script_path, "pct2rgb", f"{rgb2pct1_tif} {output_tif}" + _, err = test_py_scripts.run_py_script( + script_path, "pct2rgb", f"{rgb2pct1_tif} {output_tif}", return_stderr=True ) + assert "UseExceptions" not in err ds = gdal.Open(output_tif) assert ds.GetRasterBand(1).Checksum() == 20963 @@ -220,13 +221,15 @@ def test_rgb2pct_3(script_path, tmp_path, rgb2pct2_tif): output_tif = str(tmp_path / "test_rgb2pct_3.tif") - test_py_scripts.run_py_script( + _, err = test_py_scripts.run_py_script( script_path, "rgb2pct", f"-pct {rgb2pct2_tif} " + test_py_scripts.get_data_path("gcore") + f"rgbsmall.tif {output_tif}", + return_stderr=True, ) + assert "UseExceptions" not in err ds = gdal.Open(output_tif) assert ds.GetRasterBand(1).Checksum() == 16596