Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve point validation #144

Merged
merged 2 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions geojson/geometry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from decimal import Decimal
from numbers import Number

from geojson.base import GeoJSON

Expand Down Expand Up @@ -83,6 +84,9 @@ def check_point(coord):
return 'each position must be a list'
if len(coord) not in (2, 3):
return 'a position must have exactly 2 or 3 values'
for number in coord:
if not isinstance(number, Number):
return 'a position cannot have inner positions'


class Point(Geometry):
Expand Down
3 changes: 3 additions & 0 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def test_invalid_point(self):
point = geojson.Point((10, 20, 30, 40))
self.assertEqual(point.is_valid, False)

point = geojson.Point([(10, 20), (30, 40)])
self.assertEqual(point.is_valid, False)

def test_valid_point(self):
point = geojson.Point((-3.68, 40.41))
self.assertEqual(point.is_valid, True)
Expand Down