From 5eb46878bd954ec434d288dc97de596676273bb5 Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Wed, 14 May 2025 17:12:46 +0200 Subject: [PATCH] support/testing: new python-pydantic-settings runtime test Signed-off-by: Marcus Hoffmann Signed-off-by: Arnout Vandecappelle --- DEVELOPERS | 2 ++ .../sample_python_pydantic_settings.py | 8 +++++ .../package/test_python_pydantic_settings.py | 35 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 support/testing/tests/package/sample_python_pydantic_settings.py create mode 100644 support/testing/tests/package/test_python_pydantic_settings.py diff --git a/DEVELOPERS b/DEVELOPERS index 44056c5149..6528a63a83 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -2284,11 +2284,13 @@ 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_pydantic_settings.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_pydantic_settings.py F: support/testing/tests/package/sample_python_ruamel_yaml.py N: Marek Belisko diff --git a/support/testing/tests/package/sample_python_pydantic_settings.py b/support/testing/tests/package/sample_python_pydantic_settings.py new file mode 100644 index 0000000000..c98d1ce9c1 --- /dev/null +++ b/support/testing/tests/package/sample_python_pydantic_settings.py @@ -0,0 +1,8 @@ +from pydantic_settings import BaseSettings + + +class Settings(BaseSettings): + api_key: str + + +assert Settings().api_key == "ABCD1234" diff --git a/support/testing/tests/package/test_python_pydantic_settings.py b/support/testing/tests/package/test_python_pydantic_settings.py new file mode 100644 index 0000000000..608cbbc5b1 --- /dev/null +++ b/support/testing/tests/package/test_python_pydantic_settings.py @@ -0,0 +1,35 @@ +import os + +from tests.package.test_python import TestPythonPackageBase + + +class TestPythonPy3PydanticSettings(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_SETTINGS=y + BR2_TARGET_ROOTFS_CPIO=y + # BR2_TARGET_ROOTFS_TAR is not set + """ + sample_scripts = ["tests/package/sample_python_pydantic_settings.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() + + def run_sample_scripts(self): + """Run sample script while setting an environment variable""" + for script in self.sample_scripts: + cmd = ( + "api_key=ABCD1234 " + self.interpreter + " " + os.path.basename(script) + ) + self.assertRunOk(cmd, timeout=self.timeout)