mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-08-08 08:30:47 -09:00
support/testing: new python-pydantic runtime test
While in theory, the fastapi tests finds problems with the pydantic package, it's not obvious that this test should be run when the pydantic package is updated. Add a new test that just covers pydantic. Signed-off-by: Marcus Hoffmann <buildroot@bubu1.eu> Signed-off-by: Arnout Vandecappelle <arnout@rnout.be>
This commit is contained in:
committed by
Arnout Vandecappelle
parent
c100f6a2fe
commit
45321879e1
32
support/testing/tests/package/sample_python_pydantic.py
Normal file
32
support/testing/tests/package/sample_python_pydantic.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel, PositiveInt
|
||||
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user