Skip to content

Add back struct support #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/test_struct.py
Original file line number Diff line number Diff line change
@@ -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],
}
Loading