Skip to content

Commit

Permalink
added unit test for coco format (case: object segment field is empty)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Zhavoronkov committed Nov 1, 2019
1 parent 7e71954 commit 810ff9f
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions cvat/apps/engine/tests/test_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2779,6 +2779,84 @@ def etree_to_dict(t):
elif annotation_format_name == "MASK":
self.assertTrue(zipfile.is_zipfile(content))


def _run_coco_annotation_upload_test(self, user):
def generate_coco_anno():
return b"""{
"categories": [
{
"id": 1,
"name": "car",
"supercategory": ""
},
{
"id": 2,
"name": "person",
"supercategory": ""
}
],
"images": [
{
"coco_url": "",
"date_captured": "",
"flickr_url": "",
"license": 0,
"id": 0,
"file_name": "test_1.jpg",
"height": 720,
"width": 1280
}
],
"annotations": [
{
"category_id": 1,
"id": 1,
"image_id": 0,
"iscrowd": 0,
"segmentation": [
[]
],
"area": 17702.0,
"bbox": [
574.0,
407.0,
167.0,
106.0
]
}
]
}"""

response = self._get_annotation_formats(user)
self.assertEqual(response.status_code, status.HTTP_200_OK)
supported_formats = response.data
self.assertTrue(isinstance(supported_formats, list) and supported_formats)

coco_format = None
for f in response.data:
if f["name"] == "COCO":
coco_format = f
break
self.assertTrue(coco_format)
loader = coco_format["loaders"][0]

task, _ = self._create_task(user, user)

content = io.BytesIO(generate_coco_anno())
content.seek(0)

uploaded_data = {
"annotation_file": content,
}
response = self._upload_api_v1_tasks_id_annotations(task["id"], user, uploaded_data, "format={}".format(loader["display_name"]))
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)

response = self._upload_api_v1_tasks_id_annotations(task["id"], user, {}, "format={}".format(loader["display_name"]))
self.assertEqual(response.status_code, status.HTTP_201_CREATED)

response = self._get_api_v1_tasks_id_annotations(task["id"], user)
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_api_v1_tasks_id_annotations_admin(self):
self._run_api_v1_tasks_id_annotations(self.admin, self.assignee,
self.assignee)
Expand All @@ -2801,6 +2879,9 @@ def test_api_v1_tasks_id_annotations_dump_load_user(self):
def test_api_v1_tasks_id_annotations_dump_load_no_auth(self):
self._run_api_v1_tasks_id_annotations_dump_load(self.user, self.assignee, None)

def test_api_v1_tasks_id_annotations_upload_coco_user(self):
self._run_coco_annotation_upload_test(self.user)

class ServerShareAPITestCase(APITestCase):
def setUp(self):
self.client = APIClient()
Expand Down

0 comments on commit 810ff9f

Please sign in to comment.