diff --git a/rasterio/_io.pyx b/rasterio/_io.pyx index fb875480..9c192da1 100644 --- a/rasterio/_io.pyx +++ b/rasterio/_io.pyx @@ -234,7 +234,7 @@ cdef class DatasetReaderBase(DatasetBase): self.height, self.width) int_window = windows.int_reshape(window) - win_shape += (int_window.num_rows, int_window.num_cols) + win_shape += (int(int_window.num_rows), int(int_window.num_cols)) else: win_shape += self.shape @@ -472,7 +472,7 @@ cdef class DatasetReaderBase(DatasetBase): self.height, self.width) int_window = windows.int_reshape(window) - win_shape += (int_window.num_rows, int_window.num_cols) + win_shape += (int(int_window.num_rows), int(int_window.num_cols)) else: win_shape += self.shape diff --git a/rasterio/windows.py b/rasterio/windows.py index 45d2b0e5..5b889ae5 100644 --- a/rasterio/windows.py +++ b/rasterio/windows.py @@ -26,7 +26,7 @@ def warn_window_deprecation(): """Standard warning about range tuple deprecation""" warnings.warn( "Range tuple window are deprecated. Please switch to Window class", - DeprecationWarning, stacklevel=2) + DeprecationWarning) def iter_args(function): diff --git a/tests/test_mask.py b/tests/test_mask.py index a5ef8e14..01b1ddea 100644 --- a/tests/test_mask.py +++ b/tests/test_mask.py @@ -1,12 +1,18 @@ """Unittests for rasterio.mask""" - +from packaging.version import parse import pytest import rasterio from rasterio.mask import mask as mask_tool +# Custom markers. +xfail_pixel_sensitive_gdal2 = pytest.mark.xfail( + parse(rasterio.__gdal_version__) < parse('2.0dev'), + reason="This test is sensitive to pixel values and requires GDAL 2.0+") + + def test_nodata(basic_image_file, basic_geometry): nodata_val = 0 geometries = [basic_geometry] @@ -24,6 +30,7 @@ def test_no_nodata(basic_image_file, basic_geometry): assert(masked.data.all() == default_nodata_val) +@xfail_pixel_sensitive_gdal2 def test_crop(basic_image, basic_image_file, basic_geometry): geometries = [basic_geometry] with rasterio.open(basic_image_file, "r") as src: @@ -37,6 +44,7 @@ def test_crop(basic_image, basic_image_file, basic_geometry): assert (masked[0] == image[2:5, 2:5]).all() +@xfail_pixel_sensitive_gdal2 def test_crop_all_touched(basic_image, basic_image_file, basic_geometry): geometries = [basic_geometry] with rasterio.open(basic_image_file, "r") as src: diff --git a/tests/test_rio_features.py b/tests/test_rio_features.py index 5b1fae38..cb8538ff 100644 --- a/tests/test_rio_features.py +++ b/tests/test_rio_features.py @@ -7,6 +7,7 @@ import warnings from affine import Affine import numpy as np +from packaging.version import parse import pytest import rasterio @@ -19,6 +20,12 @@ DEFAULT_SHAPE = (10, 10) logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +# Custom markers. +xfail_without_gdal2 = pytest.mark.xfail( + parse(rasterio.__gdal_version__) < parse('2.0dev'), + reason="This test is sensitive to pixel values and requires GDAL 2.0+") + + def bbox(*args): return ' '.join([str(x) for x in args]) @@ -169,6 +176,7 @@ def test_mask_invalid_geojson(runner, tmpdir, pixelated_image_file): assert 'Invalid GeoJSON' in result.output +@xfail_without_gdal2 def test_mask_crop(runner, tmpdir, basic_feature, pixelated_image): """ In order to test --crop option, we need to use a transform more similar to @@ -206,6 +214,7 @@ def test_mask_crop(runner, tmpdir, basic_feature, pixelated_image): out.read(1, masked=True).filled(0)) +@xfail_without_gdal2 def test_mask_crop_inverted_y(runner, tmpdir, basic_feature, pixelated_image_file): """ --crop option should also work if raster has a positive y pixel size diff --git a/tests/test_rio_info.py b/tests/test_rio_info.py index 0e81f6c3..c868a615 100644 --- a/tests/test_rio_info.py +++ b/tests/test_rio_info.py @@ -4,7 +4,7 @@ import sys import click from click.testing import CliRunner -from packaging.version import Version +from packaging.version import Version, parse import pytest import rasterio @@ -13,9 +13,6 @@ from rasterio.rio.edit_info import ( from rasterio.rio.main import main_group -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) - - def test_delete_nodata_exclusive_opts(data): """--unset-nodata and --nodata can't be used together""" runner = CliRunner() @@ -34,8 +31,8 @@ def test_delete_crs_exclusive_opts(data): assert result.exit_code == 2 -@pytest.mark.xfail( - Version(rasterio.__gdal_version__) < Version('1.10'), +@pytest.mark.skip( + parse(rasterio.__gdal_version__) < parse('1.10'), reason='GDAL version >= 1.10 required') def test_unset_crs(data): runner = CliRunner() @@ -48,7 +45,7 @@ def test_unset_crs(data): @pytest.mark.skip( - Version(rasterio.__gdal_version__) >= Version('1.10'), + parse(rasterio.__gdal_version__) >= parse('1.10'), reason='Test applies to GDAL version < 1.10') def test_unset_crs_gdal19(data): """unsetting crs doesn't work for geotiff and gdal 1.9 @@ -59,7 +56,7 @@ def test_unset_crs_gdal19(data): orig_crs = src.crs with pytest.warns(UserWarning): result = runner.invoke(main_group, - ['edit-info', inputfile, '--unset-crs']) + ['edit-info', inputfile, '--unset-crs']) assert result.exit_code == 0 with rasterio.open(inputfile) as src: assert src.crs == orig_crs # nochange diff --git a/tests/test_rio_merge.py b/tests/test_rio_merge.py index 57726d63..a3cec6c4 100644 --- a/tests/test_rio_merge.py +++ b/tests/test_rio_merge.py @@ -8,6 +8,7 @@ import logging import affine from click.testing import CliRunner import numpy as np +from packaging.version import parse from pytest import fixture import pytest @@ -17,7 +18,10 @@ from rasterio.rio.main import main_group from rasterio.transform import Affine -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +# Custom markers. +xfail_pixel_sensitive_gdal2 = pytest.mark.xfail( + parse(rasterio.__gdal_version__) < parse('2.0dev'), + reason="This test is sensitive to pixel values and requires GDAL 2.0+") # Fixture to create test datasets within temporary directory @@ -95,6 +99,7 @@ def test_merge_with_colormap(test_data_dir_1): assert cmap[255] == (0, 0, 0, 255) +@xfail_pixel_sensitive_gdal2 def test_merge_with_nodata(test_data_dir_1): outputname = str(test_data_dir_1.join('merged.tif')) inputs = [str(x) for x in test_data_dir_1.listdir()] @@ -125,6 +130,7 @@ def test_merge_warn(test_data_dir_1): assert os.path.exists(outputname) +@xfail_pixel_sensitive_gdal2 def test_merge_without_nodata(test_data_dir_2): outputname = str(test_data_dir_2.join('merged.tif')) inputs = [str(x) for x in test_data_dir_2.listdir()] @@ -268,6 +274,10 @@ def test_data_dir_float(tmpdir): return tmpdir +@xfail_pixel_sensitive_gdal2 +@pytest.mark.xfail( + os.environ.get('GDALVERSION', 'a.b.c').startswith('1.9'), + reason="GDAL 1.9 doesn't catch this error") def test_merge_float(test_data_dir_float): outputname = str(test_data_dir_float.join('merged.tif')) inputs = [str(x) for x in test_data_dir_float.listdir()] @@ -371,6 +381,7 @@ def test_merge_tiny_output_opt(tiffs): assert data[0][3][0] == 40 +@xfail_pixel_sensitive_gdal2 def test_merge_tiny_res_bounds(tiffs): outputname = str(tiffs.join('merged.tif')) inputs = [str(x) for x in tiffs.listdir()]