|
18 | 18 |
|
19 | 19 | import gdaltest
|
20 | 20 | import pytest
|
| 21 | +from test_py_scripts import run_py_script_as_external_script |
21 | 22 |
|
22 | 23 | from osgeo import gdal, osr
|
23 | 24 |
|
@@ -1126,6 +1127,39 @@ def test_misc_gdal_driver_has_open_option(driver_name, open_option, expected):
|
1126 | 1127 | assert driver.HasOpenOption(open_option) == expected
|
1127 | 1128 |
|
1128 | 1129 |
|
| 1130 | +############################################################################### |
| 1131 | +# Test gdal.quiet_errors() and gdal.quiet_warnings() |
| 1132 | + |
| 1133 | + |
| 1134 | +@pytest.mark.parametrize("context", ("quiet_errors", "quiet_warnings")) |
| 1135 | +def test_misc_quiet_errors(tmp_path, context): |
| 1136 | + |
| 1137 | + script = f""" |
| 1138 | +from osgeo import gdal |
| 1139 | +
|
| 1140 | +with gdal.{context}(): |
| 1141 | + gdal.Error(gdal.CE_Debug, gdal.CPLE_AppDefined, "Debug") |
| 1142 | + gdal.Error(gdal.CE_Warning, gdal.CPLE_AppDefined, "Warning") |
| 1143 | + gdal.Error(gdal.CE_Failure, gdal.CPLE_AppDefined, "Failure") |
| 1144 | +""" |
| 1145 | + |
| 1146 | + with open(tmp_path / "script.py", "w") as f: |
| 1147 | + f.write(script) |
| 1148 | + |
| 1149 | + out, err = run_py_script_as_external_script( |
| 1150 | + tmp_path, "script", "", return_stderr=True |
| 1151 | + ) |
| 1152 | + if context == "quiet_errors": |
| 1153 | + assert "Debug" in err |
| 1154 | + assert "Warning" not in err |
| 1155 | + assert "Failure" not in err |
| 1156 | + |
| 1157 | + if context == "quiet_warnings": |
| 1158 | + assert "Debug" in err |
| 1159 | + assert "Warning" not in err |
| 1160 | + assert "Failure" in err |
| 1161 | + |
| 1162 | + |
1129 | 1163 | ###############################################################################
|
1130 | 1164 |
|
1131 | 1165 |
|
|
0 commit comments