1111"""
1212
1313
14- def test_create_from_url (model_run_with_data_rows ,
15- annotation_import_test_helpers ):
16- name = str (uuid .uuid4 ())
17- url = "https://storage.googleapis.com/labelbox-public-bucket/predictions_test_v2.ndjson"
18- annotation_import = model_run_with_data_rows .add_predictions (
19- name = name , predictions = url )
20- assert annotation_import .model_run_id == model_run_with_data_rows .uid
21- annotation_import_test_helpers .check_running_state (annotation_import , name ,
22- url )
23- annotation_import .wait_until_done ()
24-
25-
26- def test_create_from_objects (model_run_with_data_rows , object_predictions ,
14+ def test_create_from_objects (model_run_with_data_rows ,
15+ object_predictions_for_annotation_import ,
2716 annotation_import_test_helpers ):
2817 name = str (uuid .uuid4 ())
18+ object_predictions = object_predictions_for_annotation_import
19+ use_data_row_ids = [p ['dataRow' ]['id' ] for p in object_predictions ]
20+ model_run_with_data_rows .upsert_data_rows (use_data_row_ids )
2921
3022 annotation_import = model_run_with_data_rows .add_predictions (
3123 name = name , predictions = object_predictions )
@@ -36,15 +28,19 @@ def test_create_from_objects(model_run_with_data_rows, object_predictions,
3628 annotation_import .input_file_url , object_predictions )
3729 annotation_import .wait_until_done ()
3830
31+ assert annotation_import .state == AnnotationImportState .FINISHED
32+ annotation_import_test_helpers .download_and_assert_status (
33+ annotation_import .status_file_url )
34+
3935
4036def test_create_from_objects_global_key (client , model_run_with_data_rows ,
41- entity_inference ,
37+ polygon_inference ,
4238 annotation_import_test_helpers ):
4339 name = str (uuid .uuid4 ())
44- dr = client .get_data_row (entity_inference ['dataRow' ]['id' ])
45- del entity_inference ['dataRow' ]['id' ]
46- entity_inference ['dataRow' ]['globalKey' ] = dr .global_key
47- object_predictions = [entity_inference ]
40+ dr = client .get_data_row (polygon_inference ['dataRow' ]['id' ])
41+ del polygon_inference ['dataRow' ]['id' ]
42+ polygon_inference ['dataRow' ]['globalKey' ] = dr .global_key
43+ object_predictions = [polygon_inference ]
4844
4945 annotation_import = model_run_with_data_rows .add_predictions (
5046 name = name , predictions = object_predictions )
@@ -55,6 +51,10 @@ def test_create_from_objects_global_key(client, model_run_with_data_rows,
5551 annotation_import .input_file_url , object_predictions )
5652 annotation_import .wait_until_done ()
5753
54+ assert annotation_import .state == AnnotationImportState .FINISHED
55+ annotation_import_test_helpers .download_and_assert_status (
56+ annotation_import .status_file_url )
57+
5858
5959def test_create_from_objects_with_confidence (predictions_with_confidence ,
6060 model_run_with_data_rows ,
@@ -77,15 +77,20 @@ def test_create_from_objects_with_confidence(predictions_with_confidence,
7777 annotation_import_test_helpers .assert_file_content (
7878 annotation_import .input_file_url , predictions_with_confidence )
7979 annotation_import .wait_until_done ()
80+
8081 assert annotation_import .state == AnnotationImportState .FINISHED
8182 annotation_import_test_helpers .download_and_assert_status (
8283 annotation_import .status_file_url )
8384
8485
8586def test_create_from_objects_all_project_labels (
86- model_run_with_all_project_labels , object_predictions ,
87+ model_run_with_all_project_labels ,
88+ object_predictions_for_annotation_import ,
8789 annotation_import_test_helpers ):
8890 name = str (uuid .uuid4 ())
91+ object_predictions = object_predictions_for_annotation_import
92+ use_data_row_ids = [p ['dataRow' ]['id' ] for p in object_predictions ]
93+ model_run_with_all_project_labels .upsert_data_rows (use_data_row_ids )
8994
9095 annotation_import = model_run_with_all_project_labels .add_predictions (
9196 name = name , predictions = object_predictions )
@@ -96,13 +101,18 @@ def test_create_from_objects_all_project_labels(
96101 annotation_import .input_file_url , object_predictions )
97102 annotation_import .wait_until_done ()
98103
104+ assert annotation_import .state == AnnotationImportState .FINISHED
105+ annotation_import_test_helpers .download_and_assert_status (
106+ annotation_import .status_file_url )
107+
99108
100109def test_model_run_project_labels (model_run_with_all_project_labels ,
101110 model_run_predictions ):
102111 model_run = model_run_with_all_project_labels
103112 # TODO: Move to export_v2
104113 model_run_exported_labels = model_run .export_labels (download = True )
105114 labels_indexed_by_schema_id = {}
115+
106116 for label in model_run_exported_labels :
107117 # assuming exported array of label 'objects' has only one label per data row... as usually is when there are no label revisions
108118 schema_id = label ['Label' ]['objects' ][0 ]['schemaId' ]
@@ -121,11 +131,17 @@ def test_model_run_project_labels(model_run_with_all_project_labels,
121131 assert actual_label ['DataRow ID' ] == expected_label ['dataRow' ]['id' ]
122132
123133
124- def test_create_from_label_objects (model_run_with_data_rows , object_predictions ,
134+ def test_create_from_label_objects (model_run_with_data_rows ,
135+ object_predictions_for_annotation_import ,
125136 annotation_import_test_helpers ):
126137 name = str (uuid .uuid4 ())
138+ use_data_row_ids = [
139+ p ['dataRow' ]['id' ] for p in object_predictions_for_annotation_import
140+ ]
141+ model_run_with_data_rows .upsert_data_rows (use_data_row_ids )
127142
128- predictions = list (NDJsonConverter .deserialize (object_predictions ))
143+ predictions = list (
144+ NDJsonConverter .deserialize (object_predictions_for_annotation_import ))
129145
130146 annotation_import = model_run_with_data_rows .add_predictions (
131147 name = name , predictions = predictions )
@@ -137,25 +153,39 @@ def test_create_from_label_objects(model_run_with_data_rows, object_predictions,
137153 annotation_import .input_file_url , normalized_predictions )
138154 annotation_import .wait_until_done ()
139155
156+ assert annotation_import .state == AnnotationImportState .FINISHED
157+ annotation_import_test_helpers .download_and_assert_status (
158+ annotation_import .status_file_url )
159+
140160
141161def test_create_from_local_file (tmp_path , model_run_with_data_rows ,
142- object_predictions ,
162+ object_predictions_for_annotation_import ,
143163 annotation_import_test_helpers ):
164+ use_data_row_ids = [
165+ p ['dataRow' ]['id' ] for p in object_predictions_for_annotation_import
166+ ]
167+ model_run_with_data_rows .upsert_data_rows (use_data_row_ids )
168+
144169 name = str (uuid .uuid4 ())
145170 file_name = f"{ name } .ndjson"
146171 file_path = tmp_path / file_name
147172 with file_path .open ("w" ) as f :
148- parser .dump (object_predictions , f )
173+ parser .dump (object_predictions_for_annotation_import , f )
149174
150175 annotation_import = model_run_with_data_rows .add_predictions (
151176 name = name , predictions = str (file_path ))
152177
153178 assert annotation_import .model_run_id == model_run_with_data_rows .uid
154179 annotation_import_test_helpers .check_running_state (annotation_import , name )
155180 annotation_import_test_helpers .assert_file_content (
156- annotation_import .input_file_url , object_predictions )
181+ annotation_import .input_file_url ,
182+ object_predictions_for_annotation_import )
157183 annotation_import .wait_until_done ()
158184
185+ assert annotation_import .state == AnnotationImportState .FINISHED
186+ annotation_import_test_helpers .download_and_assert_status (
187+ annotation_import .status_file_url )
188+
159189
160190def test_get (client , model_run_with_data_rows , annotation_import_test_helpers ):
161191 name = str (uuid .uuid4 ())
0 commit comments