55 TEST_IMG_URLS ,
66 TEST_BOX_ANNOTATIONS ,
77 TEST_POLYGON_ANNOTATIONS ,
8+ TEST_CATEGORY_ANNOTATIONS ,
89 TEST_SEGMENTATION_ANNOTATIONS ,
910 reference_id_from_url ,
1011 assert_box_annotation_matches_dict ,
1112 assert_polygon_annotation_matches_dict ,
13+ assert_category_annotation_matches_dict ,
1214 assert_segmentation_annotation_matches_dict ,
1315)
1416
1517from nucleus import (
1618 BoxAnnotation ,
1719 PolygonAnnotation ,
20+ CategoryAnnotation ,
1821 SegmentationAnnotation ,
1922 DatasetItem ,
2023 Segment ,
@@ -55,6 +58,12 @@ def dataset(CLIENT):
5558
5659 response = ds .append (ds_items )
5760 assert ERROR_PAYLOAD not in response .json ()
61+
62+ response = ds .add_taxonomy (
63+ "[Pytest] Category Taxonomy 1" ,
64+ "category" ,
65+ [f"[Pytest] Category Label ${ i } " for i in range ((len (TEST_IMG_URLS )))],
66+ )
5867 yield ds
5968
6069 response = CLIENT .delete_dataset (ds .id )
@@ -100,6 +109,24 @@ def test_polygon_gt_upload(dataset):
100109 )
101110
102111
112+ def test_category_gt_upload (dataset ):
113+ annotation = CategoryAnnotation .from_json (TEST_CATEGORY_ANNOTATIONS [0 ])
114+ response = dataset .annotate (annotations = [annotation ])
115+
116+ assert response ["dataset_id" ] == dataset .id
117+ assert response ["annotations_processed" ] == 1
118+ assert response ["annotations_ignored" ] == 0
119+
120+ response = dataset .refloc (annotation .reference_id )["annotations" ][
121+ "category"
122+ ]
123+ assert len (response ) == 1
124+ response_annotation = response [0 ]
125+ assert_category_annotation_matches_dict (
126+ response_annotation , TEST_CATEGORY_ANNOTATIONS [0 ]
127+ )
128+
129+
103130def test_single_semseg_gt_upload (dataset ):
104131 annotation = SegmentationAnnotation .from_json (
105132 TEST_SEGMENTATION_ANNOTATIONS [0 ]
@@ -308,6 +335,63 @@ def test_polygon_gt_upload_ignore(dataset):
308335 response_annotation , TEST_POLYGON_ANNOTATIONS [0 ]
309336 )
310337
338+
339+ def test_category_gt_upload_update (dataset ):
340+ annotation = CategoryAnnotation .from_json (TEST_CATEGORY_ANNOTATIONS [0 ])
341+ response = dataset .annotate (annotations = [annotation ])
342+
343+ assert response ["annotations_processed" ] == 1
344+
345+ # Copy so we don't modify the original.
346+ annotation_update_params = dict (TEST_CATEGORY_ANNOTATIONS [1 ])
347+ annotation_update_params ["reference_id" ] = TEST_CATEGORY_ANNOTATIONS [0 ][
348+ "reference_id"
349+ ]
350+
351+ annotation_update = CategoryAnnotation .from_json (annotation_update_params )
352+ response = dataset .annotate (annotations = [annotation_update ], update = True )
353+
354+ assert response ["annotations_processed" ] == 1
355+ assert response ["annotations_ignored" ] == 0
356+
357+ response = dataset .refloc (annotation .reference_id )["annotations" ][
358+ "category"
359+ ]
360+ assert len (response ) == 1
361+ response_annotation = response [0 ]
362+ assert_category_annotation_matches_dict (
363+ response_annotation , annotation_update_params
364+ )
365+
366+
367+ def test_category_gt_upload_ignore (dataset ):
368+ annotation = CategoryAnnotation .from_json (TEST_CATEGORY_ANNOTATIONS [0 ])
369+ response = dataset .annotate (annotations = [annotation ])
370+
371+ assert response ["annotations_processed" ] == 1
372+
373+ # Copy so we don't modify the original.
374+ annotation_update_params = dict (TEST_CATEGORY_ANNOTATIONS [1 ])
375+ annotation_update_params ["reference_id" ] = TEST_CATEGORY_ANNOTATIONS [0 ][
376+ "reference_id"
377+ ]
378+
379+ annotation_update = CategoryAnnotation .from_json (annotation_update_params )
380+ # Default behavior is ignore.
381+ response = dataset .annotate (annotations = [annotation_update ])
382+
383+ assert response ["annotations_processed" ] == 0
384+ assert response ["annotations_ignored" ] == 1
385+
386+ response = dataset .refloc (annotation .reference_id )["annotations" ][
387+ "category"
388+ ]
389+ assert len (response ) == 1
390+ response_annotation = response [0 ]
391+ assert_category_annotation_matches_dict (
392+ response_annotation , TEST_CATEGORY_ANNOTATIONS [0 ]
393+ )
394+
311395 @pytest .mark .integration
312396 def test_box_gt_deletion (dataset ):
313397 annotation = BoxAnnotation (** TEST_BOX_ANNOTATIONS [0 ])
@@ -323,3 +407,19 @@ def test_box_gt_deletion(dataset):
323407 job_status = job .status ()
324408 assert job_status ["status" ] == "Completed"
325409 assert job_status ["job_id" ] == job .id
410+
411+ @pytest .mark .integration
412+ def test_category_gt_deletion (dataset ):
413+ annotation = CategoryAnnotation .from_json (TEST_CATEGORY_ANNOTATIONS [0 ])
414+
415+ print (annotation )
416+
417+ response = dataset .annotate (annotations = [annotation ])
418+
419+ assert response ["annotations_processed" ] == 1
420+
421+ job = dataset .delete_annotations ()
422+ job .sleep_until_complete ()
423+ job_status = job .status ()
424+ assert job_status ["status" ] == "Completed"
425+ assert job_status ["job_id" ] == job .id
0 commit comments