Skip to content

Commit 810ff9f

Browse files
author
Andrey Zhavoronkov
committed
added unit test for coco format (case: object segment field is empty)
1 parent 7e71954 commit 810ff9f

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

cvat/apps/engine/tests/test_rest_api.py

+81
Original file line numberDiff line numberDiff line change
@@ -2779,6 +2779,84 @@ def etree_to_dict(t):
27792779
elif annotation_format_name == "MASK":
27802780
self.assertTrue(zipfile.is_zipfile(content))
27812781

2782+
2783+
def _run_coco_annotation_upload_test(self, user):
2784+
def generate_coco_anno():
2785+
return b"""{
2786+
"categories": [
2787+
{
2788+
"id": 1,
2789+
"name": "car",
2790+
"supercategory": ""
2791+
},
2792+
{
2793+
"id": 2,
2794+
"name": "person",
2795+
"supercategory": ""
2796+
}
2797+
],
2798+
"images": [
2799+
{
2800+
"coco_url": "",
2801+
"date_captured": "",
2802+
"flickr_url": "",
2803+
"license": 0,
2804+
"id": 0,
2805+
"file_name": "test_1.jpg",
2806+
"height": 720,
2807+
"width": 1280
2808+
}
2809+
],
2810+
"annotations": [
2811+
{
2812+
"category_id": 1,
2813+
"id": 1,
2814+
"image_id": 0,
2815+
"iscrowd": 0,
2816+
"segmentation": [
2817+
[]
2818+
],
2819+
"area": 17702.0,
2820+
"bbox": [
2821+
574.0,
2822+
407.0,
2823+
167.0,
2824+
106.0
2825+
]
2826+
}
2827+
]
2828+
}"""
2829+
2830+
response = self._get_annotation_formats(user)
2831+
self.assertEqual(response.status_code, status.HTTP_200_OK)
2832+
supported_formats = response.data
2833+
self.assertTrue(isinstance(supported_formats, list) and supported_formats)
2834+
2835+
coco_format = None
2836+
for f in response.data:
2837+
if f["name"] == "COCO":
2838+
coco_format = f
2839+
break
2840+
self.assertTrue(coco_format)
2841+
loader = coco_format["loaders"][0]
2842+
2843+
task, _ = self._create_task(user, user)
2844+
2845+
content = io.BytesIO(generate_coco_anno())
2846+
content.seek(0)
2847+
2848+
uploaded_data = {
2849+
"annotation_file": content,
2850+
}
2851+
response = self._upload_api_v1_tasks_id_annotations(task["id"], user, uploaded_data, "format={}".format(loader["display_name"]))
2852+
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
2853+
2854+
response = self._upload_api_v1_tasks_id_annotations(task["id"], user, {}, "format={}".format(loader["display_name"]))
2855+
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
2856+
2857+
response = self._get_api_v1_tasks_id_annotations(task["id"], user)
2858+
self.assertEqual(response.status_code, status.HTTP_200_OK)
2859+
27822860
def test_api_v1_tasks_id_annotations_admin(self):
27832861
self._run_api_v1_tasks_id_annotations(self.admin, self.assignee,
27842862
self.assignee)
@@ -2801,6 +2879,9 @@ def test_api_v1_tasks_id_annotations_dump_load_user(self):
28012879
def test_api_v1_tasks_id_annotations_dump_load_no_auth(self):
28022880
self._run_api_v1_tasks_id_annotations_dump_load(self.user, self.assignee, None)
28032881

2882+
def test_api_v1_tasks_id_annotations_upload_coco_user(self):
2883+
self._run_coco_annotation_upload_test(self.user)
2884+
28042885
class ServerShareAPITestCase(APITestCase):
28052886
def setUp(self):
28062887
self.client = APIClient()

0 commit comments

Comments
 (0)