Skip to content

Commit

Permalink
autotest: remove use of deprecate message argument of pytest.raises() (
Browse files Browse the repository at this point in the history
…fixes #1689)
  • Loading branch information
rouault committed Jun 30, 2019
1 parent 825662d commit 94a32bb
Show file tree
Hide file tree
Showing 21 changed files with 82 additions and 211 deletions.
4 changes: 1 addition & 3 deletions autotest/gcore/hfa_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
16 changes: 4 additions & 12 deletions autotest/gcore/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')


###############################################################################
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')


###############################################################################
Expand Down
40 changes: 20 additions & 20 deletions autotest/gcore/numpy_rw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)


Expand Down
3 changes: 1 addition & 2 deletions autotest/gcore/rasterio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 1 addition & 3 deletions autotest/gcore/tiff_ovr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
52 changes: 13 additions & 39 deletions autotest/gcore/tiff_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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')


###############################################################################
Expand Down Expand Up @@ -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')


###############################################################################
Expand Down Expand Up @@ -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')


###############################################################################
Expand Down Expand Up @@ -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')


###############################################################################
Expand Down Expand Up @@ -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')


###############################################################################
Expand Down Expand Up @@ -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')


###############################################################################
Expand Down Expand Up @@ -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')


###############################################################################
Expand Down Expand Up @@ -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')


###############################################################################
Expand Down Expand Up @@ -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')


###############################################################################
Expand Down Expand Up @@ -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')


###############################################################################
Expand Down Expand Up @@ -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')


###############################################################################
Expand Down Expand Up @@ -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')
Expand Down
Loading

0 comments on commit 94a32bb

Please sign in to comment.