1
1
import json
2
- import pytest
3
2
from uuid import uuid4
4
3
4
+ import pytest
5
+
5
6
from labelbox .data .serialization .ndjson .converter import NDJsonConverter
6
7
7
8
8
9
def test_relationship ():
9
- with open (' tests/data/assets/ndjson/relationship_import.json' , 'r' ) as file :
10
+ with open (" tests/data/assets/ndjson/relationship_import.json" , "r" ) as file :
10
11
data = json .load (file )
11
12
12
13
res = list (NDJsonConverter .deserialize (data ))
13
14
res = list (NDJsonConverter .serialize (res ))
15
+ assert len (res ) == len (data )
16
+
17
+ res_relationship_annotation = [
18
+ annot for annot in res if "relationship" in annot
19
+ ][0 ]
20
+ res_source_and_target = [
21
+ annot for annot in res if "relationship" not in annot
22
+ ]
23
+ assert res_relationship_annotation
14
24
15
- assert res == data
25
+ assert res_relationship_annotation ["relationship" ]["source" ] in [
26
+ annot ["uuid" ] for annot in res_source_and_target
27
+ ]
28
+ assert res_relationship_annotation ["relationship" ]["target" ] in [
29
+ annot ["uuid" ] for annot in res_source_and_target
30
+ ]
16
31
17
32
18
33
def test_relationship_nonexistent_object ():
19
- with open (' tests/data/assets/ndjson/relationship_import.json' , 'r' ) as file :
34
+ with open (" tests/data/assets/ndjson/relationship_import.json" , "r" ) as file :
20
35
data = json .load (file )
21
36
22
37
relationship_annotation = data [2 ]
@@ -30,7 +45,7 @@ def test_relationship_nonexistent_object():
30
45
31
46
32
47
def test_relationship_duplicate_uuids ():
33
- with open (' tests/data/assets/ndjson/relationship_import.json' , 'r' ) as file :
48
+ with open (" tests/data/assets/ndjson/relationship_import.json" , "r" ) as file :
34
49
data = json .load (file )
35
50
36
51
source , target = data [0 ], data [1 ]
0 commit comments