11
11
"""
12
12
13
13
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 ,
27
16
annotation_import_test_helpers ):
28
17
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 )
29
21
30
22
annotation_import = model_run_with_data_rows .add_predictions (
31
23
name = name , predictions = object_predictions )
@@ -36,15 +28,19 @@ def test_create_from_objects(model_run_with_data_rows, object_predictions,
36
28
annotation_import .input_file_url , object_predictions )
37
29
annotation_import .wait_until_done ()
38
30
31
+ assert annotation_import .state == AnnotationImportState .FINISHED
32
+ annotation_import_test_helpers .download_and_assert_status (
33
+ annotation_import .status_file_url )
34
+
39
35
40
36
def test_create_from_objects_global_key (client , model_run_with_data_rows ,
41
- entity_inference ,
37
+ polygon_inference ,
42
38
annotation_import_test_helpers ):
43
39
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 ]
48
44
49
45
annotation_import = model_run_with_data_rows .add_predictions (
50
46
name = name , predictions = object_predictions )
@@ -55,6 +51,10 @@ def test_create_from_objects_global_key(client, model_run_with_data_rows,
55
51
annotation_import .input_file_url , object_predictions )
56
52
annotation_import .wait_until_done ()
57
53
54
+ assert annotation_import .state == AnnotationImportState .FINISHED
55
+ annotation_import_test_helpers .download_and_assert_status (
56
+ annotation_import .status_file_url )
57
+
58
58
59
59
def test_create_from_objects_with_confidence (predictions_with_confidence ,
60
60
model_run_with_data_rows ,
@@ -77,15 +77,20 @@ def test_create_from_objects_with_confidence(predictions_with_confidence,
77
77
annotation_import_test_helpers .assert_file_content (
78
78
annotation_import .input_file_url , predictions_with_confidence )
79
79
annotation_import .wait_until_done ()
80
+
80
81
assert annotation_import .state == AnnotationImportState .FINISHED
81
82
annotation_import_test_helpers .download_and_assert_status (
82
83
annotation_import .status_file_url )
83
84
84
85
85
86
def 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 ,
87
89
annotation_import_test_helpers ):
88
90
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 )
89
94
90
95
annotation_import = model_run_with_all_project_labels .add_predictions (
91
96
name = name , predictions = object_predictions )
@@ -96,13 +101,18 @@ def test_create_from_objects_all_project_labels(
96
101
annotation_import .input_file_url , object_predictions )
97
102
annotation_import .wait_until_done ()
98
103
104
+ assert annotation_import .state == AnnotationImportState .FINISHED
105
+ annotation_import_test_helpers .download_and_assert_status (
106
+ annotation_import .status_file_url )
107
+
99
108
100
109
def test_model_run_project_labels (model_run_with_all_project_labels ,
101
110
model_run_predictions ):
102
111
model_run = model_run_with_all_project_labels
103
112
# TODO: Move to export_v2
104
113
model_run_exported_labels = model_run .export_labels (download = True )
105
114
labels_indexed_by_schema_id = {}
115
+
106
116
for label in model_run_exported_labels :
107
117
# assuming exported array of label 'objects' has only one label per data row... as usually is when there are no label revisions
108
118
schema_id = label ['Label' ]['objects' ][0 ]['schemaId' ]
@@ -121,11 +131,17 @@ def test_model_run_project_labels(model_run_with_all_project_labels,
121
131
assert actual_label ['DataRow ID' ] == expected_label ['dataRow' ]['id' ]
122
132
123
133
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 ,
125
136
annotation_import_test_helpers ):
126
137
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 )
127
142
128
- predictions = list (NDJsonConverter .deserialize (object_predictions ))
143
+ predictions = list (
144
+ NDJsonConverter .deserialize (object_predictions_for_annotation_import ))
129
145
130
146
annotation_import = model_run_with_data_rows .add_predictions (
131
147
name = name , predictions = predictions )
@@ -137,25 +153,39 @@ def test_create_from_label_objects(model_run_with_data_rows, object_predictions,
137
153
annotation_import .input_file_url , normalized_predictions )
138
154
annotation_import .wait_until_done ()
139
155
156
+ assert annotation_import .state == AnnotationImportState .FINISHED
157
+ annotation_import_test_helpers .download_and_assert_status (
158
+ annotation_import .status_file_url )
159
+
140
160
141
161
def test_create_from_local_file (tmp_path , model_run_with_data_rows ,
142
- object_predictions ,
162
+ object_predictions_for_annotation_import ,
143
163
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
+
144
169
name = str (uuid .uuid4 ())
145
170
file_name = f"{ name } .ndjson"
146
171
file_path = tmp_path / file_name
147
172
with file_path .open ("w" ) as f :
148
- parser .dump (object_predictions , f )
173
+ parser .dump (object_predictions_for_annotation_import , f )
149
174
150
175
annotation_import = model_run_with_data_rows .add_predictions (
151
176
name = name , predictions = str (file_path ))
152
177
153
178
assert annotation_import .model_run_id == model_run_with_data_rows .uid
154
179
annotation_import_test_helpers .check_running_state (annotation_import , name )
155
180
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 )
157
183
annotation_import .wait_until_done ()
158
184
185
+ assert annotation_import .state == AnnotationImportState .FINISHED
186
+ annotation_import_test_helpers .download_and_assert_status (
187
+ annotation_import .status_file_url )
188
+
159
189
160
190
def test_get (client , model_run_with_data_rows , annotation_import_test_helpers ):
161
191
name = str (uuid .uuid4 ())
0 commit comments