Skip to content

Commit 412a441

Browse files
authored
TST: Replace test datasets with pyogrio-generated files where possible (#441)
1 parent db45ddf commit 412a441

16 files changed

+489
-170
lines changed

pyogrio/tests/conftest.py

Lines changed: 149 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from pathlib import Path
33
from zipfile import ZIP_DEFLATED, ZipFile
44

5+
import numpy as np
6+
57
from pyogrio import (
68
__gdal_version_string__,
79
__version__,
@@ -126,28 +128,165 @@ def naturalearth_lowres_vsi(tmp_path, naturalearth_lowres):
126128

127129

128130
@pytest.fixture(scope="session")
129-
def test_fgdb_vsi():
130-
return f"/vsizip/{_data_dir}/test_fgdb.gdb.zip"
131+
def line_zm_file():
132+
return _data_dir / "line_zm.gpkg"
131133

132134

133135
@pytest.fixture(scope="session")
134-
def test_gpkg_nulls():
135-
return _data_dir / "test_gpkg_nulls.gpkg"
136+
def curve_file():
137+
return _data_dir / "curve.gpkg"
136138

137139

138140
@pytest.fixture(scope="session")
139-
def test_ogr_types_list():
140-
return _data_dir / "test_ogr_types_list.geojson"
141+
def curve_polygon_file():
142+
return _data_dir / "curvepolygon.gpkg"
141143

142144

143145
@pytest.fixture(scope="session")
144-
def test_datetime():
145-
return _data_dir / "test_datetime.geojson"
146+
def multisurface_file():
147+
return _data_dir / "multisurface.gpkg"
146148

147149

148150
@pytest.fixture(scope="session")
149-
def test_datetime_tz():
150-
return _data_dir / "test_datetime_tz.geojson"
151+
def test_gpkg_nulls():
152+
return _data_dir / "test_gpkg_nulls.gpkg"
153+
154+
155+
@pytest.fixture(scope="function")
156+
def no_geometry_file(tmp_path):
157+
# create a GPKG layer that does not include geometry
158+
filename = tmp_path / "test_no_geometry.gpkg"
159+
write(
160+
filename,
161+
layer="no_geometry",
162+
geometry=None,
163+
field_data=[np.array(["a", "b", "c"])],
164+
fields=["col"],
165+
)
166+
167+
return filename
168+
169+
170+
@pytest.fixture(scope="function")
171+
def list_field_values_file(tmp_path):
172+
# Create a GeoJSON file with list values in a property
173+
list_geojson = """{
174+
"type": "FeatureCollection",
175+
"features": [
176+
{
177+
"type": "Feature",
178+
"properties": { "int64": 1, "list_int64": [0, 1] },
179+
"geometry": { "type": "Point", "coordinates": [0, 2] }
180+
},
181+
{
182+
"type": "Feature",
183+
"properties": { "int64": 2, "list_int64": [2, 3] },
184+
"geometry": { "type": "Point", "coordinates": [1, 2] }
185+
},
186+
{
187+
"type": "Feature",
188+
"properties": { "int64": 3, "list_int64": [4, 5] },
189+
"geometry": { "type": "Point", "coordinates": [2, 2] }
190+
},
191+
{
192+
"type": "Feature",
193+
"properties": { "int64": 4, "list_int64": [6, 7] },
194+
"geometry": { "type": "Point", "coordinates": [3, 2] }
195+
},
196+
{
197+
"type": "Feature",
198+
"properties": { "int64": 5, "list_int64": [8, 9] },
199+
"geometry": { "type": "Point", "coordinates": [4, 2] }
200+
}
201+
]
202+
}"""
203+
204+
filename = tmp_path / "test_ogr_types_list.geojson"
205+
with open(filename, "w") as f:
206+
_ = f.write(list_geojson)
207+
208+
return filename
209+
210+
211+
@pytest.fixture(scope="function")
212+
def nested_geojson_file(tmp_path):
213+
# create GeoJSON file with nested properties
214+
nested_geojson = """{
215+
"type": "FeatureCollection",
216+
"features": [
217+
{
218+
"type": "Feature",
219+
"geometry": {
220+
"type": "Point",
221+
"coordinates": [0, 0]
222+
},
223+
"properties": {
224+
"top_level": "A",
225+
"intermediate_level": {
226+
"bottom_level": "B"
227+
}
228+
}
229+
}
230+
]
231+
}"""
232+
233+
filename = tmp_path / "test_nested.geojson"
234+
with open(filename, "w") as f:
235+
_ = f.write(nested_geojson)
236+
237+
return filename
238+
239+
240+
@pytest.fixture(scope="function")
241+
def datetime_file(tmp_path):
242+
# create GeoJSON file with millisecond precision
243+
datetime_geojson = """{
244+
"type": "FeatureCollection",
245+
"features": [
246+
{
247+
"type": "Feature",
248+
"properties": { "col": "2020-01-01T09:00:00.123" },
249+
"geometry": { "type": "Point", "coordinates": [1, 1] }
250+
},
251+
{
252+
"type": "Feature",
253+
"properties": { "col": "2020-01-01T10:00:00" },
254+
"geometry": { "type": "Point", "coordinates": [2, 2] }
255+
}
256+
]
257+
}"""
258+
259+
filename = tmp_path / "test_datetime.geojson"
260+
with open(filename, "w") as f:
261+
_ = f.write(datetime_geojson)
262+
263+
return filename
264+
265+
266+
@pytest.fixture(scope="function")
267+
def datetime_tz_file(tmp_path):
268+
# create GeoJSON file with datetimes with timezone
269+
datetime_tz_geojson = """{
270+
"type": "FeatureCollection",
271+
"features": [
272+
{
273+
"type": "Feature",
274+
"properties": { "datetime_col": "2020-01-01T09:00:00.123-05:00" },
275+
"geometry": { "type": "Point", "coordinates": [1, 1] }
276+
},
277+
{
278+
"type": "Feature",
279+
"properties": { "datetime_col": "2020-01-01T10:00:00-05:00" },
280+
"geometry": { "type": "Point", "coordinates": [2, 2] }
281+
}
282+
]
283+
}"""
284+
285+
filename = tmp_path / "test_datetime_tz.geojson"
286+
with open(filename, "w") as f:
287+
f.write(datetime_tz_geojson)
288+
289+
return filename
151290

152291

153292
@pytest.fixture(scope="function")

pyogrio/tests/fixtures/README.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
# Test datasets
22

3-
## Natural Earth lowres
3+
## Obtaining / creating test datasets
44

5-
`naturalearth_lowres.shp` was copied from GeoPandas.
5+
If a test dataset can be created in code, do that instead. If it is used in a
6+
single test, create the test dataset as part of that test. If it is used in
7+
more than a single test, add it to `pyogrio/tests/conftest.py` instead, as a
8+
function-scoped test fixture.
9+
10+
If you need to obtain 3rd party test files:
11+
12+
- add a section below that describes the source location and processing steps
13+
to derive that dataset
14+
- make sure the license is compatible with including in Pyogrio (public domain or open-source)
15+
and record that license below
16+
17+
Please keep the test files no larger than necessary to use in tests.
618

7-
## FGDB test dataset
19+
## Included test datasets
20+
21+
### Natural Earth lowres
22+
23+
`naturalearth_lowres.shp` was copied from GeoPandas.
824

9-
`test_fgdb.gdb.zip`
10-
Downloaded from http://trac.osgeo.org/gdal/raw-attachment/wiki/FileGDB/test_fgdb.gdb.zip
25+
License: public domain
1126

1227
### GPKG test dataset with null values
1328

@@ -75,15 +90,19 @@ NOTE: Reading boolean values into GeoPandas using Fiona backend treats those
7590
values as `None` and column dtype as `object`; Pyogrio treats those values as
7691
`np.nan` and column dtype as `float64`.
7792

78-
### GPKG test with MultiSurface
79-
80-
This was extracted from https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0308_HU4_GDB.zip
81-
`NHDWaterbody` layer using ogr2ogr:
82-
83-
```bash
84-
ogr2ogr test_mixed_surface.gpkg NHDPLUS_H_0308_HU4_GDB.gdb NHDWaterbody -where '"NHDPlusID" = 15000300070477' -select "NHDPlusID"
85-
```
93+
License: same as Pyogrio
8694

8795
### OSM PBF test
8896

8997
This was downloaded from https://github.com/openstreetmap/OSM-binary/blob/master/resources/sample.pbf
98+
99+
License: [Open Data Commons Open Database License (ODbL)](https://opendatacommons.org/licenses/odbl/)
100+
101+
### Test files for geometry types that are downgraded on read
102+
103+
`line_zm.gpkg` was created using QGIS to digitize a LineString GPKG layer with Z and M enabled. Downgraded to LineString Z on read.
104+
`curve.gpkg` was created using QGIS to digitize a Curve GPKG layer. Downgraded to LineString on read.
105+
`curvepolygon.gpkg` was created using QGIS to digitize a CurvePolygon GPKG layer. Downgraded to Polygon on read.
106+
`multisurface.gpkg` was created using QGIS to digitize a MultiSurface GPKG layer. Downgraded to MultiPolygon on read.
107+
108+
License: same as Pyogrio

pyogrio/tests/fixtures/curve.gpkg

96 KB
Binary file not shown.
96 KB
Binary file not shown.
96 KB
Binary file not shown.
96 KB
Binary file not shown.
-2.35 KB
Binary file not shown.

pyogrio/tests/fixtures/test_datetime.geojson

Lines changed: 0 additions & 7 deletions
This file was deleted.

pyogrio/tests/fixtures/test_datetime_tz.geojson

Lines changed: 0 additions & 8 deletions
This file was deleted.
-99.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)