Skip to content

Commit 56c3ce5

Browse files
committed
Test struct to dict
1 parent 59f7441 commit 56c3ce5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

betterproto2/tests/test_struct.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def test_struct_to_dict():
2+
from tests.output_betterproto_pydantic.google.protobuf import ListValue, NullValue, Struct, Value
3+
4+
struct = Struct(
5+
fields={
6+
"null_field": Value(null_value=NullValue._), # TODO fix the name
7+
"number_field": Value(number_value=12),
8+
"string_field": Value(string_value="test"),
9+
"bool_field": Value(bool_value=True),
10+
"struct_field": Value(struct_value=Struct(fields={"x": Value(string_value="abc")})),
11+
"list_field": Value(list_value=ListValue(values=[Value(number_value=42), Value(bool_value=False)])),
12+
}
13+
)
14+
15+
assert struct.to_dict() == {
16+
"null_field": None,
17+
"number_field": 12,
18+
"string_field": "test",
19+
"bool_field": True,
20+
"struct_field": {"x": "abc"},
21+
"list_field": [42, False],
22+
}

0 commit comments

Comments
 (0)