Skip to content

Commit db719ff

Browse files
author
Kevin Kim
committed
Make mea tests more reliable
1 parent 7746ed1 commit db719ff

File tree

1 file changed

+48
-7
lines changed

1 file changed

+48
-7
lines changed

tests/integration/annotation_import/conftest.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
295321
def 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,21 @@ def model_run_with_training_metadata(rand_gen, model):
615643

616644
@pytest.fixture
617645
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):
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]
660+
print(label_ids)
626661
model_run.upsert_labels(label_ids)
627662
time.sleep(3)
628663
yield model_run
@@ -632,13 +667,19 @@ def model_run_with_model_run_data_rows(client, configured_project,
632667

633668
@pytest.fixture
634669
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):
636672
configured_project.enable_model_assisted_labeling()
637673

638674
upload_task = LabelImport.create_from_objects(
639675
client, configured_project.uid, f"label-import-{uuid.uuid4()}",
640676
model_run_predictions)
641677
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)
642683
model_run.upsert_labels(project_id=configured_project.uid)
643684
time.sleep(3)
644685
yield model_run

0 commit comments

Comments
 (0)