From 45321879e16d97079c3d1a4431f615c73291200b Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Wed, 14 May 2025 17:12:45 +0200 Subject: [PATCH] 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 Signed-off-by: Arnout Vandecappelle --- DEVELOPERS | 2 ++ .../tests/package/sample_python_pydantic.py | 32 +++++++++++++++++++ .../tests/package/test_python_pydantic.py | 27 ++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 support/testing/tests/package/sample_python_pydantic.py create mode 100644 support/testing/tests/package/test_python_pydantic.py diff --git a/DEVELOPERS b/DEVELOPERS index 2b28384d0b..44056c5149 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -2283,10 +2283,12 @@ F: package/python-typing-inspection/ F: package/python-tzlocal/ F: package/python-waitress/ F: support/testing/tests/package/test_python_fastapi.py +F: support/testing/tests/package/test_python_pydantic.py F: support/testing/tests/package/test_python_ruamel_yaml.py F: support/testing/tests/package/test_python_tzlocal.py F: support/testing/tests/package/test_python_waitress.py F: support/testing/tests/package/sample_python_fastapi.py +F: support/testing/tests/package/sample_python_pydantic.py F: support/testing/tests/package/sample_python_ruamel_yaml.py N: Marek Belisko diff --git a/support/testing/tests/package/sample_python_pydantic.py b/support/testing/tests/package/sample_python_pydantic.py new file mode 100644 index 0000000000..4c22f5ede4 --- /dev/null +++ b/support/testing/tests/package/sample_python_pydantic.py @@ -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 diff --git a/support/testing/tests/package/test_python_pydantic.py b/support/testing/tests/package/test_python_pydantic.py new file mode 100644 index 0000000000..1369d82f59 --- /dev/null +++ b/support/testing/tests/package/test_python_pydantic.py @@ -0,0 +1,27 @@ +import os + +from tests.package.test_python import TestPythonPackageBase + + +class TestPythonPy3Pydantic(TestPythonPackageBase): + __test__ = True + config = """ + BR2_arm=y + BR2_cortex_a9=y + BR2_ARM_ENABLE_NEON=y + BR2_ARM_ENABLE_VFP=y + BR2_TOOLCHAIN_EXTERNAL=y + BR2_PACKAGE_PYTHON3=y + BR2_PACKAGE_PYTHON_PYDANTIC=y + BR2_TARGET_ROOTFS_CPIO=y + # BR2_TARGET_ROOTFS_TAR is not set + """ + sample_scripts = ["tests/package/sample_python_pydantic.py"] + timeout = 30 + + def login(self): + cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio") + self.emulator.boot( + arch="armv7", kernel="builtin", options=["-initrd", cpio_file] + ) + self.emulator.login()