Skip to content

Commit 6ac90ac

Browse files
author
Ubuntu
committed
refactor tests and add segmentation local upload test
1 parent ad186d3 commit 6ac90ac

File tree

3 files changed

+92
-65
lines changed

3 files changed

+92
-65
lines changed

tests/helpers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ def reference_id_from_url(url):
301301

302302
TEST_MASK_URL = "https://raw.githubusercontent.com/scaleapi/nucleus-python-client/master/tests/testdata/000000000285.png"
303303

304+
this_dir = os.path.dirname(os.path.realpath(__file__))
305+
TEST_LOCAL_MASK_URL = os.path.join(this_dir, "testdata/000000000285.png")
306+
304307
TEST_SEGMENTATION_ANNOTATIONS = [
305308
{
306309
"reference_id": reference_id_from_url(TEST_IMG_URLS[i]),

tests/test_annotation.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
assert_multicategory_annotation_matches_dict,
3535
assert_partial_equality,
3636
assert_polygon_annotation_matches_dict,
37-
assert_segmentation_annotation_matches_dict,
3837
reference_id_from_url,
3938
)
4039

@@ -242,70 +241,6 @@ def test_default_multicategory_gt_upload(dataset):
242241
)
243242

244243

245-
def test_single_semseg_gt_upload(dataset):
246-
annotation = SegmentationAnnotation.from_json(
247-
TEST_SEGMENTATION_ANNOTATIONS[0]
248-
)
249-
response = dataset.annotate(annotations=[annotation])
250-
assert response["dataset_id"] == dataset.id
251-
assert response["annotations_processed"] == 1
252-
assert response["annotations_ignored"] == 0
253-
254-
response_annotation = dataset.refloc(annotation.reference_id)[
255-
"annotations"
256-
]["segmentation"][0]
257-
assert_segmentation_annotation_matches_dict(
258-
response_annotation, TEST_SEGMENTATION_ANNOTATIONS[0]
259-
)
260-
261-
262-
def test_batch_semseg_gt_upload(dataset):
263-
annotations = [
264-
SegmentationAnnotation.from_json(ann)
265-
for ann in TEST_SEGMENTATION_ANNOTATIONS
266-
]
267-
response = dataset.annotate(annotations=annotations)
268-
assert response["dataset_id"] == dataset.id
269-
assert response["annotations_processed"] == 5
270-
assert response["annotations_ignored"] == 0
271-
272-
273-
def test_batch_semseg_gt_upload_ignore(dataset):
274-
# First upload annotations
275-
annotations = [
276-
SegmentationAnnotation.from_json(ann)
277-
for ann in TEST_SEGMENTATION_ANNOTATIONS
278-
]
279-
response = dataset.annotate(annotations=annotations)
280-
assert response["dataset_id"] == dataset.id
281-
assert response["annotations_processed"] == 5
282-
assert response["annotations_ignored"] == 0
283-
284-
# When we re-upload, expect them to be ignored
285-
response = dataset.annotate(annotations=annotations)
286-
assert response["dataset_id"] == dataset.id
287-
assert response["annotations_processed"] == 0
288-
assert response["annotations_ignored"] == 5
289-
290-
291-
def test_batch_semseg_gt_upload_update(dataset):
292-
# First upload annotations
293-
annotations = [
294-
SegmentationAnnotation.from_json(ann)
295-
for ann in TEST_SEGMENTATION_ANNOTATIONS
296-
]
297-
response = dataset.annotate(annotations=annotations)
298-
assert response["dataset_id"] == dataset.id
299-
assert response["annotations_processed"] == 5
300-
assert response["annotations_ignored"] == 0
301-
302-
# When we re-upload, expect uploads to be processed
303-
response = dataset.annotate(annotations=annotations, update=True)
304-
assert response["dataset_id"] == dataset.id
305-
assert response["annotations_processed"] == 5
306-
assert response["annotations_ignored"] == 0
307-
308-
309244
def test_mixed_annotation_upload(dataset):
310245
# First upload annotations
311246
semseg_annotations = [

tests/test_segmentation.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
from nucleus.annotation import SegmentationAnnotation
2+
from tests.helpers import (
3+
TEST_LOCAL_MASK_URL,
4+
TEST_SEGMENTATION_ANNOTATIONS,
5+
assert_segmentation_annotation_matches_dict,
6+
)
7+
8+
9+
def test_single_local_semseg_gt_upload(dataset):
10+
annotation = SegmentationAnnotation.from_json(
11+
TEST_SEGMENTATION_ANNOTATIONS[0]
12+
)
13+
annotation.mask_url = TEST_LOCAL_MASK_URL
14+
response = dataset.annotate(annotations=[annotation])
15+
16+
assert response["dataset_id"] == dataset.id
17+
assert response["annotations_processed"] == 1
18+
assert response["annotations_ignored"] == 0
19+
20+
response_annotation = dataset.refloc(annotation.reference_id)[
21+
"annotations"
22+
]["segmentation"][0]
23+
assert_segmentation_annotation_matches_dict(
24+
response_annotation, TEST_SEGMENTATION_ANNOTATIONS[0]
25+
)
26+
27+
28+
def test_single_semseg_gt_upload(dataset):
29+
annotation = SegmentationAnnotation.from_json(
30+
TEST_SEGMENTATION_ANNOTATIONS[0]
31+
)
32+
response = dataset.annotate(annotations=[annotation])
33+
assert response["dataset_id"] == dataset.id
34+
assert response["annotations_processed"] == 1
35+
assert response["annotations_ignored"] == 0
36+
37+
response_annotation = dataset.refloc(annotation.reference_id)[
38+
"annotations"
39+
]["segmentation"][0]
40+
assert_segmentation_annotation_matches_dict(
41+
response_annotation, TEST_SEGMENTATION_ANNOTATIONS[0]
42+
)
43+
44+
45+
def test_batch_semseg_gt_upload(dataset):
46+
annotations = [
47+
SegmentationAnnotation.from_json(ann)
48+
for ann in TEST_SEGMENTATION_ANNOTATIONS
49+
]
50+
response = dataset.annotate(annotations=annotations)
51+
assert response["dataset_id"] == dataset.id
52+
assert response["annotations_processed"] == 5
53+
assert response["annotations_ignored"] == 0
54+
55+
56+
def test_batch_semseg_gt_upload_ignore(dataset):
57+
# First upload annotations
58+
annotations = [
59+
SegmentationAnnotation.from_json(ann)
60+
for ann in TEST_SEGMENTATION_ANNOTATIONS
61+
]
62+
response = dataset.annotate(annotations=annotations)
63+
assert response["dataset_id"] == dataset.id
64+
assert response["annotations_processed"] == 5
65+
assert response["annotations_ignored"] == 0
66+
67+
# When we re-upload, expect them to be ignored
68+
response = dataset.annotate(annotations=annotations)
69+
assert response["dataset_id"] == dataset.id
70+
assert response["annotations_processed"] == 0
71+
assert response["annotations_ignored"] == 5
72+
73+
74+
def test_batch_semseg_gt_upload_update(dataset):
75+
# First upload annotations
76+
annotations = [
77+
SegmentationAnnotation.from_json(ann)
78+
for ann in TEST_SEGMENTATION_ANNOTATIONS
79+
]
80+
response = dataset.annotate(annotations=annotations)
81+
assert response["dataset_id"] == dataset.id
82+
assert response["annotations_processed"] == 5
83+
assert response["annotations_ignored"] == 0
84+
85+
# When we re-upload, expect uploads to be processed
86+
response = dataset.annotate(annotations=annotations, update=True)
87+
assert response["dataset_id"] == dataset.id
88+
assert response["annotations_processed"] == 5
89+
assert response["annotations_ignored"] == 0

0 commit comments

Comments
 (0)