MCPcopy Index your code
hub / github.com/msgspec/msgspec / test_datetime_constrs

Method test_datetime_constrs

tests/unit/test_convert.py:571–584  ·  view source on GitHub ↗
(self, as_str)

Source from the content-addressed store, hash-verified

569
570 @pytest.mark.parametrize("as_str", [False, True])
571 def test_datetime_constrs(self, as_str):
572 class Ex(Struct):
573 x: Annotated[datetime.datetime, Meta(tz=True)]
574
575 builtin_types = None if as_str else (datetime.datetime,)
576
577 aware = Ex(datetime.datetime(1, 2, 3, 4, 5, 6, 7, UTC))
578 aware_msg = to_builtins(aware, builtin_types=builtin_types)
579 naive = Ex(datetime.datetime(1, 2, 3, 4, 5, 6, 7))
580 naive_msg = to_builtins(naive, builtin_types=builtin_types)
581
582 assert convert(aware_msg, Ex) == aware
583 with pytest.raises(ValidationError):
584 convert(naive_msg, Ex)
585
586
587class TestTime:

Callers

nothing calls this directly

Calls 1

ExClass · 0.70

Tested by

no test coverage detected