@@ -291,6 +291,32 @@ def ontology():
291
291
return {"tools" : tools , "classifications" : classifications }
292
292
293
293
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
+
294
320
@pytest .fixture
295
321
def configured_project (client , ontology , rand_gen , image_url ):
296
322
project = client .create_project (name = rand_gen (str ),
@@ -303,6 +329,7 @@ def configured_project(client, ontology, rand_gen, image_url):
303
329
data_row_ids = []
304
330
for _ in range (len (ontology ['tools' ]) + len (ontology ['classifications' ])):
305
331
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 )
306
333
project .datasets .connect (dataset )
307
334
project .data_row_ids = data_row_ids
308
335
yield project
@@ -321,6 +348,7 @@ def configured_project_pdf(client, ontology, rand_gen, pdf_url):
321
348
project .setup (editor , ontology )
322
349
data_row_ids = []
323
350
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 )
324
352
project .datasets .connect (dataset )
325
353
project .data_row_ids = data_row_ids
326
354
yield project
@@ -393,10 +421,10 @@ def polygon_inference(prediction_id_mapping):
393
421
"y" : 118.154
394
422
}, {
395
423
"x" : 142.769 ,
396
- "y" : 404 .923
424
+ "y" : 104 .923
397
425
}, {
398
426
"x" : 57.846 ,
399
- "y" : 318 .769
427
+ "y" : 118 .769
400
428
}, {
401
429
"x" : 28.308 ,
402
430
"y" : 169.846
@@ -413,8 +441,8 @@ def rectangle_inference(prediction_id_mapping):
413
441
"bbox" : {
414
442
"top" : 48 ,
415
443
"left" : 58 ,
416
- "height" : 865 ,
417
- "width" : 1512
444
+ "height" : 65 ,
445
+ "width" : 12
418
446
},
419
447
'classifications' : [{
420
448
"schemaId" :
@@ -615,14 +643,21 @@ def model_run_with_training_metadata(rand_gen, model):
615
643
616
644
@pytest .fixture
617
645
def 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 ):
619
648
configured_project .enable_model_assisted_labeling ()
620
649
621
650
upload_task = LabelImport .create_from_objects (
622
651
client , configured_project .uid , f"label-import-{ uuid .uuid4 ()} " ,
623
652
model_run_predictions )
624
653
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 ]
660
+ print (label_ids )
626
661
model_run .upsert_labels (label_ids )
627
662
time .sleep (3 )
628
663
yield model_run
@@ -632,13 +667,19 @@ def model_run_with_model_run_data_rows(client, configured_project,
632
667
633
668
@pytest .fixture
634
669
def model_run_with_all_project_labels (client , configured_project ,
635
- model_run_predictions , model_run ):
670
+ model_run_predictions , model_run ,
671
+ wait_for_label_processing ):
636
672
configured_project .enable_model_assisted_labeling ()
637
673
638
674
upload_task = LabelImport .create_from_objects (
639
675
client , configured_project .uid , f"label-import-{ uuid .uuid4 ()} " ,
640
676
model_run_predictions )
641
677
upload_task .wait_until_done ()
678
+ assert upload_task .state == AnnotationImportState .FINISHED , "Label Import did not finish"
679
+ assert len (
680
+ upload_task .errors
681
+ ) == 0 , f"Label Import { upload_task .name } failed with errors { upload_task .errors } "
682
+ wait_for_label_processing (configured_project )
642
683
model_run .upsert_labels (project_id = configured_project .uid )
643
684
time .sleep (3 )
644
685
yield model_run
0 commit comments