@@ -311,47 +311,9 @@ def configured_project_with_label(client, rand_gen, image_url, project, dataset,
311311 One label is already created and yielded when using fixture
312312 """
313313 project .datasets .connect (dataset )
314- editor = list (
315- project .client .get_labeling_frontends (
316- where = LabelingFrontend .name == "editor" ))[0 ]
317-
318- ontology_builder = OntologyBuilder (tools = [
319- Tool (tool = Tool .Type .BBOX , name = "test-bbox-class" ),
320- ])
321- project .setup (editor , ontology_builder .asdict ())
322- # TODO: ontology may not be synchronous after setup. remove sleep when api is more consistent
323- time .sleep (2 )
324-
325- ontology = ontology_builder .from_project (project )
326- predictions = [{
327- "uuid" : str (uuid .uuid4 ()),
328- "schemaId" : ontology .tools [0 ].feature_schema_id ,
329- "dataRow" : {
330- "id" : datarow .uid
331- },
332- "bbox" : {
333- "top" : 20 ,
334- "left" : 20 ,
335- "height" : 50 ,
336- "width" : 50
337- }
338- }]
339-
340- def create_label ():
341- """ Ad-hoc function to create a LabelImport
342- Creates a LabelImport task which will create a label
343- """
344- upload_task = LabelImport .create_from_objects (
345- client , project .uid , f'label-import-{ uuid .uuid4 ()} ' , predictions )
346- upload_task .wait_until_done (sleep_time_seconds = 5 )
347- assert upload_task .state == AnnotationImportState .FINISHED , "Label Import did not finish"
348- assert len (
349- upload_task .errors
350- ) == 0 , f"Label Import { upload_task .name } failed with errors { upload_task .errors } "
351314
352- project .create_label = create_label
353- project .create_label ()
354- label = wait_for_label_processing (project )[0 ]
315+ ontology = _setup_ontology (project )
316+ label = _create_label (project , datarow , ontology , wait_for_label_processing )
355317
356318 yield [project , dataset , datarow , label ]
357319
@@ -370,18 +332,18 @@ def configured_batch_project_with_label(client, rand_gen, image_url,
370332 """
371333 data_rows = [dr .uid for dr in list (dataset .data_rows ())]
372334 batch_project .create_batch ("test-batch" , data_rows )
373- editor = list (
374- batch_project .client .get_labeling_frontends (
375- where = LabelingFrontend .name == "editor" ))[0 ]
376335
377- ontology_builder = OntologyBuilder (tools = [
378- Tool (tool = Tool .Type .BBOX , name = "test-bbox-class" ),
379- ])
380- batch_project .setup (editor , ontology_builder .asdict ())
381- # TODO: ontology may not be synchronous after setup. remove sleep when api is more consistent
382- time .sleep (2 )
336+ ontology = _setup_ontology (batch_project )
337+ label = _create_label (batch_project , datarow , ontology ,
338+ wait_for_label_processing )
339+
340+ yield [batch_project , dataset , datarow , label ]
341+
342+ for label in batch_project .labels ():
343+ label .delete ()
383344
384- ontology = ontology_builder .from_project (batch_project )
345+
346+ def _create_label (project , datarow , ontology , wait_for_label_processing ):
385347 predictions = [{
386348 "uuid" : str (uuid .uuid4 ()),
387349 "schemaId" : ontology .tools [0 ].feature_schema_id ,
@@ -401,22 +363,31 @@ def create_label():
401363 Creates a LabelImport task which will create a label
402364 """
403365 upload_task = LabelImport .create_from_objects (
404- client , batch_project .uid , f'label-import-{ uuid .uuid4 ()} ' ,
366+ project . client , project .uid , f'label-import-{ uuid .uuid4 ()} ' ,
405367 predictions )
406368 upload_task .wait_until_done (sleep_time_seconds = 5 )
407369 assert upload_task .state == AnnotationImportState .FINISHED , "Label Import did not finish"
408370 assert len (
409371 upload_task .errors
410372 ) == 0 , f"Label Import { upload_task .name } failed with errors { upload_task .errors } "
411373
412- batch_project .create_label = create_label
413- batch_project .create_label ()
414- label = wait_for_label_processing (batch_project )[0 ]
374+ project .create_label = create_label
375+ project .create_label ()
376+ label = wait_for_label_processing (project )[0 ]
377+ return label
415378
416- yield [batch_project , dataset , datarow , label ]
417379
418- for label in batch_project .labels ():
419- label .delete ()
380+ def _setup_ontology (project ):
381+ editor = list (
382+ project .client .get_labeling_frontends (
383+ where = LabelingFrontend .name == "editor" ))[0 ]
384+ ontology_builder = OntologyBuilder (tools = [
385+ Tool (tool = Tool .Type .BBOX , name = "test-bbox-class" ),
386+ ])
387+ project .setup (editor , ontology_builder .asdict ())
388+ # TODO: ontology may not be synchronous after setup. remove sleep when api is more consistent
389+ time .sleep (2 )
390+ return ontology_builder .from_project (project )
420391
421392
422393@pytest .fixture
0 commit comments