Skip to content

Commit 4976908

Browse files
author
Val Brodsky
committed
Adding an option to configure source of data rows for predictions, also making ndjson test use project without datatows
1 parent b95d1b8 commit 4976908

File tree

3 files changed

+158
-63
lines changed

3 files changed

+158
-63
lines changed

tests/integration/annotation_import/conftest.py

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,27 @@ def initial_dataset(client, rand_gen):
486486

487487

488488
@pytest.fixture
489-
def configured_project(client, configured_project_without_data_rows,
490-
initial_dataset, ontology, rand_gen, image_url):
489+
def hardcoded_datarow_id():
490+
data_row_id = 'ck8q9q9qj00003g5z3q1q9q9q'
491+
492+
def get_data_row_id(indx=0):
493+
return data_row_id
494+
495+
yield get_data_row_id
496+
497+
498+
@pytest.fixture
499+
def configured_project_datarow_id(configured_project):
500+
501+
def get_data_row_id(indx=0):
502+
return configured_project.data_row_ids[indx]
503+
504+
yield get_data_row_id
505+
506+
507+
@pytest.fixture
508+
def configured_project(configured_project_without_data_rows, initial_dataset,
509+
ontology, rand_gen, image_url):
491510
start_time = time.time()
492511
dataset = initial_dataset
493512
project = configured_project_without_data_rows
@@ -509,6 +528,7 @@ def configured_project(client, configured_project_without_data_rows,
509528
)
510529
print("After creating batch ", time.time() - start_time)
511530
project.data_row_ids = data_row_ids
531+
512532
yield project
513533
project.delete()
514534

@@ -577,10 +597,19 @@ def configured_project_without_data_rows(client, ontology, rand_gen):
577597
# In an example of a 'rectangle' we have extended to support multiple instances of the same tool type
578598
# TODO: we will support this approach in the future for all tools
579599
@pytest.fixture
580-
def prediction_id_mapping(configured_project):
600+
def prediction_id_mapping(configured_project_without_data_rows, ontology,
601+
request):
581602
# Maps tool types to feature schema ids
582-
project = configured_project
603+
if 'configured_project' in request.fixturenames:
604+
data_row_id_factory = request.getfixturevalue(
605+
'configured_project_datarow_id')
606+
project = configured_project
607+
else:
608+
data_row_id_factory = request.getfixturevalue('hardcoded_datarow_id')
609+
project = configured_project_without_data_rows
610+
583611
ontology = project.ontology().normalized
612+
584613
result = {}
585614

586615
for idx, tool in enumerate(ontology['tools'] + ontology['classifications']):
@@ -597,7 +626,47 @@ def prediction_id_mapping(configured_project):
597626
"schemaId": tool['featureSchemaId'],
598627
"name": tool['name'],
599628
"dataRow": {
600-
"id": project.data_row_ids[idx],
629+
"id": data_row_id_factory(idx),
630+
},
631+
'tool': tool
632+
}
633+
if tool_type not in result:
634+
result[tool_type] = []
635+
result[tool_type].append(value)
636+
else:
637+
result[tool_type] = {
638+
"uuid": str(uuid.uuid4()),
639+
"schemaId": tool['featureSchemaId'],
640+
"name": tool['name'],
641+
"dataRow": {
642+
"id": data_row_id_factory(idx),
643+
},
644+
'tool': tool
645+
}
646+
return result
647+
648+
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,
601670
},
602671
'tool': tool
603672
}
@@ -610,7 +679,7 @@ def prediction_id_mapping(configured_project):
610679
"schemaId": tool['featureSchemaId'],
611680
"name": tool['name'],
612681
"dataRow": {
613-
"id": project.data_row_ids[idx],
682+
"id": data_row_id,
614683
},
615684
'tool': tool
616685
}

0 commit comments

Comments
 (0)