Skip to content

Commit e751a3e

Browse files
committed
Improve test case for relationships
1 parent e67070d commit e751a3e

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

tests/data/serialization/ndjson/test_relationship.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11
import json
2-
import pytest
32
from uuid import uuid4
43

4+
import pytest
5+
56
from labelbox.data.serialization.ndjson.converter import NDJsonConverter
67

78

89
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:
1011
data = json.load(file)
1112

1213
res = list(NDJsonConverter.deserialize(data))
1314
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
1424

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+
]
1631

1732

1833
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:
2035
data = json.load(file)
2136

2237
relationship_annotation = data[2]
@@ -30,7 +45,7 @@ def test_relationship_nonexistent_object():
3045

3146

3247
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:
3449
data = json.load(file)
3550

3651
source, target = data[0], data[1]

0 commit comments

Comments
 (0)