From f69723dd589514dca087a3f68de6e4255dd0e9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Thu, 21 Dec 2023 13:11:49 +0100 Subject: [PATCH] updates some tests to have a running event loop --- tests/data_service/test_data_service_cache.py | 4 +++- tests/data_service/test_task_manager.py | 15 ++++++++++----- tests/utils/test_serializer.py | 3 ++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/data_service/test_data_service_cache.py b/tests/data_service/test_data_service_cache.py index 5408cd6..d8e1b1f 100644 --- a/tests/data_service/test_data_service_cache.py +++ b/tests/data_service/test_data_service_cache.py @@ -1,6 +1,7 @@ import logging import pydase +import pytest from pydase.data_service.data_service_observer import DataServiceObserver from pydase.data_service.state_manager import StateManager @@ -34,7 +35,8 @@ def test_nested_attributes_cache_callback() -> None: ) -def test_task_status_update() -> None: +@pytest.mark.asyncio +async def test_task_status_update() -> None: class ServiceClass(pydase.DataService): name = "World" diff --git a/tests/data_service/test_task_manager.py b/tests/data_service/test_task_manager.py index 87dfb93..ce0042b 100644 --- a/tests/data_service/test_task_manager.py +++ b/tests/data_service/test_task_manager.py @@ -1,6 +1,7 @@ import logging import pydase +import pytest from pydase.data_service.data_service_observer import DataServiceObserver from pydase.data_service.state_manager import StateManager from pytest import LogCaptureFixture @@ -8,13 +9,14 @@ from pytest import LogCaptureFixture logger = logging.getLogger() -def test_autostart_task_callback(caplog: LogCaptureFixture) -> None: +@pytest.mark.asyncio +async def test_autostart_task_callback(caplog: LogCaptureFixture) -> None: class MyService(pydase.DataService): def __init__(self) -> None: super().__init__() self._autostart_tasks = { # type: ignore - "my_task": (), - "my_other_task": (), + "my_task": (), # type: ignore + "my_other_task": (), # type: ignore } async def my_task(self) -> None: @@ -23,6 +25,7 @@ def test_autostart_task_callback(caplog: LogCaptureFixture) -> None: async def my_other_task(self) -> None: logger.info("Triggered other task.") + # Your test code here service_instance = MyService() state_manager = StateManager(service_instance) DataServiceObserver(state_manager) @@ -32,7 +35,8 @@ def test_autostart_task_callback(caplog: LogCaptureFixture) -> None: assert "'my_other_task' changed to '{}'" in caplog.text -def test_DataService_subclass_autostart_task_callback( +@pytest.mark.asyncio +async def test_DataService_subclass_autostart_task_callback( caplog: LogCaptureFixture, ) -> None: class MySubService(pydase.DataService): @@ -61,7 +65,8 @@ def test_DataService_subclass_autostart_task_callback( assert "'sub_service.my_other_task' changed to '{}'" in caplog.text -def test_DataService_subclass_list_autostart_task_callback( +@pytest.mark.asyncio +async def test_DataService_subclass_list_autostart_task_callback( caplog: LogCaptureFixture, ) -> None: class MySubService(pydase.DataService): diff --git a/tests/utils/test_serializer.py b/tests/utils/test_serializer.py index 6bf5922..79b12a9 100644 --- a/tests/utils/test_serializer.py +++ b/tests/utils/test_serializer.py @@ -125,7 +125,8 @@ def test_ColouredEnum_serialize() -> None: } -def test_method_serialization() -> None: +@pytest.mark.asyncio +async def test_method_serialization() -> None: class ClassWithMethod(pydase.DataService): def some_method(self) -> str: return "some method"