def test_from_geojson_on_invalid_unsupported_option(): with pytest.raises(ValueError, match="not a valid option"): shapely.from_geojson(GEOJSON_GEOMETRY, on_invalid="unsupported_option")
def test_geojson_all_types(geom): if shapely.get_type_id(geom) == shapely.GeometryType.LINEARRING: pytest.skip("Linearrings are not preserved in GeoJSON") geojson = shapely.to_geojson(geom) actual = shapely.from_geojson(geojson) assert_geometries_equal(actual, geom)
def test_from_geojson_ignore_on_invalid(): with warnings.catch_warnings(): warnings.simplefilter("error") assert shapely.from_geojson("", on_invalid="ignore") is None
def test_from_geojson_warn_on_invalid(): with pytest.warns(Warning, match="Invalid GeoJSON"): assert shapely.from_geojson("", on_invalid="warn") is None
def test_from_geojson_exceptions(): with pytest.raises(TypeError, match="Expected bytes or string, got int"): shapely.from_geojson(1) with pytest.raises(shapely.GEOSException, match="Error parsing JSON"): shapely.from_geojson("") with pytest.raises(shapely.GEOSException, match="Unknown geometry type"): shapely.from_geojson('{"type": "NoGeometry", "coordinates": []}') with pytest.raises(shapely.GEOSException, match="type must be array, but is null"): shapely.from_geojson('{"type": "LineString", "coordinates": null}') # Note: The two below tests are the reason that from_geojson is disabled for # GEOS 3.10.0 See https://trac.osgeo.org/geos/ticket/1138 with pytest.raises(shapely.GEOSException, match="key 'type' not found"): shapely.from_geojson('{"geometry": null, "properties": []}') with pytest.raises(shapely.GEOSException, match="key 'type' not found"): shapely.from_geojson('{"no": "geojson"}')
def test_from_geojson(geojson, expected): actual = shapely.from_geojson(geojson) assert_geometries_equal(actual, expected)
def test_from_geojson_ignore_on_invalid(): with pytest.warns(None): assert shapely.from_geojson("", on_invalid="ignore") is None