Force DeprecationWarning's to be visible.

This commit is contained in:
Kevin Wurster 2016-06-19 22:13:24 -04:00
parent ef952def3b
commit e7350746ee
3 changed files with 22 additions and 12 deletions

View File

@ -12,8 +12,6 @@ except ImportError: # pragma: no cover
def emit(self, record):
pass
import affine
from rasterio._base import (
eval_window, window_shape, window_index, gdal_version)
from rasterio.dtypes import (
@ -164,12 +162,14 @@ def open(path, mode='r', driver=None, width=None, height=None,
raise ValueError("The 'affine' and 'transform' arguments are exclusive")
elif 'affine' in kwargs:
transform = kwargs.pop('affine')
warnings.warn(
"The affine kwarg is deprecated as of 1.0 and only exists to ease "
"the transition. Please switch to the transform kwarg. See "
"https://github.com/mapbox/rasterio/issues/86 for details.",
RuntimeWarning,
stacklevel=2)
with warnings.catch_warnings():
warnings.simplefilter('always')
warnings.warn(
"The affine kwarg is deprecated as of 1.0 and only exists to "
"ease the transition. Please switch to the transform kwarg. "
"See https://github.com/mapbox/rasterio/issues/86 for details.",
DeprecationWarning,
stacklevel=2)
if transform is not None:
transform = guard_transform(transform)

View File

@ -560,11 +560,13 @@ cdef class DatasetReader(object):
"""
def __get__(self):
warnings.warn(
with warnings.catch_warnings():
warnings.simplefilter('always')
warnings.warn(
"'src.affine' is deprecated. Please switch to "
"'src.transform'. See "
"https://github.com/mapbox/rasterio/issues/86 for details.",
RuntimeWarning,
DeprecationWarning,
stacklevel=2)
return Affine.from_gdal(*self.get_transform())

View File

@ -27,8 +27,9 @@ def test_open_transform_not_Affine(path_rgb_byte_tif):
pass
def test_affine_warning(path_rgb_byte_tif):
with pytest.warns(RuntimeWarning):
def test_open_affine_kwarg_warning(path_rgb_byte_tif):
"""Passing the 'affine' kwarg to rasterio.open() should raise a warning."""
with pytest.warns(DeprecationWarning):
with rasterio.open(
path_rgb_byte_tif,
affine=affine.Affine.identity()) as src:
@ -41,3 +42,10 @@ def test_guard_transform_gdal_exception(path_rgb_byte_tif):
transform = src.transform
with pytest.raises(ValueError):
guard_transform(transform.to_gdal())
def test_src_affine_warning(path_rgb_byte_tif):
"""Calling src.affine should raise a warning."""
with pytest.warns(DeprecationWarning):
with rasterio.open(path_rgb_byte_tif) as src:
src.affine