From 56c3ce5f794b202f6152d497e675778f8372aef4 Mon Sep 17 00:00:00 2001 From: Adrien Vannson Date: Mon, 5 May 2025 11:27:03 +0200 Subject: [PATCH] Test struct to dict --- betterproto2/tests/test_struct.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 betterproto2/tests/test_struct.py diff --git a/betterproto2/tests/test_struct.py b/betterproto2/tests/test_struct.py new file mode 100644 index 00000000..c8f51011 --- /dev/null +++ b/betterproto2/tests/test_struct.py @@ -0,0 +1,22 @@ +def test_struct_to_dict(): + from tests.output_betterproto_pydantic.google.protobuf import ListValue, NullValue, Struct, Value + + struct = Struct( + fields={ + "null_field": Value(null_value=NullValue._), # TODO fix the name + "number_field": Value(number_value=12), + "string_field": Value(string_value="test"), + "bool_field": Value(bool_value=True), + "struct_field": Value(struct_value=Struct(fields={"x": Value(string_value="abc")})), + "list_field": Value(list_value=ListValue(values=[Value(number_value=42), Value(bool_value=False)])), + } + ) + + assert struct.to_dict() == { + "null_field": None, + "number_field": 12, + "string_field": "test", + "bool_field": True, + "struct_field": {"x": "abc"}, + "list_field": [42, False], + }