Skip to content

Commit 7763ddf

Browse files
committed
Adding test for annotations upload
1 parent 2eba398 commit 7763ddf

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

bigml/api_handlers/sourcehandler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,12 @@ def update_composite_annotations(self, source, images_file,
548548
"components": source_ids})
549549
elif optype == "regions":
550550
for value, source_id in values:
551+
if isinstance(value, dict):
552+
# dictionary should contain the bigml-coco format
553+
value = compact_regions(value)
551554
changes.append(
552555
{"field": field,
553-
"value": compact_regions(value),
556+
"value": value,
554557
"components": [source_id]})
555558
else:
556559
for value, source_id in values:

bigml/tests/create_dataset_steps.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,16 @@ def clone_dataset(step, dataset):
222222
def the_cloned_dataset_is(step, dataset):
223223
"""Checking the dataset is a clone"""
224224
eq_(world.dataset["origin"], dataset)
225+
226+
227+
def check_annotations(step, annotations_field, annotations_num):
228+
"""Checking the dataset contains a number of annotations"""
229+
annotations_num = int(annotations_num)
230+
field = world.dataset["fields"][annotations_field]
231+
if field["optype"] == "regions":
232+
count = field["summary"]["regions"]["sum"]
233+
else:
234+
count = 0
235+
for _, num in field["summary"]["categories"]:
236+
count += num
237+
eq_(count, annotations_num)

bigml/tests/test_22_source_args.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from .world import world, setup_module, teardown_module, show_doc, \
2626
show_method
2727
from . import create_source_steps as source_create
28+
from . import create_dataset_steps as dataset_create
2829

2930

3031
class TestUploadSource:
@@ -125,3 +126,38 @@ def test_scenario3(self):
125126
source_create.the_source_is_finished(
126127
self, example["source_wait"])
127128
source_create.the_cloned_source_origin_is(self, source)
129+
130+
def test_scenario4(self):
131+
"""
132+
Scenario: Successfully adding annotatations to composite source:
133+
Given I create an annotated images data source uploading a "<data>" file
134+
And I wait until the source is ready less than <source_wait> secs
135+
And I create a dataset
136+
And I wait until the dataset is ready less than <dataset_wait> secs
137+
Then the new dataset has <annotations_num> annotations in the <annotations_field> field
138+
"""
139+
headers = ["data", "source_wait", "dataset_wait", "annotations_num",
140+
"annotations_field"]
141+
examples = [
142+
['data/images/metadata.json', '500', '500', '12',
143+
'100002'],
144+
['data/images/metadata_compact.json', '500', '500', '3',
145+
'100003']]
146+
show_doc(self.test_scenario4)
147+
for example in examples:
148+
example = dict(zip(headers, example))
149+
show_method(self, self.bigml["method"], example)
150+
source_create.i_create_annotated_source(
151+
self,
152+
example["data"],
153+
args={"image_analysis": {"enabled": False,
154+
"extracted_features": []}})
155+
source_create.the_source_is_finished(
156+
self, example["source_wait"])
157+
dataset_create.i_create_a_dataset(self)
158+
dataset_create.the_dataset_is_finished_in_less_than(
159+
self, example["dataset_wait"])
160+
dataset_create.check_annotations(self,
161+
example["annotations_field"],
162+
example["annotations_num"])
163+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[{"file": "f1/fruits1f.png", "my_regions": "[[\"region1\" 0.2 0.2 0.4 0.4]]"},
2+
{"file": "f1/fruits1.png", "my_regions": "[[\"region2\" 0.3 0.3 0.5 0.5] [\"region1\" 0.6 0.6 0.8 0.8]]"}]

data/images/metadata_compact.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{"description": "Fruit images to test colour distributions with regions",
2+
"images_file": "./fruits_hist.zip",
3+
"new_fields": [{"name": "my_regions", "optype": "regions"}],
4+
"source_id": null,
5+
"annotations": "./annotations_compact.json"}

0 commit comments

Comments
 (0)