updates some tests to have a running event loop

This commit is contained in:
Mose Müller 2023-12-21 13:11:49 +01:00
parent c733026522
commit f69723dd58
3 changed files with 15 additions and 7 deletions

View File

@ -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"

View File

@ -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):

View File

@ -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"