Skip to content

Commit

Permalink
added further tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristofferEdlund committed Oct 16, 2023
1 parent b21b144 commit bc86dba
Showing 1 changed file with 64 additions and 14 deletions.
78 changes: 64 additions & 14 deletions tests/darwin/exporter/formats/export_darwin_1_0_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

class TestBuildJson:
def test_empty_annotation_file(self):
annotation_file = dt.AnnotationFile(
path=Path("test.json"), filename="test.json", annotation_classes=[], annotations=[]
)
annotation_file = dt.AnnotationFile(path=Path("test.json"), filename="test.json", annotation_classes=[], annotations=[])

assert _build_json(annotation_file) == {
"image": {
Expand Down Expand Up @@ -130,19 +128,14 @@ def test_complex_polygon(self):
"dataset": "None",
}


def test_polygon_annotation_file_with_bbox(self):
polygon_path = [
{"x": 534.1440000000002, "y": 429.0896},
{"x": 531.6440000000002, "y": 428.4196},
{"x": 529.8140000000002, "y": 426.5896},
]

bounding_box = {"x": 557.66,
"y": 428.98,
"w": 160.76,
"h": 315.3
}
bounding_box = {"x": 557.66, "y": 428.98, "w": 160.76, "h": 315.3}

annotation_class = dt.AnnotationClass(name="test", annotation_type="polygon")
annotation = dt.Annotation(annotation_class=annotation_class, data={"path": polygon_path, "bounding_box": bounding_box}, subs=[])
Expand Down Expand Up @@ -185,11 +178,7 @@ def test_complex_polygon_with_bbox(self):
],
]

bounding_box = {"x": 557.66,
"y": 428.98,
"w": 160.76,
"h": 315.3
}
bounding_box = {"x": 557.66, "y": 428.98, "w": 160.76, "h": 315.3}

annotation_class = dt.AnnotationClass(name="test", annotation_type="complex_polygon")
annotation = dt.Annotation(annotation_class=annotation_class, data={"paths": polygon_path, "bounding_box": bounding_box}, subs=[])
Expand Down Expand Up @@ -219,3 +208,64 @@ def test_complex_polygon_with_bbox(self):
"annotations": [{"complex_polygon": {"path": polygon_path}, "name": "test", "slot_names": [], "bounding_box": bounding_box}],
"dataset": "None",
}

def test_bounding_box(self):
bounding_box_data = {"x": 100, "y": 150, "w": 50, "h": 30}
annotation_class = dt.AnnotationClass(name="bbox_test", annotation_type="bounding_box")
annotation = dt.Annotation(annotation_class=annotation_class, data=bounding_box_data, subs=[])

annotation_file = dt.AnnotationFile(
path=Path("test.json"),
filename="test.json",
annotation_classes=[annotation_class],
annotations=[annotation],
image_height=1080,
image_width=1920,
image_url="https://darwin.v7labs.com/image.jpg",
)

assert _build_json(annotation_file) == {
"image": {
"seq": None,
"width": 1920,
"height": 1080,
"filename": "test.json",
"original_filename": "test.json",
"url": "https://darwin.v7labs.com/image.jpg",
"thumbnail_url": None,
"path": None,
"workview_url": None,
},
"annotations": [{"bounding_box": bounding_box_data, "name": "bbox_test", "slot_names": []}],
"dataset": "None",
}

def test_tags(self):
tag_data = "sample_tag"
annotation_class = dt.AnnotationClass(name="tag_test", annotation_type="tag")
annotation = dt.Annotation(annotation_class=annotation_class, data=tag_data, subs=[])

annotation_file = dt.AnnotationFile(
path=Path("test.json"),
filename="test.json",
annotation_classes=[annotation_class],
annotations=[annotation],
image_height=1080,
image_width=1920,
image_url="https://darwin.v7labs.com/image.jpg",
)
assert _build_json(annotation_file) == {
"image": {
"seq": None,
"width": 1920,
"height": 1080,
"filename": "test.json",
"original_filename": "test.json",
"url": "https://darwin.v7labs.com/image.jpg",
"thumbnail_url": None,
"path": None,
"workview_url": None,
},
"annotations": [{"tag": {}, "name": "tag_test", "slot_names": []}],
"dataset": "None",
}

0 comments on commit bc86dba

Please sign in to comment.