From b2b144a12d1e3f390c975955507f313c382862bf Mon Sep 17 00:00:00 2001 From: "Brendan C. Ward" Date: Mon, 1 Jul 2024 20:31:37 -0700 Subject: [PATCH 1/2] Consolidate test marks that skip if shapely is not installed --- pyogrio/tests/test_core.py | 14 ++++---------- pyogrio/tests/test_raw_io.py | 21 ++++++--------------- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/pyogrio/tests/test_core.py b/pyogrio/tests/test_core.py index 765564eb..3ed12307 100644 --- a/pyogrio/tests/test_core.py +++ b/pyogrio/tests/test_core.py @@ -16,7 +16,7 @@ from pyogrio.core import detect_write_driver from pyogrio._compat import GDAL_GE_38 from pyogrio.errors import DataSourceError, DataLayerError -from pyogrio.tests.conftest import HAS_SHAPELY, prepare_testfile +from pyogrio.tests.conftest import prepare_testfile, requires_shapely from pyogrio._env import GDALEnv @@ -302,9 +302,7 @@ def test_read_bounds_bbox(naturalearth_lowres_all_ext): ) -@pytest.mark.skipif( - not HAS_SHAPELY, reason="Shapely is required for mask functionality" -) +@requires_shapely @pytest.mark.parametrize( "mask", [ @@ -318,9 +316,7 @@ def test_read_bounds_mask_invalid(naturalearth_lowres, mask): read_bounds(naturalearth_lowres, mask=mask) -@pytest.mark.skipif( - not HAS_SHAPELY, reason="Shapely is required for mask functionality" -) +@requires_shapely def test_read_bounds_bbox_mask_invalid(naturalearth_lowres): with pytest.raises(ValueError, match="cannot set both 'bbox' and 'mask'"): read_bounds( @@ -328,9 +324,7 @@ def test_read_bounds_bbox_mask_invalid(naturalearth_lowres): ) -@pytest.mark.skipif( - not HAS_SHAPELY, reason="Shapely is required for mask functionality" -) +@requires_shapely @pytest.mark.parametrize( "mask,expected", [ diff --git a/pyogrio/tests/test_raw_io.py b/pyogrio/tests/test_raw_io.py index e21f768c..963ed72f 100644 --- a/pyogrio/tests/test_raw_io.py +++ b/pyogrio/tests/test_raw_io.py @@ -26,6 +26,7 @@ prepare_testfile, requires_pyarrow_api, requires_arrow_api, + requires_shapely, ) try: @@ -255,9 +256,7 @@ def test_read_bbox_where(naturalearth_lowres_all_ext): assert np.array_equal(fields[3], ["CAN"]) -@pytest.mark.skipif( - not HAS_SHAPELY, reason="Shapely is required for mask functionality" -) +@requires_shapely @pytest.mark.parametrize( "mask", [ @@ -271,17 +270,13 @@ def test_read_mask_invalid(naturalearth_lowres, mask): read(naturalearth_lowres, mask=mask) -@pytest.mark.skipif( - not HAS_SHAPELY, reason="Shapely is required for mask functionality" -) +@requires_shapely def test_read_bbox_mask_invalid(naturalearth_lowres): with pytest.raises(ValueError, match="cannot set both 'bbox' and 'mask'"): read(naturalearth_lowres, bbox=(-85, 8, -80, 10), mask=shapely.Point(-105, 55)) -@pytest.mark.skipif( - not HAS_SHAPELY, reason="Shapely is required for mask functionality" -) +@requires_shapely @pytest.mark.parametrize( "mask,expected", [ @@ -316,9 +311,7 @@ def test_read_mask(naturalearth_lowres_all_ext, mask, expected): assert len(geometry) == len(expected) -@pytest.mark.skipif( - not HAS_SHAPELY, reason="Shapely is required for mask functionality" -) +@requires_shapely def test_read_mask_sql(naturalearth_lowres_all_ext): fields = read( naturalearth_lowres_all_ext, @@ -329,9 +322,7 @@ def test_read_mask_sql(naturalearth_lowres_all_ext): assert np.array_equal(fields[3], ["CAN"]) -@pytest.mark.skipif( - not HAS_SHAPELY, reason="Shapely is required for mask functionality" -) +@requires_shapely def test_read_mask_where(naturalearth_lowres_all_ext): fields = read( naturalearth_lowres_all_ext, From 923b883e972e8af3ddcaad979c9130946042c088 Mon Sep 17 00:00:00 2001 From: "Brendan C. Ward" Date: Tue, 2 Jul 2024 12:44:45 -0700 Subject: [PATCH 2/2] Update from main --- pyogrio/tests/test_raw_io.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pyogrio/tests/test_raw_io.py b/pyogrio/tests/test_raw_io.py index 6ffd46d8..b56e588e 100644 --- a/pyogrio/tests/test_raw_io.py +++ b/pyogrio/tests/test_raw_io.py @@ -117,9 +117,7 @@ def test_read_no_geometry(naturalearth_lowres): assert geometry is None -@pytest.mark.skipif( - not HAS_SHAPELY, reason="Shapely is required for mask functionality" -) +@requires_shapely def test_read_no_geometry__mask(naturalearth_lowres): geometry, fields = read( naturalearth_lowres,