@@ -291,6 +291,32 @@ def ontology():
291291 return {"tools" : tools , "classifications" : classifications }
292292
293293
294+ @pytest .fixture
295+ def wait_for_label_processing ():
296+ """
297+ Do not use. Only for testing.
298+
299+ Returns project's labels as a list after waiting for them to finish processing.
300+ If `project.labels()` is called before label is fully processed,
301+ it may return an empty set
302+ """
303+
304+ def func (project ):
305+ timeout_seconds = 10
306+ while True :
307+ labels = list (project .labels ())
308+ if len (labels ) > 0 :
309+ return labels
310+ timeout_seconds -= 2
311+ if timeout_seconds <= 0 :
312+ raise TimeoutError (
313+ f"Timed out waiting for label for project '{ project .uid } ' to finish processing"
314+ )
315+ time .sleep (2 )
316+
317+ return func
318+
319+
294320@pytest .fixture
295321def configured_project (client , ontology , rand_gen , image_url ):
296322 project = client .create_project (name = rand_gen (str ),
@@ -303,6 +329,7 @@ def configured_project(client, ontology, rand_gen, image_url):
303329 data_row_ids = []
304330 for _ in range (len (ontology ['tools' ]) + len (ontology ['classifications' ])):
305331 data_row_ids .append (dataset .create_data_row (row_data = image_url ).uid )
332+ project ._wait_until_data_rows_are_processed (data_row_ids = data_row_ids )
306333 project .datasets .connect (dataset )
307334 project .data_row_ids = data_row_ids
308335 yield project
@@ -321,6 +348,7 @@ def configured_project_pdf(client, ontology, rand_gen, pdf_url):
321348 project .setup (editor , ontology )
322349 data_row_ids = []
323350 data_row_ids .append (dataset .create_data_row (pdf_url ).uid )
351+ project ._wait_until_data_rows_are_processed (data_row_ids = data_row_ids )
324352 project .datasets .connect (dataset )
325353 project .data_row_ids = data_row_ids
326354 yield project
@@ -393,10 +421,10 @@ def polygon_inference(prediction_id_mapping):
393421 "y" : 118.154
394422 }, {
395423 "x" : 142.769 ,
396- "y" : 404 .923
424+ "y" : 104 .923
397425 }, {
398426 "x" : 57.846 ,
399- "y" : 318 .769
427+ "y" : 118 .769
400428 }, {
401429 "x" : 28.308 ,
402430 "y" : 169.846
@@ -413,8 +441,8 @@ def rectangle_inference(prediction_id_mapping):
413441 "bbox" : {
414442 "top" : 48 ,
415443 "left" : 58 ,
416- "height" : 865 ,
417- "width" : 1512
444+ "height" : 65 ,
445+ "width" : 12
418446 },
419447 'classifications' : [{
420448 "schemaId" :
@@ -615,14 +643,20 @@ def model_run_with_training_metadata(rand_gen, model):
615643
616644@pytest .fixture
617645def model_run_with_model_run_data_rows (client , configured_project ,
618- model_run_predictions , model_run ):
646+ model_run_predictions , model_run ,
647+ wait_for_label_processing ):
619648 configured_project .enable_model_assisted_labeling ()
620649
621650 upload_task = LabelImport .create_from_objects (
622651 client , configured_project .uid , f"label-import-{ uuid .uuid4 ()} " ,
623652 model_run_predictions )
624653 upload_task .wait_until_done ()
625- label_ids = [label .uid for label in configured_project .labels ()]
654+ assert upload_task .state == AnnotationImportState .FINISHED , "Label Import did not finish"
655+ assert len (
656+ upload_task .errors
657+ ) == 0 , f"Label Import { upload_task .name } failed with errors { upload_task .errors } "
658+ labels = wait_for_label_processing (configured_project )
659+ label_ids = [label .uid for label in labels ]
626660 model_run .upsert_labels (label_ids )
627661 time .sleep (3 )
628662 yield model_run
@@ -632,13 +666,19 @@ def model_run_with_model_run_data_rows(client, configured_project,
632666
633667@pytest .fixture
634668def model_run_with_all_project_labels (client , configured_project ,
635- model_run_predictions , model_run ):
669+ model_run_predictions , model_run ,
670+ wait_for_label_processing ):
636671 configured_project .enable_model_assisted_labeling ()
637672
638673 upload_task = LabelImport .create_from_objects (
639674 client , configured_project .uid , f"label-import-{ uuid .uuid4 ()} " ,
640675 model_run_predictions )
641676 upload_task .wait_until_done ()
677+ assert upload_task .state == AnnotationImportState .FINISHED , "Label Import did not finish"
678+ assert len (
679+ upload_task .errors
680+ ) == 0 , f"Label Import { upload_task .name } failed with errors { upload_task .errors } "
681+ wait_for_label_processing (configured_project )
642682 model_run .upsert_labels (project_id = configured_project .uid )
643683 time .sleep (3 )
644684 yield model_run
0 commit comments