1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
"""Unittests to verify Fiona is functioning properly with other software."""
from collections import UserDict
import fiona
from fiona.model import Feature
def test_dict_subclass(tmpdir):
"""Rasterio now has a `CRS()` class that subclasses
`collections.UserDict()`. Make sure we can receive it.
`UserDict()` is a good class to test against because in Python 2 it is
not a subclass of `collections.Mapping()`, so it provides an edge case.
"""
class CRS(UserDict):
pass
outfile = str(tmpdir.join("test_UserDict.geojson"))
profile = {
"crs": CRS(init="EPSG:4326"),
"driver": "GeoJSON",
"schema": {"geometry": "Point", "properties": {}},
}
with fiona.open(outfile, "w", **profile) as dst:
dst.write(
Feature.from_dict(
**{
"type": "Feature",
"properties": {},
"geometry": {"type": "Point", "coordinates": (10, -10)},
}
)
)
with fiona.open(outfile) as src:
assert len(src) == 1
assert src.crs == {"init": "epsg:4326"}
|