Skip to content

Commit

Permalink
Merge pull request #19 from JJardin77580/patch-1
Browse files Browse the repository at this point in the history
Update LAT LON max
  • Loading branch information
folt authored Jan 1, 2023
2 parents 0a8265e + 0b84556 commit e9e82ba
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Aliaksandr Vaskevich <[email protected]>

Contributors
------------
Jeoffrey Jardin <[email protected]>
8 changes: 4 additions & 4 deletions pydantic_geojson/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
Union[float, int],
Field(
title='Coordinate longitude',
gt=-180,
lt=180,
gte=-180,
lte=180,
),
]

LatField = Annotated[
Union[float, int],
Field(
title='Coordinate latitude',
gt=-90,
lt=90,
gte=-90,
lte=90,
),
]

Expand Down
109 changes: 109 additions & 0 deletions tests/test_feature_on_lat_lon_limit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
from pydantic_geojson import LineStringModel, PointModel, PolygonModel

data_linestring = {
"type": "LineString",
"coordinates": [
[-180.0, -90],
[180.0, 90],
]
}

data_point = {
'type': 'Point',
'coordinates': [-180, 90]
}

data_point_error_lon_min = {
'type': 'Point',
'coordinates': [-181, 90]
}

data_point_error_lon_max = {
'type': 'Point',
'coordinates': [181, 90]
}


data_point_error_lat_min = {
'type': 'Point',
'coordinates': [-180, -91]
}

data_point_error_lat_max = {
'type': 'Point',
'coordinates': [180, 91]

}

data_polygon = {
'type': 'Polygon',
'coordinates': [
[
[-180, 90],
[180, 90],
[180, -90],
[-180, -90],
[180, 90]
]
]
}


class TestFeatureOnLimit:
def test_loads_model_linestring(self):
ls_model = LineStringModel(**data_linestring)
coordinates = ls_model.coordinates

for lsi_key, ls_item in enumerate(coordinates):
lon, lat = ls_item
assert data_linestring['coordinates'][lsi_key] == [lon, lat]

assert ls_model.type == data_linestring['type']

def test_loads_model_point(self):
p_model = PointModel(**data_point)
coordinates = p_model.coordinates

lon, lat = coordinates.lon, coordinates.lat
assert data_point['coordinates'] == [lon, lat]

assert p_model.type == data_point['type']

def test_loads_model(self):
p_model = PolygonModel(**data_polygon)
coordinates = p_model.coordinates

for pi_key, p_item in enumerate(coordinates):
for pl_key, p_coordinate in enumerate(p_item):
lon, lat = p_coordinate.lon, p_coordinate.lat
assert data_polygon['coordinates'][pi_key][pl_key] == [lon, lat]

assert p_model.type == data_polygon['type']

def test_error_in_output_range_lon_min(self):
try:
PointModel(**data_point_error_lon_min)
assert False
except Exception:
assert True

def test_error_in_output_range_lat_min(self):
try:
PointModel(**data_point_error_lat_min)
assert False
except Exception:
assert True

def test_error_in_output_range_lon_max(self):
try:
PointModel(**data_point_error_lon_max)
assert False
except Exception:
assert True

def test_error_in_output_range_lat_max(self):
try:
PointModel(**data_point_error_lat_max)
assert False
except Exception:
assert True

0 comments on commit e9e82ba

Please sign in to comment.