From 94a32bb70a6c6d1c32d33e4ee5c15b39121f522f Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 29 Jun 2019 23:31:46 +0200 Subject: [PATCH] autotest: remove use of deprecate message argument of pytest.raises() (fixes #1689) --- autotest/gcore/hfa_write.py | 4 +- autotest/gcore/mask.py | 16 ++---- autotest/gcore/numpy_rw.py | 40 +++++++------- autotest/gcore/rasterio.py | 3 +- autotest/gcore/tiff_ovr.py | 4 +- autotest/gcore/tiff_read.py | 52 +++++------------- autotest/gcore/tiff_write.py | 64 +++++------------------ autotest/gdrivers/gdalhttp.py | 4 +- autotest/gdrivers/hfa.py | 9 +--- autotest/gdrivers/jp2metadata.py | 4 +- autotest/gdrivers/jpeg.py | 4 +- autotest/gdrivers/til.py | 12 +---- autotest/gdrivers/vrtmask.py | 3 +- autotest/gnm/gnm_test.py | 6 +-- autotest/ogr/ogr_fgdb.py | 34 +++--------- autotest/ogr/ogr_gml_read.py | 8 +-- autotest/ogr/ogr_index_test.py | 8 +-- autotest/ogr/ogr_sql_test.py | 4 +- autotest/utilities/test_gdal_translate.py | 4 +- autotest/utilities/test_gdaladdo.py | 4 +- autotest/utilities/test_gnmutils.py | 6 +-- 21 files changed, 82 insertions(+), 211 deletions(-) diff --git a/autotest/gcore/hfa_write.py b/autotest/gcore/hfa_write.py index 9afcb05fec6d..3c96e23dc7b4 100755 --- a/autotest/gcore/hfa_write.py +++ b/autotest/gcore/hfa_write.py @@ -161,9 +161,7 @@ def test_hfa_clean_external_overviews(): assert ds.GetRasterBand(1).GetOverviewCount() == 0, 'Overviews still exist.' ds = None - with pytest.raises(OSError, message='small.rrd still present.'): - os.stat('tmp/small.rrd') - + assert not os.path.exists('tmp/small.rrd') gdal.GetDriverByName('HFA').Delete('tmp/small.img') diff --git a/autotest/gcore/mask.py b/autotest/gcore/mask.py index 345bc454a299..e1a58d166e00 100755 --- a/autotest/gcore/mask.py +++ b/autotest/gcore/mask.py @@ -417,9 +417,7 @@ def test_mask_13(): drv.Delete('tmp/byte_with_mask.tif') - with pytest.raises(OSError, message='tmp/byte_with_mask.tif.msk is still there'): - os.stat('tmp/byte_with_mask.tif.msk') - + assert not os.path.exists('tmp/byte_with_mask.tif.msk') ############################################################################### @@ -470,9 +468,7 @@ def test_mask_14(): ds = None - with pytest.raises(OSError, message='tmp/byte_with_mask.tif.msk should not exist'): - os.stat('tmp/byte_with_mask.tif.msk') - + assert not os.path.exists('tmp/byte_with_mask.tif.msk') gdal.SetConfigOption('GDAL_TIFF_INTERNAL_MASK_TO_8BIT', 'FALSE') ds = gdal.Open('tmp/byte_with_mask.tif') @@ -556,9 +552,7 @@ def mask_and_ovr(order, method): ds = None - with pytest.raises(OSError, message='tmp/byte_with_mask.tif.msk should not exist'): - os.stat('tmp/byte_with_ovr_and_mask.tif.msk') - + assert not os.path.exists('tmp/byte_with_ovr_and_mask.tif.msk') gdal.SetConfigOption('GDAL_TIFF_INTERNAL_MASK_TO_8BIT', 'FALSE') ds = gdal.Open('tmp/byte_with_ovr_and_mask.tif') @@ -736,9 +730,7 @@ def test_mask_22(): drv.Delete('tmp/mask_22.tif') - with pytest.raises(OSError, message='tmp/mask_22.tif.msk is still there'): - os.stat('tmp/mask_22.tif.msk') - + assert not os.path.exists('tmp/mask_22.tif.msk') ############################################################################### diff --git a/autotest/gcore/numpy_rw.py b/autotest/gcore/numpy_rw.py index a180429fa698..4d45da0729e0 100755 --- a/autotest/gcore/numpy_rw.py +++ b/autotest/gcore/numpy_rw.py @@ -378,39 +378,39 @@ def test_numpy_rw_13(): # Try reading into unsupported array type ar = numpy.empty([1, 2], dtype=numpy.int64) - with pytest.raises(Exception, message='expected "ValueError: array does not have ' - 'corresponding GDAL data type"'): + with pytest.raises(Exception, match='array does not have ' + 'corresponding GDAL data type'): ds.GetRasterBand(1).ReadAsArray(buf_obj=ar) # Try call with inconsistent parameters. ar = numpy.empty([1, 2], dtype=numpy.uint8) - with pytest.raises(Exception, message='expected "Specified buf_ysize not consistent ' - 'with buffer shape"'): + with pytest.raises(Exception, match='Specified buf_ysize not consistent ' + 'with array shape'): ds.GetRasterBand(1).ReadAsArray(buf_obj=ar, buf_xsize=2, buf_ysize=2) # Same with 3 dimensions ar = numpy.empty([1, 1, 2], dtype=numpy.uint8) - with pytest.raises(Exception, message='expected "Specified buf_ysize not consistent ' - 'with buffer shape"'): + with pytest.raises(Exception, match='Specified buf_ysize not consistent ' + 'with array shape'): ds.GetRasterBand(1).ReadAsArray(buf_obj=ar, buf_xsize=2, buf_ysize=2) # Try call with inconsistent parameters. ar = numpy.empty([1, 2], dtype=numpy.uint8) - with pytest.raises(Exception, message='expected "Specified buf_xsize not consistent ' - 'with buffer shape"'): + with pytest.raises(Exception, match='Specified buf_xsize not consistent ' + 'with array shape'): ds.GetRasterBand(1).ReadAsArray(buf_obj=ar, buf_xsize=1, buf_ysize=1) # Inconsistent data type ar = numpy.empty([1, 2], dtype=numpy.uint8) - with pytest.raises(Exception, message='expected "Specified buf_type not consistent ' - 'with array type"'): + with pytest.raises(Exception, match='Specified buf_type not consistent ' + 'with array type'): ds.GetRasterBand(1).ReadAsArray(buf_obj=ar, buf_type=gdal.GDT_Int16) @@ -450,41 +450,41 @@ def test_numpy_rw_13(): ds.GetRasterBand(i + 1).WriteArray(ar[i]) ar = numpy.empty([3, 1, 2], dtype=numpy.int64) - with pytest.raises(Exception, message='expected "ValueError: array does not have ' - 'corresponding GDAL data type"'): + with pytest.raises(Exception, match='array does not have ' + 'corresponding GDAL data type'): ds.ReadAsArray(buf_obj=ar) # Try call with inconsistent parameters. ar = numpy.empty([3, 1, 2], dtype=numpy.uint8) - with pytest.raises(Exception, message='expected "Specified buf_ysize not consistent ' - 'with buffer shape"'): + with pytest.raises(Exception, match='Specified buf_ysize not consistent ' + 'with array shape'): ds.ReadAsArray(buf_obj=ar, buf_xsize=2, buf_ysize=2) # With 2 dimensions ar = numpy.empty([1, 2], dtype=numpy.uint8) - with pytest.raises(Exception, message='expected "ValueError: Array should have 3 ' - 'dimensions"'): + with pytest.raises(Exception, match='Array should have 3 ' + 'dimensions'): ds.ReadAsArray(buf_obj=ar) # Try call with inconsistent parameters ar = numpy.empty([3, 1, 2], dtype=numpy.uint8) - with pytest.raises(Exception, message='expected "Specified buf_xsize not consistent ' - 'with buffer shape"'): + with pytest.raises(Exception, match='Specified buf_xsize not consistent ' + 'with array shape'): ds.ReadAsArray(buf_obj=ar, buf_xsize=1, buf_ysize=1) # Inconsistent data type ar = numpy.empty([3, 1, 2], dtype=numpy.uint8) - with pytest.raises(Exception, message='expected "Specified buf_type not consistent with array type"'): + with pytest.raises(Exception, match='Specified buf_type not consistent with array type'): ds.ReadAsArray(buf_obj=ar, buf_type=gdal.GDT_Int16) # Not enough space in first dimension ar = numpy.empty([2, 1, 2], dtype=numpy.uint8) - with pytest.raises(Exception, message='expected "Array should have space for 3 bands"'): + with pytest.raises(Exception, match='Array should have space for 3 bands'): ds.ReadAsArray(buf_obj=ar) diff --git a/autotest/gcore/rasterio.py b/autotest/gcore/rasterio.py index 5ef8c0f4db2e..d908d4370731 100755 --- a/autotest/gcore/rasterio.py +++ b/autotest/gcore/rasterio.py @@ -247,9 +247,8 @@ def test_rasterio_6(): ds = gdal.GetDriverByName('MEM').Create('', 2, 2) for obj in [ds, ds.GetRasterBand(1)]: - with pytest.raises(Exception, message='expected exception'): + with pytest.raises(Exception): obj.WriteRaster(0, 0, 2, 2, None) - gdal.ErrorReset() gdal.PushErrorHandler('CPLQuietErrorHandler') diff --git a/autotest/gcore/tiff_ovr.py b/autotest/gcore/tiff_ovr.py index 9feb07c0f68d..4f3ddca5a2ba 100755 --- a/autotest/gcore/tiff_ovr.py +++ b/autotest/gcore/tiff_ovr.py @@ -944,9 +944,7 @@ def test_tiff_ovr_29(both_endian): png_ds = None - with pytest.raises(OSError, message='.ovr file still present'): - os.stat('tmp/ovr29.png.ovr') - + assert not os.path.exists('tmp/ovr29.png.ovr') gdal.GetDriverByName('PNG').Delete('tmp/ovr29.png') diff --git a/autotest/gcore/tiff_read.py b/autotest/gcore/tiff_read.py index 44c74499977c..da1310ca94a9 100755 --- a/autotest/gcore/tiff_read.py +++ b/autotest/gcore/tiff_read.py @@ -738,9 +738,7 @@ def test_tiff_read_from_tab(): gdal.GetDriverByName('GTiff').Delete('tmp/tiff_read_from_tab.tif') - with pytest.raises(OSError, message='did not expect to find .tab file at that point'): - os.stat('tmp/tiff_read_from_tab.tab') - + assert not os.path.exists('tmp/tiff_read_from_tab.tab') assert gt == (400000.0, 25.0, 0.0, 1300000.0, 0.0, -25.0), \ 'did not get expected geotransform' @@ -1553,9 +1551,7 @@ def test_tiff_read_md1(): ds = None - with pytest.raises(OSError, message='Expected not generation of data/md_dg.tif.aux.xml'): - os.stat('data/md_dg.tif.aux.xml') - + assert not os.path.exists('data/md_dg.tif.aux.xml') ############################################################################### @@ -1589,9 +1585,7 @@ def test_tiff_read_md2(): ds = None - with pytest.raises(OSError, message='Expected not generation of data/md_dg_2.tif.aux.xml'): - os.stat('data/md_dg_2.tif.aux.xml') - + assert not os.path.exists('data/md_dg_2.tif.aux.xml') ############################################################################### @@ -1625,9 +1619,7 @@ def test_tiff_read_md3(): ds = None - with pytest.raises(OSError, message='Expected not generation of data/md_ge_rgb_0010000.tif.aux.xml'): - os.stat('data/md_ge_rgb_0010000.tif.aux.xml') - + assert not os.path.exists('data/md_ge_rgb_0010000.tif.aux.xml') ############################################################################### @@ -1661,9 +1653,7 @@ def test_tiff_read_md4(): ds = None - with pytest.raises(OSError, message='Expected not generation of data/md_ov.tif.aux.xml'): - os.stat('data/md_ov.tif.aux.xml') - + assert not os.path.exists('data/md_ov.tif.aux.xml') ############################################################################### @@ -1697,9 +1687,7 @@ def test_tiff_read_md5(): ds = None - with pytest.raises(OSError, message='Expected not generation of data/md_rdk1.tif.aux.xml'): - os.stat('data/md_rdk1.tif.aux.xml') - + assert not os.path.exists('data/md_rdk1.tif.aux.xml') ############################################################################### @@ -1733,9 +1721,7 @@ def test_tiff_read_md6(): ds = None - with pytest.raises(OSError, message='Expected not generation of data/md_ls_b1.tif.aux.xml'): - os.stat('data/md_ls_b1.tif.aux.xml') - + assert not os.path.exists('data/md_ls_b1.tif.aux.xml') ############################################################################### @@ -1769,9 +1755,7 @@ def test_tiff_read_md7(): ds = None - with pytest.raises(OSError, message='Expected not generation of data/spot/md_spot.tif.aux.xml'): - os.stat('data/spot/md_spot.tif.aux.xml') - + assert not os.path.exists('data/spot/md_spot.tif.aux.xml') ############################################################################### @@ -1805,9 +1789,7 @@ def test_tiff_read_md8(): ds = None - with pytest.raises(OSError, message='Expected not generation of data/md_re.tif.aux.xml'): - os.stat('data/md_re.tif.aux.xml') - + assert not os.path.exists('data/md_re.tif.aux.xml') ############################################################################### @@ -1840,9 +1822,7 @@ def test_tiff_read_md9(): ds = None - with pytest.raises(OSError, message='Expected not generation of data/alos/IMG-md_alos.tif.aux.xml'): - os.stat('data/alos/IMG-md_alos.tif.aux.xml') - + assert not os.path.exists('data/alos/IMG-md_alos.tif.aux.xml') ############################################################################### @@ -1876,9 +1856,7 @@ def test_tiff_read_md10(): ds = None - with pytest.raises(OSError, message='Expected not generation of data/md_eros.tif.aux.xml'): - os.stat('data/md_eros.tif.aux.xml') - + assert not os.path.exists('data/md_eros.tif.aux.xml') ############################################################################### @@ -1912,9 +1890,7 @@ def test_tiff_read_md11(): ds = None - with pytest.raises(OSError, message='Expected not generation of data/md_kompsat.tif.aux.xml'): - os.stat('data/md_kompsat.tif.aux.xml') - + assert not os.path.exists('data/md_kompsat.tif.aux.xml') ############################################################################### @@ -1947,9 +1923,7 @@ def test_tiff_read_md12(): ds = None - with pytest.raises(OSError, message='Expected not generation of data/md_kompsat.tif.aux.xml'): - os.stat('data/md_kompsat.tif.aux.xml') - + assert not os.path.exists('data/md_kompsat.tif.aux.xml') # Test not valid DIMAP product [https://github.com/OSGeo/gdal/issues/431] shutil.copy('../gdrivers/data/dimap2/IMG_foo_R2C1.TIF', 'tmp/IMG_foo_temp.TIF') diff --git a/autotest/gcore/tiff_write.py b/autotest/gcore/tiff_write.py index 49d86396358b..e290368f4463 100755 --- a/autotest/gcore/tiff_write.py +++ b/autotest/gcore/tiff_write.py @@ -671,14 +671,8 @@ def test_tiff_write_rpc_txt(): pass # confirm there is no .RPB file created by default. - with pytest.raises(IOError, message='unexpectedly found .RPB file'): - open('tmp/tiff_write_rpc_txt.RPB').read() - - - try: - open('tmp/tiff_write_rpc_txt_RPC.TXT').read() - except IOError: - pytest.fail('missing _RPC.TXT file.') + assert not os.path.exists('tmp/tiff_write_rpc_txt.RPB') + assert os.path.exists('tmp/tiff_write_rpc_txt_RPC.TXT') # Open the dataset, and confirm the RPC data is still intact. ds = gdal.Open('tmp/tiff_write_rpc_txt.tif') @@ -691,9 +685,7 @@ def test_tiff_write_rpc_txt(): # Confirm _RPC.TXT file is cleaned up. If not likely the # file list functionality is not working properly. - with pytest.raises(IOError, message='_RPC.TXT did not get cleaned up.'): - open('tmp/tiff_write_rpc_txt_RPC.TXT').read() - + assert not os.path.exists('tmp/tiff_write_rpc_txt_RPC.TXT') ############################################################################### @@ -718,9 +710,7 @@ def test_tiff_write_rpc_in_pam(): pytest.fail('missing .aux.xml file.') # confirm there is no .RPB file created. - with pytest.raises(IOError, message='unexpectedly found .RPB file'): - open('tmp/tiff_write_rpc_txt.RPB').read() - + assert not os.path.exists('tmp/tiff_write_rpc_txt.RPB') # Open the dataset, and confirm the RPC data is still intact. ds = gdal.Open('tmp/tiff_write_rpc_in_pam.tif') @@ -787,9 +777,7 @@ def test_tiff_write_20(): # hopefully it's closed now! - with pytest.raises(OSError, message='did not expected .aux.xml file'): - os.stat('tmp/tags.tif.aux.xml') - + assert not os.path.exists('tmp/tags.tif.aux.xml') new_ds = gdal.Open('tmp/tags.tif') md = new_ds.GetMetadata() @@ -806,9 +794,7 @@ def test_tiff_write_20(): ds.SetMetadataItem('TIFFTAG_SOFTWARE', None) ds = None - with pytest.raises(OSError, message='did not expected .aux.xml file'): - os.stat('tmp/tags.tif.aux.xml') - + assert not os.path.exists('tmp/tags.tif.aux.xml') ds = gdal.Open('tmp/tags.tif') assert ds.GetMetadataItem('TIFFTAG_SOFTWARE') is None, \ @@ -1950,9 +1936,7 @@ def test_tiff_write_60(): ds = None gdaltest.tiff_drv.Delete('tmp/tiff_write_60.tif') - with pytest.raises(OSError, message='%s should have been deleted' % options_tuple[1]): - os.stat(options_tuple[1]) - + assert not os.path.exists(options_tuple[1]) # CreateCopy case src_ds = gdal.Open('data/byte.tif') @@ -1970,9 +1954,7 @@ def test_tiff_write_60(): ds = None gdaltest.tiff_drv.Delete('tmp/tiff_write_60.tif') - with pytest.raises(OSError, message='%s should have been deleted' % options_tuple[1]): - os.stat(options_tuple[1]) - + assert not os.path.exists(options_tuple[1]) ############################################################################### @@ -2591,10 +2573,7 @@ def test_tiff_write_79(): ds.GetProjectionRef() ds.SetMetadataItem('AREA_OR_POINT', 'Point') ds = None - with pytest.raises(OSError, message='got to PAM'): - # check that it doesn't go to PAM - os.stat('tmp/tiff_write_79.tif.aux.xml') - + assert not os.path.exists('tmp/tiff_write_79.tif.aux.xml') # So should get 'Area' ds = gdal.Open('tmp/tiff_write_79.tif') @@ -2615,10 +2594,7 @@ def test_tiff_write_79(): assert mdi == 'Point', \ ('(3) did not get expected value. do_projection_ref = %d, check_just_after = %d' % (do_projection_ref, check_just_after)) ds = None - with pytest.raises(OSError, message='got to PAM'): - # check that it doesn't go to PAM - os.stat('tmp/tiff_write_79.tif.aux.xml') - + assert not os.path.exists('tmp/tiff_write_79.tif.aux.xml') # Now should get 'Point' ds = gdal.Open('tmp/tiff_write_79.tif') @@ -2664,10 +2640,7 @@ def test_tiff_write_80(): ds.GetRasterBand(1).SetOffset(1000) ds = None - with pytest.raises(OSError, message='got to PAM, but not expected...'): - # check that it doesn't go to PAM - os.stat('tmp/tiff_write_80.tif.aux.xml') - + assert not os.path.exists('tmp/tiff_write_80.tif.aux.xml') ds = gdal.Open('tmp/tiff_write_80.tif') scale = ds.GetRasterBand(1).GetScale() @@ -2733,10 +2706,7 @@ def test_tiff_write_80(): ds.GetRasterBand(1).SetOffset(0) ds = None - with pytest.raises(OSError, message='PAM file should be deleted'): - # check that there is no more any PAM file - os.stat('tmp/tiff_write_80_bis.tif.aux.xml') - + assert not os.path.exists('tmp/tiff_write_80_bis.tif.aux.xml') ds = gdal.Open('tmp/tiff_write_80_bis.tif') scale = ds.GetRasterBand(1).GetScale() @@ -2879,10 +2849,7 @@ def test_tiff_write_85(): ds.GetRasterBand(1).SetUnitType('ft') ds = None - with pytest.raises(OSError, message='got to PAM, but not expected...'): - # check that it doesn't go to PAM - os.stat('tmp/tiff_write_85.tif.aux.xml') - + assert not os.path.exists('tmp/tiff_write_85.tif.aux.xml') ds = gdal.Open('tmp/tiff_write_85.tif') unittype = ds.GetRasterBand(1).GetUnitType() @@ -2937,10 +2904,7 @@ def test_tiff_write_85(): ds.GetRasterBand(1).SetUnitType(None) ds = None - with pytest.raises(OSError, message='PAM file should be deleted'): - # check that there is no more any PAM file - os.stat('tmp/tiff_write_85_bis.tif.aux.xml') - + assert not os.path.exists('tmp/tiff_write_85_bis.tif.aux.xml') ds = gdal.Open('tmp/tiff_write_85_bis.tif') unittype = ds.GetRasterBand(1).GetUnitType() diff --git a/autotest/gdrivers/gdalhttp.py b/autotest/gdrivers/gdalhttp.py index e65ae63147e2..e2fbffaf438c 100755 --- a/autotest/gdrivers/gdalhttp.py +++ b/autotest/gdrivers/gdalhttp.py @@ -198,9 +198,9 @@ def test_http_5(): filename = ds.GetDescription() ds = None - with pytest.raises(OSError, message='file %s should have been removed' % filename): + with pytest.raises(OSError): os.stat(filename) - + pytest.fail('file %s should have been removed' % filename) ############################################################################### diff --git a/autotest/gdrivers/hfa.py b/autotest/gdrivers/hfa.py index 59ebc163dce8..6a1741628f88 100755 --- a/autotest/gdrivers/hfa.py +++ b/autotest/gdrivers/hfa.py @@ -406,9 +406,7 @@ def test_hfa_clean_ige(): out_ds = drv.CreateCopy('tmp/igetest.img', src_ds) del out_ds - with pytest.raises(IOError, message='ige file not cleaned up properly.'): - open('tmp/igetest.ige') - + assert not os.path.exists('tmp/igetest.ige') drv.Delete('tmp/igetest.img') @@ -917,11 +915,8 @@ def test_hfa_write_bit2grayscale(): gdal.SetConfigOption('HFA_USE_RRD', 'NO') # as an aside, confirm the .rrd file was deleted. - with pytest.raises(IOError, message='tmp/small1bit.rrd not deleted!'): - open('tmp/small1bit.rrd') - + assert not os.path.exists('tmp/small1bit.rrd') - ############################################################################### # Verify handling of camera model metadata (#2675) diff --git a/autotest/gdrivers/jp2metadata.py b/autotest/gdrivers/jp2metadata.py index f561c7a0f1b3..f0ee510c778b 100755 --- a/autotest/gdrivers/jp2metadata.py +++ b/autotest/gdrivers/jp2metadata.py @@ -84,9 +84,7 @@ def test_jp2metadata_2(): ds = None - with pytest.raises(OSError, message='Expected not generation of data/IMG_md_ple_R1C1.jp2.aux.xml'): - os.stat('data/IMG_md_ple_R1C1.jp2.aux.xml') - + assert not os.path.exists('data/IMG_md_ple_R1C1.jp2.aux.xml') ############################################################################### diff --git a/autotest/gdrivers/jpeg.py b/autotest/gdrivers/jpeg.py index c1fc32699107..dd0d516b0266 100755 --- a/autotest/gdrivers/jpeg.py +++ b/autotest/gdrivers/jpeg.py @@ -152,9 +152,7 @@ def test_jpeg_3(): gdal.GetDriverByName('JPEG').Delete('tmp/byte.jpg') - with pytest.raises(OSError, message='did not expect to find .wld file at that point'): - os.stat('tmp/byte.wld') - + assert not os.path.exists('tmp/byte.wld') ############################################################################### diff --git a/autotest/gdrivers/til.py b/autotest/gdrivers/til.py index 181a16815480..77e0cc11bd7e 100755 --- a/autotest/gdrivers/til.py +++ b/autotest/gdrivers/til.py @@ -33,7 +33,6 @@ import gdaltest from osgeo import gdal -import pytest ############################################################################### # Test a fake TIL dataset @@ -68,10 +67,7 @@ def test_til_2(): ds = None - with pytest.raises(OSError, message='Expected not generation of data/testtil.til.aux.xml'): - os.stat('data/testtil.til.aux.xml') - - + assert not os.path.exists('data/testtil.til.aux.xml') ############################################################################### # Check GetFileList() & XML @@ -97,10 +93,6 @@ def test_til_3(): ds = None - with pytest.raises(OSError, message='Expected not generation of data/testtil.til.aux.xml'): - os.stat('data/testtil.til.aux.xml') - - - + assert not os.path.exists('data/testtil.til.aux.xml') diff --git a/autotest/gdrivers/vrtmask.py b/autotest/gdrivers/vrtmask.py index b1334d370853..6f527fac90b0 100755 --- a/autotest/gdrivers/vrtmask.py +++ b/autotest/gdrivers/vrtmask.py @@ -256,8 +256,9 @@ def test_vrtmask_7(): ds = None os.remove('tmp/vrtmask_7_rgba.tif') - with pytest.raises(OSError, message='did not expect tmp/vrtmask_7_rgba.tif.msk'): + with pytest.raises(OSError): os.remove('tmp/vrtmask_7_rgba.tif.msk') + pytest.fail('did not expect tmp/vrtmask_7_rgba.tif.msk') os.remove('tmp/vrtmask_7_rgbmask.vrt') diff --git a/autotest/gnm/gnm_test.py b/autotest/gnm/gnm_test.py index 3493ff565a54..3942ec78531d 100755 --- a/autotest/gnm/gnm_test.py +++ b/autotest/gnm/gnm_test.py @@ -222,10 +222,6 @@ def test_gnm_delete(): gdal.GetDriverByName('GNMFile').Delete('tmp/test_gnm') - with pytest.raises(OSError, message='Expected delete tmp/test_gnm'): - os.stat('tmp/test_gnm') - - - + assert not os.path.exists('tmp/test_gnm') diff --git a/autotest/ogr/ogr_fgdb.py b/autotest/ogr/ogr_fgdb.py index fa518ae68fad..2f49cbaca890 100755 --- a/autotest/ogr/ogr_fgdb.py +++ b/autotest/ogr/ogr_fgdb.py @@ -400,9 +400,7 @@ def test_ogr_fgdb_5(): assert ogrtest.fgdb_drv.DeleteDataSource("tmp/test.gdb") == 0, \ 'DeleteDataSource() failed' - with pytest.raises(OSError, message="tmp/test.gdb still existing"): - os.stat("tmp/test.gdb") - + assert not os.path.exists("tmp/test.gdb") ############################################################################### @@ -1097,12 +1095,8 @@ def test_ogr_fgdb_19(): assert ds.StartTransaction(force=True) == 0 - try: - os.stat('tmp/test.gdb.ogredited') - except OSError: - pytest.fail() - with pytest.raises(OSError): - os.stat('tmp/test.gdb.ogrtmp') + assert os.path.exists('tmp/test.gdb.ogredited') + assert not os.path.exists('tmp/test.gdb.ogrtmp') ret = lyr.CreateField(ogr.FieldDefn('foobar', ogr.OFTString)) @@ -1167,13 +1161,8 @@ def test_ogr_fgdb_19(): # Test that CommitTransaction() works assert ds.CommitTransaction() == 0 - with pytest.raises(OSError): - os.stat('tmp/test.gdb.ogredited') - - - with pytest.raises(OSError): - os.stat('tmp/test.gdb.ogrtmp') - + assert not os.path.exists('tmp/test.gdb.ogredited') + assert not os.path.exists('tmp/test.gdb.ogrtmp') lst = gdal.ReadDir('tmp/test.gdb') for filename in lst: @@ -1216,13 +1205,8 @@ def test_ogr_fgdb_19(): assert ds.RollbackTransaction() == 0 - with pytest.raises(OSError): - os.stat('tmp/test.gdb.ogredited') - - - with pytest.raises(OSError): - os.stat('tmp/test.gdb.ogrtmp') - + assert not os.path.exists('tmp/test.gdb.ogredited') + assert not os.path.exists('tmp/test.gdb.ogrtmp') assert lyr.GetFeatureCount() == old_count @@ -1421,9 +1405,7 @@ def test_ogr_fgdb_19(): ds = None if case == 'CASE4': - with pytest.raises(OSError, message=case): - os.stat('tmp/test.gdb.ogredited') - + assert not os.path.exists('tmp/test.gdb.ogredited'), case else: shutil.rmtree('tmp/test.gdb.ogredited') diff --git a/autotest/ogr/ogr_gml_read.py b/autotest/ogr/ogr_gml_read.py index 9bae9f3d6e8a..a455a39eb18a 100755 --- a/autotest/ogr/ogr_gml_read.py +++ b/autotest/ogr/ogr_gml_read.py @@ -1206,9 +1206,7 @@ def test_ogr_gml_35(): ds = ogr.Open('tmp/GmlTopo-sample.xml') gdal.SetConfigOption('GML_SKIP_RESOLVE_ELEMS', None) - with pytest.raises(OSError, message='did not expect tmp/GmlTopo-sample.sqlite'): - os.stat('tmp/GmlTopo-sample.sqlite') - + assert not os.path.exists('tmp/GmlTopo-sample.sqlite') assert gdal.GetLastErrorMsg() == '', 'did not expect error' assert ds.GetLayerCount() == 3, ('expected 3 layers, got %d' % ds.GetLayerCount()) @@ -1321,9 +1319,7 @@ def test_ogr_gml_38(resolver='HUGE'): gdal.SetConfigOption('GML_FACE_HOLE_NEGATIVE', None) if resolver == 'HUGE': - with pytest.raises(OSError, message='did not expect tmp/sample_gml_face_hole_negative_no.sqlite'): - os.stat('tmp/sample_gml_face_hole_negative_no.sqlite') - + assert not os.path.exists('tmp/sample_gml_face_hole_negative_no.sqlite') assert gdal.GetLastErrorMsg() == '', 'did not expect error' diff --git a/autotest/ogr/ogr_index_test.py b/autotest/ogr/ogr_index_test.py index 6e10fb5acefc..afca08899631 100755 --- a/autotest/ogr/ogr_index_test.py +++ b/autotest/ogr/ogr_index_test.py @@ -222,9 +222,7 @@ def test_ogr_index_9(): # After dataset closing, check that the index files do not exist after # dropping the index for filename in ['join_t.idm', 'join_t.ind']: - with pytest.raises(OSError, message="%s should not exist" % filename): - os.stat(filename) - + assert not os.path.exists(filename) # Re-create an index gdaltest.s_ds = ogr.OpenShared('join_t.dbf', update=1) @@ -429,9 +427,7 @@ def test_ogr_index_cleanup(): ogr.GetDriverByName('ESRI Shapefile').DeleteDataSource('join_t.dbf') for filename in ['join_t.idm', 'join_t.ind']: - with pytest.raises(OSError, message="%s should not exist" % filename): - os.stat(filename) - + assert not os.path.exists(filename) ogr.GetDriverByName('ESRI Shapefile').DeleteDataSource( 'tmp/ogr_index_10.shp') diff --git a/autotest/ogr/ogr_sql_test.py b/autotest/ogr/ogr_sql_test.py index 74770874f31f..d8c8ebefa11b 100755 --- a/autotest/ogr/ogr_sql_test.py +++ b/autotest/ogr/ogr_sql_test.py @@ -627,9 +627,9 @@ def test_ogr_sql_28(): field_defn = ogr.FieldDefn("strfield2", ogr.OFTString) lyr.CreateField(field_defn) - with pytest.raises(Exception, message='expected error on NULL query'): + with pytest.raises(Exception): sql_lyr = ds.ExecuteSQL(None) - + pytest.fail('expected exception on NULL query') queries = [ '', diff --git a/autotest/utilities/test_gdal_translate.py b/autotest/utilities/test_gdal_translate.py index d2b89e8c5a8a..4cb4b3793ea9 100755 --- a/autotest/utilities/test_gdal_translate.py +++ b/autotest/utilities/test_gdal_translate.py @@ -501,9 +501,7 @@ def test_gdal_translate_23(): assert md['STATISTICS_MINIMUM'] == '74', 'STATISTICS_MINIMUM is wrong.' - with pytest.raises(OSError, message='did not expect .aux.xml file presence'): - os.stat('tmp/test_gdal_translate_23.tif.aux.xml') - + assert not os.path.exists('tmp/test_gdal_translate_23.tif.aux.xml') gdal.Unlink('../gcore/data/byte.tif.aux.xml') diff --git a/autotest/utilities/test_gdaladdo.py b/autotest/utilities/test_gdaladdo.py index 70de99ce1eab..2c00e9a2f176 100755 --- a/autotest/utilities/test_gdaladdo.py +++ b/autotest/utilities/test_gdaladdo.py @@ -126,9 +126,7 @@ def test_gdaladdo_4(): assert cnt == 0, 'did not clean overviews.' - with pytest.raises(OSError, message='.ovr file still exists'): - os.stat('tmp/test_gdaladdo_3.tif.ovr') - + assert not os.path.exists('tmp/test_gdaladdo_3.tif.ovr') os.remove('tmp/test_gdaladdo_3.tif') diff --git a/autotest/utilities/test_gnmutils.py b/autotest/utilities/test_gnmutils.py index f02212bfda82..6621ef27280b 100755 --- a/autotest/utilities/test_gnmutils.py +++ b/autotest/utilities/test_gnmutils.py @@ -138,11 +138,7 @@ def test_gnm_cleanup(): (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gnmmanage_path() + ' delete tmp/test_gnm') assert (err is None or err == ''), 'got error/warning' - with pytest.raises(OSError, message='Expected delete tmp/test_gnm'): - os.stat('tmp/test_gnm') - - - + assert not os.path.exists('tmp/test_gnm')