1
1
from nucleus .annotation import SegmentationAnnotation
2
+ from nucleus .dataset import Dataset
2
3
from tests .helpers import (
3
4
TEST_LOCAL_MASK_URL ,
4
5
TEST_SEGMENTATION_ANNOTATIONS ,
5
6
assert_segmentation_annotation_matches_dict ,
6
7
)
7
8
8
9
9
- def test_single_local_semseg_gt_upload (dataset ):
10
- annotation = SegmentationAnnotation .from_json (
10
+ def test_single_local_semseg_gt_upload (dataset : Dataset ):
11
+ request_annotation = SegmentationAnnotation .from_json (
11
12
TEST_SEGMENTATION_ANNOTATIONS [0 ]
12
13
)
13
- annotation .mask_url = TEST_LOCAL_MASK_URL
14
- response = dataset .annotate (annotations = [annotation ])
14
+ request_annotation .mask_url = TEST_LOCAL_MASK_URL
15
+ response = dataset .annotate (annotations = [request_annotation ])
15
16
16
17
assert response ["dataset_id" ] == dataset .id
17
18
assert response ["annotations_processed" ] == 1
18
19
assert response ["annotations_ignored" ] == 0
19
20
20
- response_annotation = dataset .refloc (annotation .reference_id )[
21
+ response_annotation = dataset .refloc (request_annotation .reference_id )[
21
22
"annotations"
22
23
]["segmentation" ][0 ]
23
- assert_segmentation_annotation_matches_dict (
24
- response_annotation , TEST_SEGMENTATION_ANNOTATIONS [0 ]
25
- )
24
+
25
+ assert response_annotation == request_annotation
26
+
27
+
28
+ def test_batch_local_semseg_gt_upload (dataset : Dataset ):
29
+
30
+ # This reference id is not in the dataset.
31
+ bad_reference_id = TEST_SEGMENTATION_ANNOTATIONS [- 1 ]["reference_id" ]
32
+
33
+ request_annotations = [
34
+ SegmentationAnnotation .from_json (json_data )
35
+ for json_data in TEST_SEGMENTATION_ANNOTATIONS
36
+ ]
37
+ for request_annotation in request_annotations :
38
+ request_annotation .mask_url = TEST_LOCAL_MASK_URL
39
+ response = dataset .annotate (annotations = request_annotations )
40
+
41
+ print (request_annotations )
42
+ print (response )
43
+
44
+ assert response ["dataset_id" ] == dataset .id
45
+ assert response ["annotations_processed" ] == 4
46
+ assert response ["annotations_ignored" ] == 0
47
+ assert bad_reference_id in response ["errors" ][0 ]
48
+
49
+ for request_annotation in request_annotations [:4 ]:
50
+ response_annotation = dataset .refloc (request_annotation .reference_id )[
51
+ "annotations"
52
+ ]["segmentation" ][0 ]
53
+
54
+ assert response_annotation == request_annotation
26
55
27
56
28
57
def test_single_semseg_gt_upload (dataset ):
@@ -49,7 +78,7 @@ def test_batch_semseg_gt_upload(dataset):
49
78
]
50
79
response = dataset .annotate (annotations = annotations )
51
80
assert response ["dataset_id" ] == dataset .id
52
- assert response ["annotations_processed" ] == 5
81
+ assert response ["annotations_processed" ] == 4
53
82
assert response ["annotations_ignored" ] == 0
54
83
55
84
@@ -61,14 +90,14 @@ def test_batch_semseg_gt_upload_ignore(dataset):
61
90
]
62
91
response = dataset .annotate (annotations = annotations )
63
92
assert response ["dataset_id" ] == dataset .id
64
- assert response ["annotations_processed" ] == 5
93
+ assert response ["annotations_processed" ] == 4
65
94
assert response ["annotations_ignored" ] == 0
66
95
67
96
# When we re-upload, expect them to be ignored
68
97
response = dataset .annotate (annotations = annotations )
69
98
assert response ["dataset_id" ] == dataset .id
70
99
assert response ["annotations_processed" ] == 0
71
- assert response ["annotations_ignored" ] == 5
100
+ assert response ["annotations_ignored" ] == 4
72
101
73
102
74
103
def test_batch_semseg_gt_upload_update (dataset ):
@@ -79,11 +108,11 @@ def test_batch_semseg_gt_upload_update(dataset):
79
108
]
80
109
response = dataset .annotate (annotations = annotations )
81
110
assert response ["dataset_id" ] == dataset .id
82
- assert response ["annotations_processed" ] == 5
111
+ assert response ["annotations_processed" ] == 4
83
112
assert response ["annotations_ignored" ] == 0
84
113
85
114
# When we re-upload, expect uploads to be processed
86
115
response = dataset .annotate (annotations = annotations , update = True )
87
116
assert response ["dataset_id" ] == dataset .id
88
- assert response ["annotations_processed" ] == 5
117
+ assert response ["annotations_processed" ] == 4
89
118
assert response ["annotations_ignored" ] == 0
0 commit comments