[rasterio] 01/04: Imported Upstream version 0.34.0
Sebastiaan Couwenberg
sebastic at moszumanska.debian.org
Tue Apr 5 18:05:43 UTC 2016
This is an automated email from the git hooks/post-receive script.
sebastic pushed a commit to branch master
in repository rasterio.
commit 11f4a62f6fa0ca5a4268d27e7c2668a022e64e85
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date: Tue Apr 5 07:36:50 2016 +0200
Imported Upstream version 0.34.0
---
.travis.yml | 10 ++--
CHANGES.txt | 7 +++
docs/features.rst | 6 +++
docs/reading.rst | 2 +-
rasterio/__init__.py | 11 +++--
rasterio/_base.pyx | 13 +++++
rasterio/_drivers.pyx | 5 ++
rasterio/_gdal.pxd | 4 ++
rasterio/aws.py | 4 +-
rasterio/rio/bounds.py | 5 +-
rasterio/rio/clip.py | 5 +-
rasterio/rio/insp.py | 3 +-
rasterio/rio/main.py | 10 +++-
rasterio/rio/sample.py | 9 ++--
rasterio/rio/shapes.py | 3 +-
scripts/travis_gdal_install.sh | 3 --
setup.py | 3 +-
tests/test_aws.py | 108 +++++++++++++++++++++++++++++++++--------
tests/test_colorinterp.py | 17 -------
tests/test_deprecations.py | 41 ++++++++++------
tests/test_rio_convert.py | 29 +++++------
tests/test_rio_main.py | 26 ++++++++++
22 files changed, 225 insertions(+), 99 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index d3c796e..341675c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,8 +10,8 @@ env:
- PIP_FIND_LINKS=file://$HOME/.cache/pip/wheels
- GDALINST=$HOME/gdalinstall
- GDALBUILD=$HOME/gdalbuild
- - secure: "Wp1x31bAV//2BF3yJeZKRtit5sAqmULgoTmTH825A+8Frgqb3k9tYf6OR/nP61q9Q84BI2ODqkSRd+EPTgz0hzQIHtDdnOEs4aFefE91dsFRml6LpyhJtoC1cAj45GySS/H8/qME2lby+OvBYceGdQAuaXWHjOT2cdhNqULxQOg="
- - secure: "qAvCpDLYDiMdHhd8l6PZaukogRKFregFm2JG3aWatiOwNPA7qmp+O7Ac2Z0SsQdXxk7LNw6cVKyuRaiyXbWkAIGt2858a1eRJK++kssZ9NXnIGz5WvYeoVQutYMJU/CBCAgSxzpFo56JJg0CK4xizHU8AyDpi72UTDKAOdpCKd8="
+ - secure: "g2h6k0oCsLnYVor3qYSUdLVbifvkkbVqrsiYZ3NZpZKYUc2bveUuCRdqVIU5oGmoOFh8rI1thmtu5QKbbtloP779uI+N4RSBBrp+UmiAryb7wnBFCVAEUrWAKrYOWjcVm5y0ShEIHwtFLsarWoU14WXVZo7rSaAQ03oTke6KvC0="
+ - secure: "XV9rt4WOIO9eZfpy1yuXQv93IDj1rrIn+d/WM0QRn7D6vBeVyahmowvMlJDzpeQqiY7FC5AC/K9OM/lGHFmu9Y0nzMf80GA3Gd543vYKYtxGLFWqggKH1Kw+s65nTikS2seZMzk6j976UcgnBRdjqwuKdk/aqTOGFiYqS8Zs6SE="
matrix:
- GDALVERSION="1.9.2"
- GDALVERSION="1.10.0" # doesn't exist but path/lib will fall back to system
@@ -45,8 +45,10 @@ install:
- "pip install -r requirements-dev.txt"
- "pip install --upgrade --force-reinstall --global-option=build_ext --global-option='-I$GDALINST/gdal-$GDALVERSION/include' --global-option='-L$GDALINST/gdal-$GDALVERSION/lib' --global-option='-R$GDALINST/gdal-$GDALVERSION/lib' -e ."
- "pip install coveralls>=1.1"
- - "pip install -e .[s3]"
+ - "pip install -e .[test]"
+ - "rio --version"
+ - "rio --gdal-version"
script:
- py.test --cov rasterio --cov-report term-missing
after_success:
- - coveralls
+ - coveralls || echo "!! intermittent coveralls failure"
diff --git a/CHANGES.txt b/CHANGES.txt
index 6a97bb3..4e1f459 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,13 @@
Changes
=======
+0.34.0 (2016-04-04)
+-------------------
+
+- Bug fix: S3 support was found missing in several of the CLI commands
+ mentioned below. This is corrected in 0.34 and we have the tests to prove it
+ (#633).
+
0.33.0 (2016-04-01)
-------------------
diff --git a/docs/features.rst b/docs/features.rst
index a1adaf3..da05e29 100644
--- a/docs/features.rst
+++ b/docs/features.rst
@@ -61,6 +61,12 @@ intersecting with geometries.
((g, 255) for g, v in shapes),
out_shape=src.shape)
+By default, only pixels whose center is within the polygon or that
+are selected by Bresenham's line algorithm will be burned in.
+You can specify ``all_touched=True`` to burn in all pixels touched by the geometry.
+The geometries will be rasterized by the "painter's algorithm" -
+geometries are handled in order and subsequent geometries will overwrite previous values.
+
Again, to burn in georeferenced shapes, pass an appropriate transform for the
image to be created.
diff --git a/docs/reading.rst b/docs/reading.rst
index 2eab628..c39aaaa 100644
--- a/docs/reading.rst
+++ b/docs/reading.rst
@@ -46,7 +46,7 @@ thing as ``open()``, raising an exception immediately.
>>> rasterio.open('/lol/wut.tif')
Traceback (most recent call last):
...
- IOError: No such file or directory
+ RasterioIOError: No such file or directory
Datasets generally have one or more bands (or layers). Following the GDAL
convention, these are indexed starting with the number 1. The first band of
diff --git a/rasterio/__init__.py b/rasterio/__init__.py
index 76eff68..419e53f 100644
--- a/rasterio/__init__.py
+++ b/rasterio/__init__.py
@@ -4,9 +4,9 @@ from __future__ import absolute_import
from collections import namedtuple
import logging
-from rasterio._base import eval_window, window_shape, window_index
+from rasterio._base import (
+ eval_window, window_shape, window_index, gdal_version)
from rasterio._drivers import driver_count, GDALEnv
-import rasterio.dtypes
from rasterio.dtypes import (
bool_, ubyte, uint8, uint16, int16, uint32, int32, float32, float64,
complex_)
@@ -23,7 +23,8 @@ from rasterio import _err, coords, enums, vfs
__all__ = [
'band', 'open', 'drivers', 'copy', 'pad']
-__version__ = "0.33.0"
+__version__ = "0.34.0"
+__gdal_version__ = gdal_version()
log = logging.getLogger('rasterio')
class NullHandler(logging.Handler):
@@ -277,8 +278,8 @@ def pad(array, transform, pad_width, mode=None, **kwargs):
transform = guard_transform(transform)
padded_array = numpy.pad(array, pad_width, mode, **kwargs)
padded_trans = list(transform)
- padded_trans[2] -= pad_width*padded_trans[0]
- padded_trans[5] -= pad_width*padded_trans[4]
+ padded_trans[2] -= pad_width * padded_trans[0]
+ padded_trans[5] -= pad_width * padded_trans[4]
return padded_array, Affine(*padded_trans[:6])
diff --git a/rasterio/_base.pyx b/rasterio/_base.pyx
index 1bafb72..2b9fcda 100644
--- a/rasterio/_base.pyx
+++ b/rasterio/_base.pyx
@@ -37,6 +37,19 @@ else:
log.addHandler(NullHandler())
+def check_gdal_version(major, minor):
+ """Return True if the major and minor versions match."""
+ return bool(_gdal.GDALCheckVersion(int(major), int(minor), NULL))
+
+
+def gdal_version():
+ """Return the version as a major.minor.patchlevel string."""
+ cdef const char *ver_c = NULL
+ ver_c = _gdal.GDALVersionInfo("RELEASE_NAME")
+ ver_b = ver_c
+ return ver_b.decode('utf-8')
+
+
cdef class DatasetReader(object):
def __init__(self, path, options=None):
diff --git a/rasterio/_drivers.pyx b/rasterio/_drivers.pyx
index ada694e..c28703a 100644
--- a/rasterio/_drivers.pyx
+++ b/rasterio/_drivers.pyx
@@ -110,6 +110,11 @@ cdef class ConfigEnv(object):
val_b = ('ON' if val else 'OFF').encode('utf-8')
val_c = val_b
CPLSetConfigOption(key_c, val_c)
+
+ # Redact AWS credentials.
+ if key in ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY',
+ 'AWS_SESSION_TOKEN', 'AWS_REGION']:
+ val = '******'
log.debug("Option %s=%s", key, val)
def exit_config_options(self):
diff --git a/rasterio/_gdal.pxd b/rasterio/_gdal.pxd
index 3b21e6b..93eb83e 100644
--- a/rasterio/_gdal.pxd
+++ b/rasterio/_gdal.pxd
@@ -134,6 +134,10 @@ cdef extern from "gdal.h" nogil:
int GDALGetOverviewCount (void *hBand)
int GDALBuildOverviews (void *hDS, const char *resampling, int nOverviews, int *overviews, int nBands, int *bands, void *progress_func, void *progress_data)
+ int GDALCheckVersion(int nVersionMajor, int nVersionMinor, const char *pszCallingComponentName)
+ const char* GDALVersionInfo (const char *pszRequest)
+
+
cdef extern from "gdalwarper.h":
ctypedef enum GDALResampleAlg:
diff --git a/rasterio/aws.py b/rasterio/aws.py
index e933101..111064e 100644
--- a/rasterio/aws.py
+++ b/rasterio/aws.py
@@ -17,12 +17,10 @@ or by calling ``rasterio.open()`` from within a session block
...
"""
-import os
-
import boto3
from rasterio._drivers import ConfigEnv
-from rasterio.five import configparser, string_types
+from rasterio.five import string_types
class Session(ConfigEnv):
diff --git a/rasterio/rio/bounds.py b/rasterio/rio/bounds.py
index 4b5466d..ab1f34a 100644
--- a/rasterio/rio/bounds.py
+++ b/rasterio/rio/bounds.py
@@ -19,7 +19,7 @@ logger = logging.getLogger('rio')
@click.command(short_help="Write bounding boxes to stdout as GeoJSON.")
# One or more files, the bounds of each are a feature in the collection
# object or feature sequence.
- at click.argument('INPUT', nargs=-1, type=click.Path(exists=True), required=True)
+ at click.argument('INPUT', nargs=-1, type=click.Path(), required=True)
@precision_opt
@indent_opt
@compact_opt
@@ -47,6 +47,7 @@ def bounds(ctx, input, precision, indent, compact, projection, dst_crs,
"""
import rasterio.warp
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
+ aws_session = (ctx.obj and ctx.obj.get('aws_session'))
logger = logging.getLogger('rio')
dump_kwds = {'sort_keys': True}
if indent:
@@ -108,7 +109,7 @@ def bounds(ctx, input, precision, indent, compact, projection, dst_crs,
# Use the generator defined above as input to the generic output
# writing function.
try:
- with rasterio.drivers(CPL_DEBUG=verbosity > 2):
+ with rasterio.drivers(CPL_DEBUG=verbosity > 2), aws_session:
write_features(
stdout, col, sequence=sequence,
geojson_type=geojson_type, use_rs=use_rs,
diff --git a/rasterio/rio/clip.py b/rasterio/rio/clip.py
index 843609f..1717bae 100644
--- a/rasterio/rio/clip.py
+++ b/rasterio/rio/clip.py
@@ -14,7 +14,7 @@ from rasterio.coords import disjoint_bounds
@click.argument(
'files',
nargs=-1,
- type=click.Path(resolve_path=True),
+ type=click.Path(),
required=True,
metavar="INPUT OUTPUT")
@options.output_opt
@@ -54,8 +54,9 @@ def clip(
from rasterio.warp import transform_bounds
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
+ aws_session = (ctx.obj and ctx.obj.get('aws_session'))
- with rasterio.drivers(CPL_DEBUG=verbosity > 2):
+ with rasterio.drivers(CPL_DEBUG=verbosity > 2), aws_session:
output, files = resolve_inout(files=files, output=output)
input = files[0]
diff --git a/rasterio/rio/insp.py b/rasterio/rio/insp.py
index 16c40c6..514ccc6 100644
--- a/rasterio/rio/insp.py
+++ b/rasterio/rio/insp.py
@@ -77,9 +77,10 @@ def insp(ctx, input, mode, interpreter):
""" Open the input file in a Python interpreter.
"""
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
+ aws_session = (ctx.obj and ctx.obj.get('aws_session'))
logger = logging.getLogger('rio')
try:
- with rasterio.drivers(CPL_DEBUG=verbosity > 2):
+ with rasterio.drivers(CPL_DEBUG=verbosity > 2), aws_session:
with rasterio.open(input, mode) as src:
main(
'Rasterio %s Interactive Inspector (Python %s)\n'
diff --git a/rasterio/rio/main.py b/rasterio/rio/main.py
index 5fc4cfe..f173194 100644
--- a/rasterio/rio/main.py
+++ b/rasterio/rio/main.py
@@ -43,6 +43,13 @@ def get_aws_session(profile_name):
return FakeSession()
+def gdal_version_cb(ctx, param, value):
+ if not value or ctx.resilient_parsing:
+ return
+ click.echo("{0}".format(rasterio.__gdal_version__), color=ctx.color)
+ ctx.exit()
+
+
@with_plugins(ep for ep in list(iter_entry_points('rasterio.rio_commands')) +
list(iter_entry_points('rasterio.rio_plugins')))
@click.group()
@@ -50,8 +57,9 @@ def get_aws_session(profile_name):
@cligj.quiet_opt
@click.option('--aws-profile', help="Use a specific profile from your shared AWS credentials file")
@click.version_option(version=rasterio.__version__, message='%(version)s')
+ at click.option('--gdal-version', is_eager=True, is_flag=True, callback=gdal_version_cb)
@click.pass_context
-def main_group(ctx, verbose, quiet, aws_profile):
+def main_group(ctx, verbose, quiet, aws_profile, gdal_version):
"""
Rasterio command line interface.
diff --git a/rasterio/rio/sample.py b/rasterio/rio/sample.py
index 8a96b15..5ba0ea8 100644
--- a/rasterio/rio/sample.py
+++ b/rasterio/rio/sample.py
@@ -53,7 +53,7 @@ def sample(ctx, files, bidx):
"""
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
- aws_session = ctx.obj.get('aws_session')
+ aws_session = (ctx.obj and ctx.obj.get('aws_session'))
logger = logging.getLogger('rio')
files = list(files)
@@ -67,7 +67,7 @@ def sample(ctx, files, bidx):
points = [input]
try:
- with rasterio.drivers(CPL_DEBUG=verbosity>2), aws_session:
+ with rasterio.drivers(CPL_DEBUG=verbosity > 2), aws_session:
with rasterio.open(source) as src:
if bidx is None:
indexes = src.indexes
@@ -76,12 +76,11 @@ def sample(ctx, files, bidx):
lambda x: int(x) if x else None, bidx.split('..'))
if start is None:
start = 1
- indexes = src.indexes[slice(start-1, stop)]
+ indexes = src.indexes[slice(start - 1, stop)]
else:
indexes = list(map(int, bidx.split(',')))
for vals in src.sample(
- (json.loads(line) for line in points),
- indexes=indexes):
+ (json.loads(line) for line in points), indexes=indexes):
click.echo(json.dumps(vals.tolist()))
except Exception:
diff --git a/rasterio/rio/shapes.py b/rasterio/rio/shapes.py
index 45827b3..beec86f 100644
--- a/rasterio/rio/shapes.py
+++ b/rasterio/rio/shapes.py
@@ -92,6 +92,7 @@ def shapes(
import rasterio.warp
verbosity = ctx.obj['verbosity'] if ctx.obj else 1
+ aws_session = (ctx.obj and ctx.obj.get('aws_session'))
logger = logging.getLogger('rio')
dump_kwds = {'sort_keys': True}
if indent:
@@ -218,7 +219,7 @@ def shapes(
geojson_type = 'collection'
try:
- with rasterio.drivers(CPL_DEBUG=(verbosity > 2)):
+ with rasterio.drivers(CPL_DEBUG=(verbosity > 2)), aws_session:
write_features(
stdout, Collection(), sequence=sequence,
geojson_type=geojson_type, use_rs=use_rs,
diff --git a/scripts/travis_gdal_install.sh b/scripts/travis_gdal_install.sh
index a7791e6..1e289b3 100644
--- a/scripts/travis_gdal_install.sh
+++ b/scripts/travis_gdal_install.sh
@@ -91,9 +91,6 @@ fi
if [ ! -d $GDALINST/gdal-2.1.0 ]; then
cd $GDALBUILD
- #
- # TODO Use official release, for now use a copy of GDAL daily from mar 28
- #
wget http://download.osgeo.org/gdal/2.1.0beta1/gdal-2.1.0beta1.tar.gz
tar -xzf gdal-2.1.0beta1.tar.gz
cd gdal-2.1.0beta1
diff --git a/setup.py b/setup.py
index 9427592..c90a773 100755
--- a/setup.py
+++ b/setup.py
@@ -263,7 +263,8 @@ setup_args = dict(
install_requires=inst_reqs,
extras_require={
'ipython': ['ipython>=2.0'],
- 's3': ['boto3']})
+ 's3': ['boto3'],
+ 'test': ['boto3', 'packaging']})
if os.environ.get('PACKAGE_DATA'):
setup_args['package_data'] = {'rasterio': ['gdal_data/*', 'proj_data/*']}
diff --git a/tests/test_aws.py b/tests/test_aws.py
index 6dbed62..42a8efb 100644
--- a/tests/test_aws.py
+++ b/tests/test_aws.py
@@ -1,20 +1,35 @@
+# Tests requiring S3 credentials.
+# Collected here to make them easier to skip/xfail.
+
import logging
-import os
import sys
+from packaging.version import parse
import pytest
import rasterio
from rasterio.aws import Session
+from rasterio.rio.main import main_group
+
+
+# Custom markers.
+mingdalversion = pytest.mark.skipif(
+ parse(rasterio.__gdal_version__) < parse('2.1.0dev'),
+ reason="S3 raster access requires GDAL 2.1")
+
+credentials = pytest.mark.skipif(
+ not(Session()._creds), reason="S3 raster access requires credentials")
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
+L8TIF = "s3://landsat-pds/L8/139/045/LC81390452014295LGN00/LC81390452014295LGN00_B1.TIF"
+
def test_session():
"""Create a session with arguments."""
s = Session(aws_access_key_id='id', aws_secret_access_key='key',
- aws_session_token='token', region_name='null-island-1')
+ aws_session_token='token', region_name='null-island-1')
assert s._creds.access_key == 'id'
assert s._creds.secret_key == 'key'
assert s._creds.token == 'token'
@@ -33,37 +48,88 @@ def test_session_env(monkeypatch):
monkeypatch.undo()
- at pytest.mark.xfail(
- (not(os.environ.get('GDALVERSION', '2.1').startswith('2.1')) or
- 'AWS_ACCESS_KEY_ID' not in os.environ or
- 'AWS_SECRET_ACCESS_KEY' not in os.environ),
- reason="S3 raster access requires GDAL 2.1")
+ at mingdalversion
+ at credentials
def test_with_session():
"""Enter and exit a session."""
- with Session() as s:
- with rasterio.open("s3://landsat-pds/L8/139/045/LC81390452014295LGN00/LC81390452014295LGN00_B1.TIF") as f:
+ with Session():
+ with rasterio.open(L8TIF) as f:
assert f.count == 1
- at pytest.mark.xfail(
- (not(os.environ.get('GDALVERSION', '2.1').startswith('2.1')) or
- 'AWS_ACCESS_KEY_ID' not in os.environ or
- 'AWS_SECRET_ACCESS_KEY' not in os.environ),
- reason="S3 raster access requires GDAL 2.1")
+ at mingdalversion
+ at credentials
def test_open_with_session():
"""Enter and exit a session."""
s = Session()
- with s.open("s3://landsat-pds/L8/139/045/LC81390452014295LGN00/LC81390452014295LGN00_B1.TIF") as f:
+ with s.open(L8TIF) as f:
assert f.count == 1
- at pytest.mark.xfail(
- (not(os.environ.get('GDALVERSION', '2.1').startswith('2.1')) or
- 'AWS_ACCESS_KEY_ID' not in os.environ or
- 'AWS_SECRET_ACCESS_KEY' not in os.environ),
- reason="S3 raster access requires GDAL 2.1")
+ at mingdalversion
+ at credentials
def test_open_with_session_minus_mode():
"""Enter and exit a session, reading in 'r-' mode"""
s = Session()
- with s.open("s3://landsat-pds/L8/139/045/LC81390452014295LGN00/LC81390452014295LGN00_B1.TIF", 'r-') as f:
+ with s.open(L8TIF, 'r-') as f:
assert f.count == 1
+
+
+# CLI tests.
+
+ at mingdalversion
+ at credentials
+def test_rio_info(runner):
+ """S3 is supported by rio-info"""
+ result = runner.invoke(main_group, ['info', L8TIF])
+ assert result.exit_code == 0
+ assert '"crs": "EPSG:32645"' in result.output
+
+
+ at mingdalversion
+ at credentials
+def test_rio_insp(runner):
+ """S3 is supported by rio-insp"""
+ result = runner.invoke(main_group, ['insp', L8TIF])
+ assert result.exit_code == 0
+ assert 'Interactive Inspector' in result.output
+
+
+ at mingdalversion
+ at credentials
+def test_rio_bounds(runner):
+ """S3 is supported by rio-bounds"""
+ result = runner.invoke(main_group, ['bounds', '--bbox', L8TIF])
+ assert result.exit_code == 0
+ assert '[85.8' in result.output
+
+
+ at mingdalversion
+ at credentials
+def test_rio_shapes(runner):
+ """S3 is supported by rio-shapes"""
+ result = runner.invoke(
+ main_group, ['shapes', '--as-mask', '--sampling', '16', L8TIF])
+ assert result.exit_code == 0
+ assert 'FeatureCollection' in result.output
+
+
+ at mingdalversion
+ at credentials
+def test_rio_sample(runner):
+ """S3 is supported by rio-sample"""
+ result = runner.invoke(
+ main_group, ['sample', L8TIF], input="[420000, 2350000]")
+ assert result.exit_code == 0
+ assert '[10680]' in result.output
+
+
+ at mingdalversion
+ at credentials
+def test_rio_clip(runner, tmpdir):
+ """S3 is supported by rio-clip"""
+ outputfile = tmpdir.join('clipped.tif')
+ result = runner.invoke(
+ main_group, ['clip', '--bounds', '420000', '2350000', '420060', '2350060',
+ '-o', str(outputfile), L8TIF])
+ assert result.exit_code == 0
diff --git a/tests/test_colorinterp.py b/tests/test_colorinterp.py
index 84d843f..3c33b15 100644
--- a/tests/test_colorinterp.py
+++ b/tests/test_colorinterp.py
@@ -33,20 +33,3 @@ def test_ycbcr_interp(tmpdir):
assert dst.colorinterp(1) == ColorInterp.red
assert dst.colorinterp(2) == ColorInterp.green
assert dst.colorinterp(3) == ColorInterp.blue
-
-
- at pytest.mark.xfail()
-def test_ycbcr_no_convert(tmpdir):
- """An unconverted YCbCr TIFF has Y, Cb, Cr bands."""
- with rasterio.drivers(GDAL_JPEG_TO_RGB=False):
- with rasterio.open('tests/data/RGB.byte.tif') as src:
- meta = src.meta
- meta['photometric'] = 'ycbcr'
- meta['compress'] = 'jpeg'
- meta['count'] = 3
- tiffname = str(tmpdir.join('foo.tif'))
- with rasterio.open(tiffname, 'w', **meta) as dst:
- assert dst.profile['photometric'] == 'ycbcr'
- assert dst.colorinterp(1) == ColorInterp.Y
- assert dst.colorinterp(2) == ColorInterp.Cb
- assert dst.colorinterp(3) == ColorInterp.Cr
diff --git a/tests/test_deprecations.py b/tests/test_deprecations.py
index be9b6a6..ff86464 100644
--- a/tests/test_deprecations.py
+++ b/tests/test_deprecations.py
@@ -1,6 +1,8 @@
# TODO delete this in 1.0
# This ensures that deprecation warnings are given but behavior is maintained
# on the way to stabilizing the API for 1.0
+import warnings
+
import pytest
import numpy
@@ -23,41 +25,50 @@ def data():
return data
-def test_data_window_unmasked(data):
- with pytest.warns(DeprecationWarning):
- old = get_data_window(data)
+def test_data_window_unmasked(data, recwarn):
+ warnings.simplefilter('always')
+ old = get_data_window(data)
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
new = windows.get_data_window(data)
+ assert len(recwarn) == 0
assert old == new
-def test_windows_intersect_disjunct():
+def test_windows_intersect_disjunct(recwarn):
data = [
((0, 6), (3, 6)),
((2, 4), (1, 5))]
-
- with pytest.warns(DeprecationWarning):
- old = windows_intersect(data)
+ warnings.simplefilter('always')
+ old = windows_intersect(data)
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
new = windows.intersect(data)
+ assert len(recwarn) == 0
assert old == new
-def test_window_intersection():
+def test_window_intersection(recwarn):
data = [
((0, 6), (3, 6)),
((2, 4), (1, 5))]
-
- with pytest.warns(DeprecationWarning):
- old = window_intersection(data)
+ warnings.simplefilter('always')
+ old = window_intersection(data)
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
new = windows.intersection(data)
+ assert len(recwarn) == 0
assert old == new
-def test_window_union():
+def test_window_union(recwarn):
data = [
((0, 6), (3, 6)),
((2, 4), (1, 5))]
-
- with pytest.warns(DeprecationWarning):
- old = window_union(data)
+ warnings.simplefilter('always')
+ old = window_union(data)
+ assert len(recwarn) == 1
+ assert recwarn.pop(DeprecationWarning)
new = windows.union(data)
+ assert len(recwarn) == 0
assert old == new
diff --git a/tests/test_rio_convert.py b/tests/test_rio_convert.py
index 001dcee..2f68637 100644
--- a/tests/test_rio_convert.py
+++ b/tests/test_rio_convert.py
@@ -6,7 +6,6 @@ from click.testing import CliRunner
import rasterio
from rasterio.rio.main import main_group
-from rasterio.rio.clip import clip
from rasterio.rio.convert import convert
@@ -19,8 +18,7 @@ def test_clip_bounds(runner, tmpdir):
output = str(tmpdir.join('test.tif'))
result = runner.invoke(
main_group,
- ['clip', 'tests/data/shade.tif', output, '--bounds'] + TEST_BBOX
- )
+ ['clip', 'tests/data/shade.tif', output, '--bounds'] + TEST_BBOX)
assert result.exit_code == 0
assert os.path.exists(output)
@@ -31,9 +29,9 @@ def test_clip_bounds(runner, tmpdir):
def test_clip_like(runner, tmpdir):
output = str(tmpdir.join('test.tif'))
result = runner.invoke(
- clip,
- ['tests/data/shade.tif', output, '--like', 'tests/data/shade.tif']
- )
+ main_group, [
+ 'clip', 'tests/data/shade.tif', output, '--like',
+ 'tests/data/shade.tif'])
assert result.exit_code == 0
assert os.path.exists(output)
@@ -46,9 +44,7 @@ def test_clip_like(runner, tmpdir):
def test_clip_missing_params(runner, tmpdir):
output = str(tmpdir.join('test.tif'))
result = runner.invoke(
- clip,
- ['tests/data/shade.tif', output]
- )
+ main_group, ['clip', 'tests/data/shade.tif', output])
assert result.exit_code == 2
assert '--bounds or --like required' in result.output
@@ -56,9 +52,8 @@ def test_clip_missing_params(runner, tmpdir):
def test_clip_bounds_disjunct(runner, tmpdir):
output = str(tmpdir.join('test.tif'))
result = runner.invoke(
- clip,
- ['tests/data/shade.tif', output, '--bounds'] + [0, 0, 10, 10]
- )
+ main_group,
+ ['clip', 'tests/data/shade.tif', output, '--bounds'] + [0, 0, 10, 10])
assert result.exit_code == 2
assert '--bounds' in result.output
@@ -66,9 +61,9 @@ def test_clip_bounds_disjunct(runner, tmpdir):
def test_clip_like_disjunct(runner, tmpdir):
output = str(tmpdir.join('test.tif'))
result = runner.invoke(
- clip,
- ['tests/data/shade.tif', output, '--like', 'tests/data/RGB.byte.tif']
- )
+ main_group, [
+ 'clip', 'tests/data/shade.tif', output, '--like',
+ 'tests/data/RGB.byte.tif'])
assert result.exit_code == 2
assert '--like' in result.output
@@ -116,7 +111,7 @@ def test_dtype(tmpdir):
['tests/data/RGB.byte.tif', outputname, '--dtype', 'uint16'])
assert result.exit_code == 0
with rasterio.open(outputname) as src:
- assert src.dtypes == ['uint16']*3
+ assert src.dtypes == ['uint16'] * 3
def test_dtype_rescaling_uint8_full(tmpdir):
@@ -174,7 +169,7 @@ def test_dtype_rescaling_float64(tmpdir):
runner = CliRunner()
result = runner.invoke(convert, [
'tests/data/RGB.byte.tif', outputname, '--dtype', 'float64',
- '--scale-ratio', str(2.0/255), '--scale-offset', '-1.0'])
+ '--scale-ratio', str(2.0 / 255), '--scale-offset', '-1.0'])
assert result.exit_code == 0
with rasterio.open(outputname) as src:
for band in src.read():
diff --git a/tests/test_rio_main.py b/tests/test_rio_main.py
new file mode 100644
index 0000000..af9995c
--- /dev/null
+++ b/tests/test_rio_main.py
@@ -0,0 +1,26 @@
+import logging
+import re
+import sys
+
+from click.testing import CliRunner
+from packaging.version import parse
+import pytest
+
+from rasterio.rio.main import main_group
+
+
+logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
+
+
+def test_version(data):
+ runner = CliRunner()
+ result = runner.invoke(main_group, ['--version'])
+ assert result.exit_code == 0
+ assert parse(result.output.strip())
+
+
+def test_gdal_version(data):
+ runner = CliRunner()
+ result = runner.invoke(main_group, ['--gdal-version'])
+ assert result.exit_code == 0
+ assert parse(result.output.strip())
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/rasterio.git
More information about the Pkg-grass-devel
mailing list