MCPcopy
hub / github.com/danielgtaylor/python-betterproto / test_enum_as_int_json

Function test_enum_as_int_json

tests/test_features.py:93–113  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

91
92
93def test_enum_as_int_json():
94 class TestEnum(betterproto.Enum):
95 ZERO = 0
96 ONE = 1
97
98 @dataclass
99 class Foo(betterproto.Message):
100 bar: TestEnum = betterproto.enum_field(1)
101
102 # JSON strings are supported, but ints should still be supported too.
103 foo = Foo().from_dict({"bar": 1})
104 assert foo.bar == TestEnum.ONE
105
106 # Plain-ol'-ints should serialize properly too.
107 foo.bar = 1
108 assert foo.to_dict() == {"bar": "ONE"}
109
110 # Similar expectations for pydict
111 foo = Foo().from_pydict({"bar": 1})
112 assert foo.bar == TestEnum.ONE
113 assert foo.to_pydict() == {"bar": TestEnum.ONE}
114
115
116def test_unknown_fields():

Callers

nothing calls this directly

Calls 5

from_pydictMethod · 0.80
to_pydictMethod · 0.80
FooClass · 0.70
from_dictMethod · 0.45
to_dictMethod · 0.45

Tested by

no test coverage detected