TST: Add tests for to_file/read_file for spatialite format (#2829)

Co-authored-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
This commit is contained in:
Pieter Roggemans
2023-03-10 16:47:02 +01:00
committed by GitHub
co-authored by Joris Van den Bossche
parent a0d4cf6208
commit fcb6ad207d
@@ -244,7 +244,7 @@ def geodataframe(request):
return request.param
@pytest.fixture(params=["GeoJSON", "ESRI Shapefile", "GPKG"])
@pytest.fixture(params=["GeoJSON", "ESRI Shapefile", "GPKG", "SQLite"])
def ogr_driver(request):
return request.param
@@ -261,15 +261,42 @@ def engine(request):
def test_to_file_roundtrip(tmpdir, geodataframe, ogr_driver, engine):
output_file = os.path.join(str(tmpdir), "output_file")
write_kwargs = {}
if ogr_driver == "SQLite":
write_kwargs["spatialite"] = True
# This if statement can be removed once minimal fiona version >= 1.8.20
if engine == "fiona":
import fiona
from packaging.version import Version
if Version(fiona.__version__) < Version("1.8.20"):
pytest.skip("SQLite driver only available from version 1.8.20")
# If only 3D Points, geometry_type needs to be specified for spatialite at the
# moment. This if can be removed once the following PR is released:
# https://github.com/geopandas/pyogrio/pull/223
if (
engine == "pyogrio"
and len(geodataframe == 2)
and geodataframe.geometry[0] is None
and geodataframe.geometry[1] is not None
and geodataframe.geometry[1].has_z
):
write_kwargs["geometry_type"] = "Point Z"
expected_error = _expected_error_on(geodataframe, ogr_driver)
if expected_error:
with pytest.raises(
RuntimeError, match="Failed to write record|Could not add feature to layer"
):
geodataframe.to_file(output_file, driver=ogr_driver, engine=engine)
geodataframe.to_file(
output_file, driver=ogr_driver, engine=engine, **write_kwargs
)
else:
geodataframe.to_file(output_file, driver=ogr_driver, engine=engine)
geodataframe.to_file(
output_file, driver=ogr_driver, engine=engine, **write_kwargs
)
reloaded = geopandas.read_file(output_file, engine=engine)