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

Function test_to_dict_datetime_values

tests/test_features.py:478–497  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

476
477
478def test_to_dict_datetime_values():
479 @dataclass
480 class TestDatetimeMessage(betterproto.Message):
481 bar: datetime = betterproto.message_field(1)
482 baz: timedelta = betterproto.message_field(2)
483
484 test = TestDatetimeMessage().from_dict(
485 {"bar": "2020-01-01T00:00:00Z", "baz": "86400.000s"}
486 )
487
488 assert test.to_dict() == {"bar": "2020-01-01T00:00:00Z", "baz": "86400.000s"}
489
490 test = TestDatetimeMessage().from_pydict(
491 {"bar": datetime(year=2020, month=1, day=1), "baz": timedelta(days=1)}
492 )
493
494 assert test.to_pydict() == {
495 "bar": datetime(year=2020, month=1, day=1),
496 "baz": timedelta(days=1),
497 }
498
499
500def test_oneof_default_value_set_causes_writes_wire():

Callers

nothing calls this directly

Calls 5

TestDatetimeMessageClass · 0.85
from_pydictMethod · 0.80
to_pydictMethod · 0.80
from_dictMethod · 0.45
to_dictMethod · 0.45

Tested by

no test coverage detected