11import uuid
22import pytest
3+ from labelbox import parser
34
45from labelbox .schema .annotation_import import AnnotationImportState , LabelImport
56"""
910"""
1011
1112
13+ def test_create_with_url_arg (client , configured_project_with_one_data_row ,
14+ annotation_import_test_helpers ):
15+ name = str (uuid .uuid4 ())
16+ url = "https://storage.googleapis.com/labelbox-public-bucket/predictions_test_v2.ndjson"
17+ label_import = LabelImport .create (
18+ client = client ,
19+ id = configured_project_with_one_data_row .uid ,
20+ name = name ,
21+ url = url )
22+ assert label_import .parent_id == configured_project_with_one_data_row .uid
23+ annotation_import_test_helpers .check_running_state (label_import , name , url )
24+
25+
1226def test_create_from_url (client , configured_project_with_one_data_row ,
1327 annotation_import_test_helpers ):
1428 name = str (uuid .uuid4 ())
@@ -22,6 +36,22 @@ def test_create_from_url(client, configured_project_with_one_data_row,
2236 annotation_import_test_helpers .check_running_state (label_import , name , url )
2337
2438
39+ def test_create_with_labels_arg (client , configured_project , object_predictions ,
40+ annotation_import_test_helpers ):
41+ """this test should check running state only to validate running, not completed"""
42+ name = str (uuid .uuid4 ())
43+
44+ label_import = LabelImport .create (client = client ,
45+ id = configured_project .uid ,
46+ name = name ,
47+ labels = object_predictions )
48+
49+ assert label_import .parent_id == configured_project .uid
50+ annotation_import_test_helpers .check_running_state (label_import , name )
51+ annotation_import_test_helpers .assert_file_content (
52+ label_import .input_file_url , object_predictions )
53+
54+
2555def test_create_from_objects (client , configured_project , object_predictions ,
2656 annotation_import_test_helpers ):
2757 """this test should check running state only to validate running, not completed"""
@@ -39,20 +69,42 @@ def test_create_from_objects(client, configured_project, object_predictions,
3969 label_import .input_file_url , object_predictions )
4070
4171
42- # TODO: add me when we add this ability
43- # def test_create_from_local_file(client, tmp_path, project,
44- # object_predictions, annotation_import_test_helpers):
45- # name = str(uuid.uuid4())
46- # file_name = f"{name}.ndjson"
47- # file_path = tmp_path / file_name
48- # with file_path.open("w") as f:
49- # ndjson.dump(object_predictions, f)
72+ def test_create_with_path_arg (client , tmp_path , project , object_predictions ,
73+ annotation_import_test_helpers ):
74+ name = str (uuid .uuid4 ())
75+ file_name = f"{ name } .ndjson"
76+ file_path = tmp_path / file_name
77+ with file_path .open ("w" ) as f :
78+ parser .dump (object_predictions , f )
79+
80+ label_import = LabelImport .create (client = client ,
81+ id = project .uid ,
82+ name = name ,
83+ path = str (file_path ))
84+
85+ assert label_import .parent_id == project .uid
86+ annotation_import_test_helpers .check_running_state (label_import , name )
87+ annotation_import_test_helpers .assert_file_content (
88+ label_import .input_file_url , object_predictions )
89+
90+
91+ def test_create_from_local_file (client , tmp_path , project , object_predictions ,
92+ annotation_import_test_helpers ):
93+ name = str (uuid .uuid4 ())
94+ file_name = f"{ name } .ndjson"
95+ file_path = tmp_path / file_name
96+ with file_path .open ("w" ) as f :
97+ parser .dump (object_predictions , f )
5098
51- # label_import = LabelImport.create_from_url(client=client, project_id=project.uid, name=name, url=str(file_path))
99+ label_import = LabelImport .create_from_url (client = client ,
100+ project_id = project .uid ,
101+ name = name ,
102+ url = str (file_path ))
52103
53- # assert label_import.parent_id == project.uid
54- # annotation_import_test_helpers.check_running_state(label_import, name)
55- # annotation_import_test_helpers.assert_file_content(label_import.input_file_url, object_predictions)
104+ assert label_import .parent_id == project .uid
105+ annotation_import_test_helpers .check_running_state (label_import , name )
106+ annotation_import_test_helpers .assert_file_content (
107+ label_import .input_file_url , object_predictions )
56108
57109
58110def test_get (client , configured_project_with_one_data_row ,
0 commit comments