MCPcopy
hub / github.com/python-visualization/folium / test_geojson_find_identifier

Function test_geojson_find_identifier

tests/test_features.py:177–277  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

175
176
177def test_geojson_find_identifier():
178 def _create(*properties):
179 return {
180 "type": "FeatureCollection",
181 "features": [
182 {"type": "Feature", "properties": item} for item in properties
183 ],
184 }
185
186 def _assert_id_got_added(data):
187 _geojson = GeoJson(data)
188 assert _geojson.find_identifier() == "feature.id"
189 assert _geojson.data["features"][0]["id"] == "0"
190
191 data_with_id = _create(None, None)
192 data_with_id["features"][0]["id"] = "this-is-an-id"
193 data_with_id["features"][1]["id"] = "this-is-another-id"
194 geojson = GeoJson(data_with_id)
195 assert geojson.find_identifier() == "feature.id"
196 assert geojson.data["features"][0]["id"] == "this-is-an-id"
197
198 data_with_unique_properties = _create(
199 {"property-key": "some-value"},
200 {"property-key": "another-value"},
201 )
202 geojson = GeoJson(data_with_unique_properties)
203 assert geojson.find_identifier() == "feature.properties.property-key"
204
205 data_with_unique_properties = _create(
206 {"property-key": 42},
207 {"property-key": 43},
208 {"property-key": "or a string"},
209 )
210 geojson = GeoJson(data_with_unique_properties)
211 assert geojson.find_identifier() == "feature.properties.property-key"
212
213 # The test cases below have no id field or unique property,
214 # so an id will be added to the data.
215
216 data_with_identical_ids = _create(None, None)
217 data_with_identical_ids["features"][0]["id"] = "identical-ids"
218 data_with_identical_ids["features"][1]["id"] = "identical-ids"
219 _assert_id_got_added(data_with_identical_ids)
220
221 data_with_some_missing_ids = _create(None, None)
222 data_with_some_missing_ids["features"][0]["id"] = "this-is-an-id"
223 # the second feature doesn't have an id
224 _assert_id_got_added(data_with_some_missing_ids)
225
226 data_with_identical_properties = _create(
227 {"property-key": "identical-value"},
228 {"property-key": "identical-value"},
229 )
230 _assert_id_got_added(data_with_identical_properties)
231
232 data_bare = _create(None)
233 _assert_id_got_added(data_bare)
234

Callers

nothing calls this directly

Calls 5

find_identifierMethod · 0.95
GeoJsonClass · 0.90
_createFunction · 0.85
_assert_id_got_addedFunction · 0.85

Tested by

no test coverage detected