From 1837bd35b2d31b95fb10d08a562b4ffd94606fec Mon Sep 17 00:00:00 2001 From: Meilo Date: Fri, 23 Aug 2024 11:19:35 +0200 Subject: [PATCH 1/2] update batch create with default value --- hasty/label.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hasty/label.py b/hasty/label.py index ef08288..b10dc68 100644 --- a/hasty/label.py +++ b/hasty/label.py @@ -183,7 +183,7 @@ def _batch_create(requester, project_id, image_id, labels): "bbox": label.get("bbox"), "polygon": label.get("polygon"), "mask": label.get("mask"), - "z_index": label.get("z_index"), + "z_index": label.get("z_index", 0), "external_id": label.get("external_id"), "tool_used": C_LABELS_TOOL_USED}) res = requester.post(Label.endpoint_image.format(project_id=project_id, image_id=image_id), json_data=data) From 432630c4a71ec254418e2df44c0fd3a45c388696 Mon Sep 17 00:00:00 2001 From: Meilo Date: Fri, 23 Aug 2024 11:39:31 +0200 Subject: [PATCH 2/2] add tests --- tests/test_label.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_label.py b/tests/test_label.py index 830821f..6ce00dd 100644 --- a/tests/test_label.py +++ b/tests/test_label.py @@ -55,6 +55,29 @@ def test_label(self): labels = self.image.get_labels() self.assertEqual(0, len(labels)) + def test_labels(self): + labels = self.image.get_labels() + self.assertEqual(0, len(labels)) + # Label with specified z_index + bbox1 = [10, 10, 50, 50] + poly1 = [[10, 20], [20, 44], [10, 15]] + z_index1 = 3 + # Label with unspecified z_index + bbox2 = [10, 10, 50, 50] + poly2 = [[10, 20], [20, 44], [10, 15]] + z_index2 = None + # Bulk create labels + _ = self.image.create_labels( + {"class_id": self.label_class.id, "bbox": bbox1, "polygon": poly1, "mask": None, "z_index": z_index1}, + {"class_id": self.label_class.id, "bbox": bbox2, "polygon": poly2, "mask": None, "z_index": z_index2} + ) + labels = self.image.get_labels() + self.assertEqual(2, len(labels)) + for label in labels: + label.delete() + labels = self.image.get_labels() + self.assertEqual(0, len(labels)) + def test_external_id_for_label(self): # Create label bbox = [10, 10, 50, 50]