55
66import labelbox as lb
77from labelbox .data .annotation_types .data .video import VideoData
8- from labelbox .schema .data_row import DataRow
98from labelbox .schema .media_type import MediaType
109import labelbox .types as lb_types
1110from labelbox .data .annotation_types .data import (
7069]
7170
7271
73- def remove_keys_recursive (d , keys ):
74- for k in keys :
75- if k in d :
76- del d [k ]
77- for k , v in d .items ():
78- if isinstance (v , dict ):
79- remove_keys_recursive (v , keys )
80- elif isinstance (v , list ):
81- for i in v :
82- if isinstance (i , dict ):
83- remove_keys_recursive (i , keys )
84-
85-
86- # NOTE this uses quite a primitive check for cuids but I do not think it is worth coming up with a better one
87- # Also this function is NOT written with performance in mind, good for small to mid size dicts like we have in our test
88- def rename_cuid_key_recursive (d ):
89- new_key = "<cuid>"
90- for k in list (d .keys ()):
91- if len (k ) == 25 and not k .isalpha (): # primitive check for cuid
92- d [new_key ] = d .pop (k )
93- for k , v in d .items ():
94- if isinstance (v , dict ):
95- rename_cuid_key_recursive (v )
96- elif isinstance (v , list ):
97- for i in v :
98- if isinstance (i , dict ):
99- rename_cuid_key_recursive (i )
100-
101-
10272def get_annotation_comparison_dicts_from_labels (labels ):
10373 labels_ndjson = list (NDJsonConverter .serialize (labels ))
10474 for annotation in labels_ndjson :
@@ -161,19 +131,6 @@ def get_annotation_comparison_dicts_from_export(export_result, data_row_id,
161131 return converted_annotations
162132
163133
164- def create_data_row_for_project (project , dataset , data_row_ndjson , batch_name ):
165- data_row = dataset .create_data_row (data_row_ndjson )
166-
167- project .create_batch (
168- batch_name ,
169- [data_row .uid ], # sample of data row objects
170- 5 , # priority between 1(Highest) - 5(lowest)
171- )
172- project .data_row_ids .append (data_row .uid )
173-
174- return data_row
175-
176-
177134# TODO: Add VideoData. Currently label import job finishes without errors but project.export_labels() returns empty list.
178135@pytest .mark .parametrize (
179136 "data_type_class" ,
@@ -190,15 +147,10 @@ def create_data_row_for_project(project, dataset, data_row_ndjson, batch_name):
190147 LlmResponseCreationData ,
191148 ],
192149)
193- def test_import_data_types (
194- client ,
195- configured_project ,
196- initial_dataset ,
197- rand_gen ,
198- data_row_json_by_data_type ,
199- annotations_by_data_type ,
200- data_type_class ,
201- ):
150+ def test_import_data_types (client , configured_project , initial_dataset ,
151+ rand_gen , data_row_json_by_data_type ,
152+ annotations_by_data_type , data_type_class ,
153+ create_data_row_for_project ):
202154 project = configured_project
203155 project_id = project .uid
204156 dataset = initial_dataset
@@ -241,6 +193,7 @@ def test_import_data_types_by_global_key(
241193 rand_gen ,
242194 data_row_json_by_data_type ,
243195 annotations_by_data_type ,
196+ create_data_row_for_project ,
244197):
245198 project = configured_project
246199 project_id = project .uid
@@ -331,6 +284,8 @@ def test_import_data_types_v2(
331284 exports_v2_by_data_type ,
332285 export_v2_test_helpers ,
333286 rand_gen ,
287+ helpers ,
288+ create_data_row_for_project ,
334289):
335290 project = configured_project
336291 dataset = initial_dataset
@@ -381,9 +336,9 @@ def test_import_data_types_v2(
381336 exported_project_labels = exported_project ["labels" ][0 ]
382337 exported_annotations = exported_project_labels ["annotations" ]
383338
384- remove_keys_recursive (exported_annotations ,
385- ["feature_id" , "feature_schema_id" ])
386- rename_cuid_key_recursive (exported_annotations )
339+ helpers . remove_keys_recursive (exported_annotations ,
340+ ["feature_id" , "feature_schema_id" ])
341+ helpers . rename_cuid_key_recursive (exported_annotations )
387342 assert exported_annotations == exports_v2_by_data_type [data_type_string ]
388343
389344 data_row = client .get_data_row (data_row .uid )
@@ -400,6 +355,7 @@ def test_import_label_annotations(
400355 data_class ,
401356 annotations ,
402357 rand_gen ,
358+ create_data_row_for_project ,
403359):
404360 project = configured_project_with_one_data_row
405361 dataset = initial_dataset
0 commit comments