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

Function test_optional_flag

tests/test_features.py:268–280  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

266
267
268def test_optional_flag():
269 @dataclass
270 class Request(betterproto.Message):
271 flag: Optional[bool] = betterproto.message_field(1, wraps=betterproto.TYPE_BOOL)
272
273 # Serialization of not passed vs. set vs. zero-value.
274 assert bytes(Request()) == b""
275 assert bytes(Request(flag=True)) == b"\n\x02\x08\x01"
276 assert bytes(Request(flag=False)) == b"\n\x00"
277
278 # Differentiate between not passed and the zero-value.
279 assert Request().parse(b"").flag is None
280 assert Request().parse(b"\n\x00").flag is False
281
282
283def test_optional_datetime_to_dict():

Callers

nothing calls this directly

Calls 2

parseMethod · 0.80
RequestClass · 0.70

Tested by

no test coverage detected