diff --git a/cligj/features.py b/cligj/features.py index a7ecc06..9b2b904 100644 --- a/cligj/features.py +++ b/cligj/features.py @@ -125,6 +125,8 @@ def iter_features(geojsonfile, func=None): newfeat = func(to_feature(json.loads(line))) if newfeat: yield newfeat + else: + raise TypeError("Invalid type") # Indented or pretty-printed GeoJSON features or feature # collections will fail out of the try clause above since diff --git a/tests/test_features.py b/tests/test_features.py index 43eea90..d972cf1 100644 --- a/tests/test_features.py +++ b/tests/test_features.py @@ -132,6 +132,13 @@ def test_geometrypretty(expected_features): features = normalize_feature_inputs(None, 'features', ["tests/point_pretty_geom.txt"]) assert _geoms(features)[0] == _geoms(expected_features)[0] + +def test_invalid_type(): + features = normalize_feature_inputs(None, 'features', ["tests/twopoints_invalid_type.txt"]) + with pytest.raises(TypeError): + _geoms(features) + + class MockGeo(object): def __init__(self, feature): self.__geo_interface__ = feature @@ -149,6 +156,7 @@ def test_normalize_feature_objects_bad(expected_features): with pytest.raises(ValueError): list(normalize_feature_objects(objs)) + def test_to_feature(expected_features): geom = expected_features[0]['geometry'] feat = {'type': 'Feature', 'properties': {}, 'geometry': geom} diff --git a/tests/twopoints_invalid_type.txt b/tests/twopoints_invalid_type.txt new file mode 100644 index 0000000..5b2c1b0 --- /dev/null +++ b/tests/twopoints_invalid_type.txt @@ -0,0 +1,2 @@ +{"type": "MultiPoint", "geometry": [[134.519974,34.084171],[134.546188,34.081322],[134.546219,34.078766],[134.542374,34.081287]]} +{"type": "MultiPoint", "geometry": [[130.405380,33.571598],[130.383682,33.567059],[130.486740,33.652233],[130.455490,33.597004],[130.437195,33.601784],[130.447998,33.654606],[130.409592,33.606941]]} \ No newline at end of file