Skip to content

Commit 551c1ef

Browse files
author
Val Brodsky
committed
Replacing configured_project
1 parent 4976908 commit 551c1ef

14 files changed

+194
-197
lines changed

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[pytest]
2-
addopts = -s -vv
2+
addopts = -s -vv --reruns 5 --reruns-delay 10 --durations=20
33
markers =
44
slow: marks tests as slow (deselect with '-m "not slow"')

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
]
1313

1414

15-
@pytest.fixture
15+
@pytest.fixture(scope="session")
1616
def rand_gen():
1717

1818
def gen(field_type):

tests/integration/annotation_import/conftest.py

Lines changed: 50 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def annotations_by_data_type_v2(
211211
}
212212

213213

214-
@pytest.fixture
214+
@pytest.fixture(scope='session')
215215
def ontology():
216216
bbox_tool_with_nested_text = {
217217
'required':
@@ -479,48 +479,45 @@ def func(project):
479479

480480

481481
@pytest.fixture
482-
def initial_dataset(client, rand_gen):
483-
dataset = client.create_dataset(name=rand_gen(str))
484-
yield dataset
485-
dataset.delete()
486-
487-
488-
@pytest.fixture
489-
def hardcoded_datarow_id():
490-
data_row_id = 'ck8q9q9qj00003g5z3q1q9q9q'
482+
def configured_project_datarow_id(configured_project):
491483

492484
def get_data_row_id(indx=0):
493-
return data_row_id
485+
return configured_project.data_row_ids[indx]
494486

495487
yield get_data_row_id
496488

497489

498490
@pytest.fixture
499-
def configured_project_datarow_id(configured_project):
491+
def configured_project_one_datarow_id(configured_project_with_one_data_row):
500492

501493
def get_data_row_id(indx=0):
502-
return configured_project.data_row_ids[indx]
494+
return configured_project_with_one_data_row.data_row_ids[0]
503495

504496
yield get_data_row_id
505497

506498

507499
@pytest.fixture
508-
def configured_project(configured_project_without_data_rows, initial_dataset,
509-
ontology, rand_gen, image_url):
500+
def configured_project(client, initial_dataset, ontology, rand_gen, image_url):
510501
start_time = time.time()
511502
dataset = initial_dataset
512-
project = configured_project_without_data_rows
503+
project = client.create_project(name=rand_gen(str),
504+
queue_mode=QueueMode.Batch)
505+
editor = list(
506+
client.get_labeling_frontends(
507+
where=LabelingFrontend.name == "editor"))[0]
508+
project.setup(editor, ontology)
509+
num_rows = 0
513510

514511
data_row_ids = []
515-
# print("Before creating data rows ", time.time() - start_time)
516-
num_rows = 0
512+
517513
for _ in range(len(ontology['tools']) + len(ontology['classifications'])):
518514
data_row_ids.append(dataset.create_data_row(row_data=image_url).uid)
519515
num_rows += 1
520-
# print("After creating data rows ", time.time() - start_time)
521-
522-
pytest.data_row_report['times'] += time.time() - start_time
523-
pytest.data_row_report['num_rows'] += num_rows
516+
project._wait_until_data_rows_are_processed(data_row_ids=data_row_ids,
517+
sleep_interval=3)
518+
if pytest.data_row_report:
519+
pytest.data_row_report['times'] += time.time() - start_time
520+
pytest.data_row_report['num_rows'] += num_rows
524521
project.create_batch(
525522
rand_gen(str),
526523
data_row_ids, # sample of data row objects
@@ -580,15 +577,36 @@ def dataset_conversation_entity(client, rand_gen, conversation_entity_data_row,
580577

581578

582579
@pytest.fixture
583-
def configured_project_without_data_rows(client, ontology, rand_gen):
580+
def configured_project_with_one_data_row(client, ontology, rand_gen,
581+
initial_dataset, image_url):
582+
start_time = time.time()
583+
584584
project = client.create_project(name=rand_gen(str),
585585
description=rand_gen(str),
586586
queue_mode=QueueMode.Batch)
587587
editor = list(
588588
client.get_labeling_frontends(
589589
where=LabelingFrontend.name == "editor"))[0]
590590
project.setup(editor, ontology)
591+
592+
data_row = initial_dataset.create_data_row(row_data=image_url)
593+
data_row_ids = [data_row.uid]
594+
project._wait_until_data_rows_are_processed(data_row_ids=data_row_ids,
595+
sleep_interval=3)
596+
597+
if pytest.data_row_report:
598+
pytest.data_row_report['times'] += time.time() - start_time
599+
pytest.data_row_report['num_rows'] += 1
600+
batch = project.create_batch(
601+
rand_gen(str),
602+
data_row_ids, # sample of data row objects
603+
5 # priority between 1(Highest) - 5(lowest)
604+
)
605+
project.data_row_ids = data_row_ids
606+
591607
yield project
608+
609+
batch.delete()
592610
project.delete()
593611

594612

@@ -597,16 +615,20 @@ def configured_project_without_data_rows(client, ontology, rand_gen):
597615
# In an example of a 'rectangle' we have extended to support multiple instances of the same tool type
598616
# TODO: we will support this approach in the future for all tools
599617
@pytest.fixture
600-
def prediction_id_mapping(configured_project_without_data_rows, ontology,
601-
request):
618+
def prediction_id_mapping(ontology, request):
602619
# Maps tool types to feature schema ids
603620
if 'configured_project' in request.fixturenames:
604621
data_row_id_factory = request.getfixturevalue(
605622
'configured_project_datarow_id')
606-
project = configured_project
607-
else:
623+
project = request.getfixturevalue('configured_project')
624+
elif 'hardcoded_datarow_id' in request.fixturenames:
608625
data_row_id_factory = request.getfixturevalue('hardcoded_datarow_id')
609-
project = configured_project_without_data_rows
626+
project = request.getfixturevalue('configured_project_with_ontology')
627+
else:
628+
data_row_id_factory = request.getfixturevalue(
629+
'configured_project_one_datarow_id')
630+
project = request.getfixturevalue(
631+
'configured_project_with_one_data_row')
610632

611633
ontology = project.ontology().normalized
612634

@@ -646,46 +668,6 @@ def prediction_id_mapping(configured_project_without_data_rows, ontology,
646668
return result
647669

648670

649-
@pytest.fixture
650-
def prediction_id_mapping_datarow_id():
651-
# Maps tool types to feature schema ids
652-
data_row_id = 'ck8q9q9qj00003g5z3q1q9q9q'
653-
result = {}
654-
655-
for _, tool in enumerate(ontology['tools'] + ontology['classifications']):
656-
if 'tool' in tool:
657-
tool_type = tool['tool']
658-
else:
659-
tool_type = tool[
660-
'type'] if 'scope' not in tool else f"{tool['type']}_{tool['scope']}" # so 'checklist' of 'checklist_index'
661-
662-
# TODO: remove this once we have a better way to associate multiple tools instances with a single tool type
663-
if tool_type == 'rectangle':
664-
value = {
665-
"uuid": str(uuid.uuid4()),
666-
"schemaId": tool['featureSchemaId'],
667-
"name": tool['name'],
668-
"dataRow": {
669-
"id": data_row_id,
670-
},
671-
'tool': tool
672-
}
673-
if tool_type not in result:
674-
result[tool_type] = []
675-
result[tool_type].append(value)
676-
else:
677-
result[tool_type] = {
678-
"uuid": str(uuid.uuid4()),
679-
"schemaId": tool['featureSchemaId'],
680-
"name": tool['name'],
681-
"dataRow": {
682-
"id": data_row_id,
683-
},
684-
'tool': tool
685-
}
686-
return result
687-
688-
689671
@pytest.fixture
690672
def polygon_inference(prediction_id_mapping):
691673
polygon = prediction_id_mapping['polygon'].copy()
@@ -1079,7 +1061,6 @@ def model_run_with_training_metadata(rand_gen, model):
10791061
@pytest.fixture
10801062
def model_run_with_data_rows(client, configured_project, model_run_predictions,
10811063
model_run, wait_for_label_processing):
1082-
start_time = time.time()
10831064
configured_project.enable_model_assisted_labeling()
10841065

10851066
upload_task = LabelImport.create_from_objects(
@@ -1093,7 +1074,6 @@ def model_run_with_data_rows(client, configured_project, model_run_predictions,
10931074
labels = wait_for_label_processing(configured_project)
10941075
label_ids = [label.uid for label in labels]
10951076
model_run.upsert_labels(label_ids)
1096-
print(f"model_run_with_data_rows: {time.time() - start_time}")
10971077
yield model_run
10981078
model_run.delete()
10991079
# TODO: Delete resources when that is possible ..

tests/integration/annotation_import/test_bulk_import_request.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ def test_validate_file(project_with_ontology):
5151
#Schema ids shouldn't match
5252

5353

54-
def test_create_from_objects(configured_project_without_data_rows, predictions,
54+
def test_create_from_objects(configured_project_with_one_data_row, predictions,
5555
annotation_import_test_helpers):
5656
name = str(uuid.uuid4())
5757

58-
bulk_import_request = configured_project_without_data_rows.upload_annotations(
58+
bulk_import_request = configured_project_with_one_data_row.upload_annotations(
5959
name=name, annotations=predictions)
6060

61-
assert bulk_import_request.project() == configured_project_without_data_rows
61+
assert bulk_import_request.project() == configured_project_with_one_data_row
6262
assert bulk_import_request.name == name
6363
assert bulk_import_request.error_file_url is None
6464
assert bulk_import_request.status_file_url is None
@@ -105,34 +105,33 @@ def test_create_from_local_file(tmp_path, predictions, configured_project,
105105
bulk_import_request.input_file_url, predictions)
106106

107107

108-
def test_get(client, configured_project_without_data_rows):
108+
def test_get(client, configured_project_with_one_data_row):
109109
name = str(uuid.uuid4())
110110
url = "https://storage.googleapis.com/labelbox-public-bucket/predictions_test_v2.ndjson"
111-
configured_project_without_data_rows.upload_annotations(name=name,
111+
configured_project_with_one_data_row.upload_annotations(name=name,
112112
annotations=url,
113113
validate=False)
114114

115115
bulk_import_request = BulkImportRequest.from_name(
116-
client, project_id=configured_project_without_data_rows.uid, name=name)
116+
client, project_id=configured_project_with_one_data_row.uid, name=name)
117117

118-
assert bulk_import_request.project() == configured_project_without_data_rows
118+
assert bulk_import_request.project() == configured_project_with_one_data_row
119119
assert bulk_import_request.name == name
120120
assert bulk_import_request.input_file_url == url
121121
assert bulk_import_request.error_file_url is None
122122
assert bulk_import_request.status_file_url is None
123123
assert bulk_import_request.state == BulkImportRequestState.RUNNING
124124

125125

126-
def test_validate_ndjson(tmp_path, configured_project):
126+
def test_validate_ndjson(tmp_path, configured_project_with_one_data_row):
127127
file_name = f"broken.ndjson"
128128
file_path = tmp_path / file_name
129129
with file_path.open("w") as f:
130130
f.write("test")
131131

132132
with pytest.raises(ValueError):
133-
configured_project.upload_annotations(name="name",
134-
validate=True,
135-
annotations=str(file_path))
133+
configured_project_with_one_data_row.upload_annotations(
134+
name="name", validate=True, annotations=str(file_path))
136135

137136

138137
def test_validate_ndjson_uuid(tmp_path, configured_project, predictions):
@@ -159,11 +158,11 @@ def test_validate_ndjson_uuid(tmp_path, configured_project, predictions):
159158

160159
@pytest.mark.slow
161160
def test_wait_till_done(rectangle_inference,
162-
configured_project_without_data_rows):
161+
configured_project_with_one_data_row):
163162
name = str(uuid.uuid4())
164-
url = configured_project_without_data_rows.client.upload_data(
163+
url = configured_project_with_one_data_row.client.upload_data(
165164
content=parser.dumps([rectangle_inference]), sign=True)
166-
bulk_import_request = configured_project_without_data_rows.upload_annotations(
165+
bulk_import_request = configured_project_with_one_data_row.upload_annotations(
167166
name=name, annotations=url, validate=False)
168167

169168
assert len(bulk_import_request.inputs) == 1
@@ -298,7 +297,7 @@ def test_pdf_mal_bbox(client, configured_project_pdf):
298297
assert import_annotations.errors == []
299298

300299

301-
def test_pdf_document_entity(client, configured_project_without_data_rows,
300+
def test_pdf_document_entity(client, configured_project_with_one_data_row,
302301
dataset_pdf_entity, rand_gen):
303302
# for content "Metal-insulator (MI) transitions have been one of the" in OCR JSON extract tests/assets/arxiv-pdf_data_99-word-token-pdfs_0801.3483-lb-textlayer.json
304303
document_text_selection = DocumentTextSelection(
@@ -322,7 +321,7 @@ def test_pdf_document_entity(client, configured_project_without_data_rows,
322321

323322
labels = []
324323
_, data_row_uids = dataset_pdf_entity
325-
configured_project_without_data_rows.create_batch(
324+
configured_project_with_one_data_row.create_batch(
326325
rand_gen(str),
327326
data_row_uids, # sample of data row objects
328327
5 # priority between 1(Highest) - 5(lowest)
@@ -337,7 +336,7 @@ def test_pdf_document_entity(client, configured_project_without_data_rows,
337336

338337
import_annotations = MALPredictionImport.create_from_objects(
339338
client=client,
340-
project_id=configured_project_without_data_rows.uid,
339+
project_id=configured_project_with_one_data_row.uid,
341340
name=f"import {str(uuid.uuid4())}",
342341
predictions=labels)
343342
import_annotations.wait_until_done()
@@ -346,14 +345,14 @@ def test_pdf_document_entity(client, configured_project_without_data_rows,
346345

347346

348347
def test_nested_video_object_annotations(client,
349-
configured_project_without_data_rows,
348+
configured_project_with_one_data_row,
350349
video_data,
351350
bbox_video_annotation_objects,
352351
rand_gen):
353352
labels = []
354353
_, data_row_uids = video_data
355-
configured_project_without_data_rows.update(media_type=MediaType.Video)
356-
configured_project_without_data_rows.create_batch(
354+
configured_project_with_one_data_row.update(media_type=MediaType.Video)
355+
configured_project_with_one_data_row.create_batch(
357356
rand_gen(str),
358357
data_row_uids, # sample of data row objects
359358
5 # priority between 1(Highest) - 5(lowest)
@@ -365,7 +364,7 @@ def test_nested_video_object_annotations(client,
365364
annotations=bbox_video_annotation_objects))
366365
import_annotations = MALPredictionImport.create_from_objects(
367366
client=client,
368-
project_id=configured_project_without_data_rows.uid,
367+
project_id=configured_project_with_one_data_row.uid,
369368
name=f"import {str(uuid.uuid4())}",
370369
predictions=labels)
371370
import_annotations.wait_until_done()

tests/integration/annotation_import/test_conversation_import.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from labelbox.schema.annotation_import import MALPredictionImport
88

99

10-
def test_conversation_entity(client, configured_project_without_data_rows,
10+
def test_conversation_entity(client, configured_project_with_one_data_row,
1111
dataset_conversation_entity, rand_gen):
1212

1313
conversation_entity_annotation = ConversationEntity(start=0,
@@ -20,7 +20,7 @@ def test_conversation_entity(client, configured_project_without_data_rows,
2020
labels = []
2121
_, data_row_uids = dataset_conversation_entity
2222

23-
configured_project_without_data_rows.create_batch(
23+
configured_project_with_one_data_row.create_batch(
2424
rand_gen(str),
2525
data_row_uids, # sample of data row objects
2626
5 # priority between 1(Highest) - 5(lowest)
@@ -35,7 +35,7 @@ def test_conversation_entity(client, configured_project_without_data_rows,
3535

3636
import_annotations = MALPredictionImport.create_from_objects(
3737
client=client,
38-
project_id=configured_project_without_data_rows.uid,
38+
project_id=configured_project_with_one_data_row.uid,
3939
name=f"import {str(uuid.uuid4())}",
4040
predictions=labels)
4141

0 commit comments

Comments
 (0)