Skip to content

Commit 10840ce

Browse files
authored
Swapped/marked remaining V1 methods in tests (#1679)
1 parent 76d6217 commit 10840ce

File tree

8 files changed

+47
-27
lines changed

8 files changed

+47
-27
lines changed

libs/labelbox/tests/data/annotation_import/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ def get_data_row_id(indx=0):
608608

609609
yield get_data_row_id
610610

611-
611+
#TODO: Switch to setup_editor, setup might get removed in later releases
612612
@pytest.fixture
613613
def configured_project(client, initial_dataset, ontology, rand_gen, image_url):
614614
dataset = initial_dataset
@@ -642,7 +642,7 @@ def configured_project(client, initial_dataset, ontology, rand_gen, image_url):
642642

643643
project.delete()
644644

645-
645+
#TODO: Switch to setup_editor, setup might get removed in later releases
646646
@pytest.fixture
647647
def project_with_ontology(client, configured_project, ontology, rand_gen):
648648
project = client.create_project(name=rand_gen(str),
@@ -657,7 +657,7 @@ def project_with_ontology(client, configured_project, ontology, rand_gen):
657657

658658
project.delete()
659659

660-
660+
#TODO: Switch to setup_editor, setup might get removed in later releases
661661
@pytest.fixture
662662
def configured_project_pdf(client, ontology, rand_gen, pdf_url):
663663
project = client.create_project(name=rand_gen(str),

libs/labelbox/tests/data/annotation_import/test_bulk_import_request.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from unittest.mock import patch
22
import uuid
3-
from labelbox import parser
3+
from labelbox import parser, Project
44
import pytest
55
import random
66
from labelbox.data.annotation_types.annotation import ObjectAnnotation
@@ -217,20 +217,20 @@ def test_delete(configured_project, predictions):
217217
assert len(list(all_import_requests)) == 0
218218

219219

220-
def test_pdf_mal_bbox(client, configured_project_pdf):
220+
def test_pdf_mal_bbox(client, configured_project_pdf:Project):
221221
"""
222222
tests pdf mal against only a bbox annotation
223223
"""
224224
annotations = []
225225
num_annotations = 1
226226

227-
for row in configured_project_pdf.export_queued_data_rows():
227+
for data_row_id in configured_project_pdf.data_row_ids:
228228
for _ in range(num_annotations):
229229
annotations.append({
230230
"uuid": str(uuid.uuid4()),
231231
"name": "bbox",
232232
"dataRow": {
233-
"id": row['id']
233+
"id": data_row_id
234234
},
235235
"bbox": {
236236
"top": round(random.uniform(0, 300), 2),
@@ -247,14 +247,14 @@ def test_pdf_mal_bbox(client, configured_project_pdf):
247247
'answer': 'the answer to the text question',
248248
'uuid': 'fc1913c6-b735-4dea-bd25-c18152a4715f',
249249
"dataRow": {
250-
"id": row['id']
250+
"id": data_row_id
251251
}
252252
},
253253
{
254254
'name': 'checklist',
255255
'uuid': '9d7b2e57-d68f-4388-867a-af2a9b233719',
256256
"dataRow": {
257-
"id": row['id']
257+
"id": data_row_id
258258
},
259259
'answer': [{
260260
'name': 'option1'
@@ -269,14 +269,14 @@ def test_pdf_mal_bbox(client, configured_project_pdf):
269269
},
270270
'uuid': 'ad60897f-ea1a-47de-b923-459339764921',
271271
"dataRow": {
272-
"id": row['id']
272+
"id": data_row_id
273273
}
274274
},
275275
{ #adding this with the intention to ensure we allow page: 0
276276
"uuid": str(uuid.uuid4()),
277277
"name": "bbox",
278278
"dataRow": {
279-
"id": row['id']
279+
"id": data_row_id
280280
},
281281
"bbox": {
282282
"top": round(random.uniform(0, 300), 2),

libs/labelbox/tests/data/annotation_import/test_data_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def create_data_row_for_project(project, dataset, data_row_ndjson, batch_name):
145145

146146

147147
# TODO: Add VideoData. Currently label import job finishes without errors but project.export_labels() returns empty list.
148+
@pytest.mark.export_v1("tests used export v1 method, v2 test -> test_import_data_types_v2 below")
148149
@pytest.mark.parametrize(
149150
"data_type_class",
150151
[

libs/labelbox/tests/data/annotation_import/test_mea_prediction_import.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import uuid
22
from labelbox import parser
33
import pytest
4+
from labelbox import ModelRun
45

56
from labelbox.schema.annotation_import import AnnotationImportState, MEAPredictionImport
67
from labelbox.data.serialization import NDJsonConverter
@@ -107,29 +108,38 @@ def test_create_from_objects_all_project_labels(
107108
annotation_import.status_file_url)
108109

109110

110-
def test_model_run_project_labels(model_run_with_all_project_labels,
111+
def test_model_run_project_labels(model_run_with_all_project_labels: ModelRun,
111112
model_run_predictions):
112113
model_run = model_run_with_all_project_labels
113-
# TODO: Move to export_v2
114-
model_run_exported_labels = model_run.export_labels(download=True)
114+
115+
export_task = model_run.export()
116+
export_task.wait_till_done()
117+
stream = export_task.get_buffered_stream()
118+
119+
# exports to list of tuples (data_row_id, label) needed to adapt test to export v2 instead of export v1 since data rows ids are not at label level in export v2.
120+
model_run_exported_labels = [(
121+
data_row.json["data_row"]["id"],
122+
data_row.json["experiments"][model_run.model_id]["runs"][model_run.uid]["labels"][0])
123+
for data_row in stream]
124+
115125
labels_indexed_by_schema_id = {}
116126

117-
for label in model_run_exported_labels:
127+
for data_row_id, label in model_run_exported_labels:
118128
# assuming exported array of label 'objects' has only one label per data row... as usually is when there are no label revisions
119-
schema_id = label['Label']['objects'][0]['schemaId']
120-
labels_indexed_by_schema_id[schema_id] = label
129+
schema_id = label["annotations"]["objects"][0]["feature_schema_id"]
130+
labels_indexed_by_schema_id[schema_id] = {"label": label, "data_row_id": data_row_id}
121131

122132
assert (len(
123133
labels_indexed_by_schema_id.keys())) == len(model_run_predictions)
124134

125135
# making sure the labels are in this model run are all labels uploaded to the project
126136
# by comparing some 'immutable' attributes
127137
for expected_label in model_run_predictions:
128-
schema_id = expected_label['schemaId']
138+
schema_id = expected_label["schemaId"]
129139
actual_label = labels_indexed_by_schema_id[schema_id]
130-
assert actual_label['Label']['objects'][0]['title'] == expected_label[
140+
assert actual_label["label"]["annotations"]["objects"][0]["name"] == expected_label[
131141
'name']
132-
assert actual_label['DataRow ID'] == expected_label['dataRow']['id']
142+
assert actual_label["data_row_id"] == expected_label["dataRow"]["id"]
133143

134144

135145
def test_create_from_label_objects(model_run_with_data_rows,

libs/labelbox/tests/data/annotation_import/test_model_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_model_run_upsert_data_rows_with_existing_labels(
119119
assert n_data_rows == len(
120120
list(model_run_with_data_rows.model_run_data_rows()))
121121

122-
122+
@pytest.mark.export_v1("tests used export v1 method, v2 test -> test_import_data_types_v2 below")
123123
def test_model_run_export_labels(model_run_with_data_rows):
124124
labels = model_run_with_data_rows.export_labels(download=True)
125125
assert len(labels) == 3

libs/labelbox/tests/data/annotation_import/test_send_to_annotate_mea.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,14 @@ def test_send_to_annotate_from_model(client, configured_project,
5656
destination_batches = list(destination_project.batches())
5757
assert len(destination_batches) == 1
5858

59-
destination_data_rows = list(destination_batches[0].export_data_rows())
59+
export_task = destination_project.export()
60+
export_task.wait_till_done()
61+
stream = export_task.get_buffered_stream()
62+
63+
destination_data_rows = [dr.json["data_row"]["id"] for dr in stream]
64+
6065
assert len(destination_data_rows) == len(data_row_ids)
61-
assert all([dr.uid in data_row_ids for dr in destination_data_rows])
66+
assert all([dr in data_row_ids for dr in destination_data_rows])
6267

6368
# Since data rows were added to a review queue, predictions should be imported into the project as labels
6469
destination_project_labels = (list(destination_project.labels()))

libs/labelbox/tests/data/export/streamable/test_export_project_streamable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def test_batch(
313313
},
314314
] * 2)
315315
task.wait_till_done()
316-
data_rows = [dr.uid for dr in list(dataset.export_data_rows())]
316+
data_rows = [result["id"] for result in task.result]
317317
batch_one = f"batch one {uuid.uuid4()}"
318318

319319
# This test creates two batches, only one batch should be exporter

libs/labelbox/tests/data/test_data_row_metadata.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@ def test_export_empty_metadata(client, configured_project_with_label,
9090
wait_for_data_row_processing):
9191
project, _, data_row, _ = configured_project_with_label
9292
data_row = wait_for_data_row_processing(client, data_row)
93-
labels = project.label_generator()
94-
label = next(labels)
95-
assert label.data.metadata == []
93+
94+
export_task = project.export(params={"metadata_fields": True})
95+
export_task.wait_till_done()
96+
stream = export_task.get_buffered_stream()
97+
data_row = [data_row.json for data_row in stream][0]
98+
99+
assert data_row["metadata_fields"] == []
96100

97101

98102
def test_bulk_export_datarow_metadata(data_row, mdo: DataRowMetadataOntology):

0 commit comments

Comments
 (0)