Skip to content

Commit cd4522c

Browse files
committed
update to base classes and added test cases
1 parent 369a6c2 commit cd4522c

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

labelbox/data/annotation_types/tiled_image.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,27 @@ class EPSG(Enum):
2222
class TiledBounds(BaseModel):
2323
""" Bounds for a tiled image asset related to the relevant epsg.
2424
25-
Each bound is a list of Point objects.
25+
Bounds should be Point objects
2626
2727
If version of asset is 2, these should be [[lat,lng],[lat,lng]]
2828
If version of asset is 1, these should be [[lng,lat]],[lng,lat]]
2929
3030
>>> bounds = TiledBounds(
31-
epsg=EPSG.4326,
32-
bounds=[[0,0],[100,100]]
31+
epsg=EPSG.4326,
32+
bounds=[Point(x=0, y=0),Point(x=100, y=100)]
3333
)
3434
"""
3535
epsg: EPSG
36-
bounds: List[List[Point]]
36+
bounds: List[Point]
37+
38+
@validator('bounds')
39+
def validate_bounds(cls, bounds):
40+
first_bound = bounds[0]
41+
second_bound = bounds[1]
42+
43+
if first_bound == second_bound:
44+
raise AssertionError(f"Bounds cannot be equal, contains {bounds}")
45+
return bounds
3746

3847

3948
class TileLayer(BaseModel):
@@ -42,22 +51,16 @@ class TileLayer(BaseModel):
4251
https://c.tile.openstreetmap.org/{z}/{x}/{y}.png
4352
4453
>>> layer = TileLayer(
45-
url=https://c.tile.openstreetmap.org/{z}/{x}/{y}.png,
54+
url="https://c.tile.openstreetmap.org/{z}/{x}/{y}.png",
4655
name="slippy map tile"
4756
)
4857
"""
4958
url: str
5059
name: Optional[str] = "default"
5160

52-
def from_dict():
53-
pass
54-
55-
def to_dict():
56-
pass
57-
5861
@validator('url')
5962
def validate_url(cls, url):
6063
xyz_format = "/{z}/{x}/{y}"
6164
if xyz_format not in url:
62-
raise AssertionError(f"{self.url} needs to contain {xyz_format}")
65+
raise AssertionError(f"{url} needs to contain {xyz_format}")
6366
return url
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pytest
2+
from labelbox.data.annotation_types import tiled_image
3+
from labelbox.data.annotation_types.geometry.point import Point
4+
from labelbox.data.annotation_types.tiled_image import (EPSG, TiledBounds,
5+
TileLayer)
6+
from pydantic import ValidationError
7+
8+
9+
@pytest.mark.parametrize("epsg", list(EPSG))
10+
def test_epsg(epsg):
11+
assert isinstance(epsg, EPSG)
12+
13+
14+
@pytest.mark.parametrize("epsg", list(EPSG))
15+
def test_tiled_bounds(epsg):
16+
top_left = Point(x=0, y=0)
17+
bottom_right = Point(x=100, y=100)
18+
19+
tiled_bounds = TiledBounds(epsg=epsg, bounds=[top_left, bottom_right])
20+
assert isinstance(tiled_bounds, TiledBounds)
21+
assert isinstance(tiled_bounds.epsg, EPSG)
22+
23+
24+
@pytest.mark.parametrize("epsg", list(EPSG))
25+
def test_tiled_bounds_same(epsg):
26+
single_bound = Point(x=0, y=0)
27+
with pytest.raises(ValidationError):
28+
tiled_bounds = TiledBounds(epsg=epsg,
29+
bounds=[single_bound, single_bound])

0 commit comments

Comments
 (0)