1
+ import uuid
2
+
3
+ from labelbox .data .annotation_types .annotation import ObjectAnnotation
4
+ from labelbox .schema .annotation_import import LabelImport
5
+
6
+
7
+ def test_export_annotations_nested_checklist (
8
+ client , configured_project_with_complex_ontology ):
9
+ project , data_row = configured_project_with_complex_ontology
10
+ ontology = project .ontology ().normalized
11
+
12
+ tool = ontology ["tools" ][0 ]
13
+
14
+ nested_check = [
15
+ subc for subc in tool ["classifications" ]
16
+ if subc ["name" ] == "test-checklist-class"
17
+ ][0 ]
18
+
19
+ data = [{
20
+ "uuid" :
21
+ str (uuid .uuid4 ()),
22
+ "schemaId" :
23
+ tool ['featureSchemaId' ],
24
+ "dataRow" : {
25
+ "id" : data_row .uid
26
+ },
27
+ "bbox" : {
28
+ "top" : 20 ,
29
+ "left" : 20 ,
30
+ "height" : 50 ,
31
+ "width" : 50
32
+ },
33
+ "classifications" : [{
34
+ "schemaId" :
35
+ nested_check ["featureSchemaId" ],
36
+ "answers" : [
37
+ {
38
+ "schemaId" : nested_check ["options" ][0 ]["featureSchemaId" ]
39
+ },
40
+ {
41
+ "schemaId" : nested_check ["options" ][1 ]["featureSchemaId" ]
42
+ },
43
+ ]
44
+ }]
45
+ }]
46
+
47
+ task = LabelImport .create_from_objects (client , project .uid ,
48
+ f'label-import-{ uuid .uuid4 ()} ' , data )
49
+ task .wait_until_done ()
50
+ labels = project .label_generator ().as_list ()
51
+ object_annotation = [
52
+ annot for annot in next (labels ).annotations
53
+ if isinstance (annot , ObjectAnnotation )
54
+ ][0 ]
55
+
56
+ nested_class_answers = object_annotation .classifications [0 ].value .answer
57
+ assert len (nested_class_answers ) == 2
58
+
59
+
60
+ def test_export_filtered_dates (client ,
61
+ configured_project_with_complex_ontology ):
62
+ project , data_row = configured_project_with_complex_ontology
63
+ ontology = project .ontology ().normalized
64
+
65
+ tool = ontology ["tools" ][0 ]
66
+
67
+ data = [{
68
+ "uuid" : str (uuid .uuid4 ()),
69
+ "schemaId" : tool ['featureSchemaId' ],
70
+ "dataRow" : {
71
+ "id" : data_row .uid
72
+ },
73
+ "bbox" : {
74
+ "top" : 20 ,
75
+ "left" : 20 ,
76
+ "height" : 50 ,
77
+ "width" : 50
78
+ }
79
+ }]
80
+
81
+ task = LabelImport .create_from_objects (client , project .uid ,
82
+ f'label-import-{ uuid .uuid4 ()} ' , data )
83
+ task .wait_until_done ()
84
+
85
+ regular_export = project .export_labels (download = True )
86
+ assert len (regular_export ) == 1
87
+
88
+ filtered_export = project .export_labels (download = True , start = "2020-01-01" )
89
+ assert len (filtered_export ) == 1
90
+
91
+ empty_export = project .export_labels (download = True ,
92
+ start = "2020-01-01" ,
93
+ end = "2020-01-02" )
94
+ assert len (empty_export ) == 0
0 commit comments