mirror of
https://github.com/PartialVolume/shredos.x86_64.git
synced 2026-03-15 07:02:12 +00:00
38 lines
828 B
Python
38 lines
828 B
Python
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, PositiveInt
|
|
from pydantic.version import check_pydantic_core_version
|
|
|
|
# pydantic pins an exact version of pydantic core
|
|
# verify these are in sync in buildroots packaging
|
|
assert check_pydantic_core_version()
|
|
|
|
|
|
class User(BaseModel):
|
|
id: int
|
|
name: str = "John Doe"
|
|
signup_ts: datetime | None
|
|
tastes: dict[str, PositiveInt]
|
|
|
|
|
|
external_data = {
|
|
"id": 123,
|
|
"signup_ts": "2019-06-01 12:22",
|
|
"tastes": {
|
|
"wine": 9,
|
|
b"cheese": 7,
|
|
"cabbage": "1",
|
|
},
|
|
}
|
|
|
|
user = User(**external_data)
|
|
expected_user_dump = {
|
|
"id": 123,
|
|
"name": "John Doe",
|
|
"signup_ts": datetime(2019, 6, 1, 12, 22),
|
|
"tastes": {"wine": 9, "cheese": 7, "cabbage": 1},
|
|
}
|
|
|
|
assert user.id == 123
|
|
assert user.model_dump() == expected_user_dump
|