-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_serialization.py
More file actions
72 lines (55 loc) · 2.62 KB
/
test_serialization.py
File metadata and controls
72 lines (55 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# This file was auto-generated by Fern from our API Definition.
from typing import Any, List
from .assets.models import ObjectWithOptionalFieldParams, ShapeParams
from humanloop.core.serialization import convert_and_respect_annotation_metadata
UNION_TEST: ShapeParams = {"radius_measurement": 1.0, "shape_type": "circle", "id": "1"}
UNION_TEST_CONVERTED = {"shapeType": "circle", "radiusMeasurement": 1.0, "id": "1"}
def test_convert_and_respect_annotation_metadata() -> None:
data: ObjectWithOptionalFieldParams = {
"string": "string",
"long_": 12345,
"bool_": True,
"literal": "lit_one",
"any": "any",
}
converted = convert_and_respect_annotation_metadata(
object_=data, annotation=ObjectWithOptionalFieldParams, direction="write"
)
assert converted == {"string": "string", "long": 12345, "bool": True, "literal": "lit_one", "any": "any"}
def test_convert_and_respect_annotation_metadata_in_list() -> None:
data: List[ObjectWithOptionalFieldParams] = [
{"string": "string", "long_": 12345, "bool_": True, "literal": "lit_one", "any": "any"},
{"string": "another string", "long_": 67890, "list_": [], "literal": "lit_one", "any": "any"},
]
converted = convert_and_respect_annotation_metadata(
object_=data, annotation=List[ObjectWithOptionalFieldParams], direction="write"
)
assert converted == [
{"string": "string", "long": 12345, "bool": True, "literal": "lit_one", "any": "any"},
{"string": "another string", "long": 67890, "list": [], "literal": "lit_one", "any": "any"},
]
def test_convert_and_respect_annotation_metadata_in_nested_object() -> None:
data: ObjectWithOptionalFieldParams = {
"string": "string",
"long_": 12345,
"union": UNION_TEST,
"literal": "lit_one",
"any": "any",
}
converted = convert_and_respect_annotation_metadata(
object_=data, annotation=ObjectWithOptionalFieldParams, direction="write"
)
assert converted == {
"string": "string",
"long": 12345,
"union": UNION_TEST_CONVERTED,
"literal": "lit_one",
"any": "any",
}
def test_convert_and_respect_annotation_metadata_in_union() -> None:
converted = convert_and_respect_annotation_metadata(object_=UNION_TEST, annotation=ShapeParams, direction="write")
assert converted == UNION_TEST_CONVERTED
def test_convert_and_respect_annotation_metadata_with_empty_object() -> None:
data: Any = {}
converted = convert_and_respect_annotation_metadata(object_=data, annotation=ShapeParams, direction="write")
assert converted == data