| 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 | |
| 587 | class TestTime: |