mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-19 08:00:02 +02:00
fix: removes monkey path of emit_notification, adapts affected tests
This commit is contained in:
parent
53ce51991f
commit
f88493d97c
@ -1,15 +0,0 @@
|
||||
from collections.abc import Generator
|
||||
from typing import Any
|
||||
|
||||
from pydase import DataService
|
||||
from pydase.data_service.callback_manager import CallbackManager
|
||||
|
||||
|
||||
def emit(self: Any, parent_path: str, name: str, value: Any) -> None:
|
||||
if isinstance(value, DataService):
|
||||
value = value.serialize()
|
||||
|
||||
print(f"{parent_path}.{name} = {value}")
|
||||
|
||||
|
||||
CallbackManager.emit_notification = emit # type: ignore
|
@ -1,10 +1,10 @@
|
||||
from pytest import CaptureFixture, LogCaptureFixture
|
||||
from pytest import LogCaptureFixture
|
||||
|
||||
from pydase.components.coloured_enum import ColouredEnum
|
||||
from pydase.data_service.data_service import DataService
|
||||
|
||||
|
||||
def test_ColouredEnum(capsys: CaptureFixture) -> None:
|
||||
def test_ColouredEnum(caplog: LogCaptureFixture) -> None:
|
||||
class MyStatus(ColouredEnum):
|
||||
RUNNING = "#00FF00"
|
||||
FAILING = "#FF0000"
|
||||
@ -25,15 +25,7 @@ def test_ColouredEnum(capsys: CaptureFixture) -> None:
|
||||
|
||||
service.status = MyStatus.FAILING
|
||||
|
||||
captured = capsys.readouterr()
|
||||
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.status = MyStatus.FAILING",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n")) # type: ignore
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.status changed to MyStatus.FAILING" in caplog.text
|
||||
|
||||
|
||||
def test_warning(caplog: LogCaptureFixture) -> None: # noqa
|
||||
|
@ -4,7 +4,7 @@ from pydase.components.number_slider import NumberSlider
|
||||
from pydase.data_service.data_service import DataService
|
||||
|
||||
|
||||
def test_NumberSlider(capsys: CaptureFixture) -> None:
|
||||
def test_NumberSlider(caplog: LogCaptureFixture) -> None:
|
||||
class ServiceClass(DataService):
|
||||
number_slider = NumberSlider(1, 0, 10, 1)
|
||||
int_number_slider = NumberSlider(1, 0, 10, 1, "int")
|
||||
@ -28,28 +28,13 @@ def test_NumberSlider(capsys: CaptureFixture) -> None:
|
||||
service.number_slider.value = 10.0
|
||||
service.int_number_slider.value = 10.1
|
||||
|
||||
captured = capsys.readouterr()
|
||||
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.number_slider.value = 10.0",
|
||||
"ServiceClass.int_number_slider.value = 10",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n")) # type: ignore
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.number_slider.value changed to 10.0" in caplog.text
|
||||
assert "ServiceClass.int_number_slider.value changed to 10" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
service.number_slider.min = 1.1
|
||||
|
||||
captured = capsys.readouterr()
|
||||
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.number_slider.min = 1.1",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n")) # type: ignore
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.number_slider.min changed to 1.1" in caplog.text
|
||||
|
||||
|
||||
def test_init_error(caplog: LogCaptureFixture) -> None: # noqa
|
||||
|
@ -1,13 +1,13 @@
|
||||
import logging
|
||||
|
||||
from pytest import CaptureFixture
|
||||
from pytest import LogCaptureFixture
|
||||
|
||||
import pydase
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
def test_DataService_task_callback(capsys: CaptureFixture) -> None:
|
||||
def test_DataService_task_callback(caplog: LogCaptureFixture) -> None:
|
||||
class MyService(pydase.DataService):
|
||||
async def my_task(self) -> None:
|
||||
logger.info("Triggered task.")
|
||||
@ -19,18 +19,11 @@ def test_DataService_task_callback(capsys: CaptureFixture) -> None:
|
||||
service.start_my_task() # type: ignore
|
||||
service.start_my_other_task() # type: ignore
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"MyService.my_task = {}",
|
||||
"MyService.my_other_task = {}",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n")) # type: ignore
|
||||
assert expected_output == actual_output
|
||||
assert "MyService.my_task changed to {}" in caplog.text
|
||||
assert "MyService.my_other_task changed to {}" in caplog.text
|
||||
|
||||
|
||||
def test_DataServiceList_task_callback(capsys: CaptureFixture) -> None:
|
||||
def test_DataServiceList_task_callback(caplog: LogCaptureFixture) -> None:
|
||||
class MySubService(pydase.DataService):
|
||||
async def my_task(self) -> None:
|
||||
logger.info("Triggered task.")
|
||||
@ -45,12 +38,5 @@ def test_DataServiceList_task_callback(capsys: CaptureFixture) -> None:
|
||||
service.sub_services_list[0].start_my_task() # type: ignore
|
||||
service.sub_services_list[1].start_my_other_task() # type: ignore
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"MyService.sub_services_list[0].my_task = {}",
|
||||
"MyService.sub_services_list[1].my_other_task = {}",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n")) # type: ignore
|
||||
assert expected_output == actual_output
|
||||
assert "MyService.sub_services_list[0].my_task changed to {}" in caplog.text
|
||||
assert "MyService.sub_services_list[1].my_other_task changed to {}" in caplog.text
|
||||
|
@ -1,13 +1,13 @@
|
||||
import logging
|
||||
|
||||
from pytest import CaptureFixture
|
||||
from pytest import LogCaptureFixture
|
||||
|
||||
import pydase
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
def test_autostart_task_callback(capsys: CaptureFixture) -> None:
|
||||
def test_autostart_task_callback(caplog: LogCaptureFixture) -> None:
|
||||
class MyService(pydase.DataService):
|
||||
def __init__(self) -> None:
|
||||
self._autostart_tasks = { # type: ignore
|
||||
@ -25,18 +25,13 @@ def test_autostart_task_callback(capsys: CaptureFixture) -> None:
|
||||
service = MyService()
|
||||
service._task_manager.start_autostart_tasks()
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"MyService.my_task = {}",
|
||||
"MyService.my_other_task = {}",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n")) # type: ignore
|
||||
assert expected_output == actual_output
|
||||
assert "MyService.my_task changed to {}" in caplog.text
|
||||
assert "MyService.my_other_task changed to {}" in caplog.text
|
||||
|
||||
|
||||
def test_DataService_subclass_autostart_task_callback(capsys: CaptureFixture) -> None:
|
||||
def test_DataService_subclass_autostart_task_callback(
|
||||
caplog: LogCaptureFixture,
|
||||
) -> None:
|
||||
class MySubService(pydase.DataService):
|
||||
def __init__(self) -> None:
|
||||
self._autostart_tasks = { # type: ignore
|
||||
@ -57,19 +52,12 @@ def test_DataService_subclass_autostart_task_callback(capsys: CaptureFixture) ->
|
||||
service = MyService()
|
||||
service._task_manager.start_autostart_tasks()
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"MyService.sub_service.my_task = {}",
|
||||
"MyService.sub_service.my_other_task = {}",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n")) # type: ignore
|
||||
assert expected_output == actual_output
|
||||
assert "MyService.sub_service.my_task changed to {}" in caplog.text
|
||||
assert "MyService.sub_service.my_other_task changed to {}" in caplog.text
|
||||
|
||||
|
||||
def test_DataServiceList_subclass_autostart_task_callback(
|
||||
capsys: CaptureFixture,
|
||||
caplog: LogCaptureFixture,
|
||||
) -> None:
|
||||
class MySubService(pydase.DataService):
|
||||
def __init__(self) -> None:
|
||||
@ -91,14 +79,7 @@ def test_DataServiceList_subclass_autostart_task_callback(
|
||||
service = MyService()
|
||||
service._task_manager.start_autostart_tasks()
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"MyService.sub_services_list[0].my_task = {}",
|
||||
"MyService.sub_services_list[0].my_other_task = {}",
|
||||
"MyService.sub_services_list[1].my_task = {}",
|
||||
"MyService.sub_services_list[1].my_other_task = {}",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n")) # type: ignore
|
||||
assert expected_output == actual_output
|
||||
assert "MyService.sub_services_list[0].my_task changed to {}" in caplog.text
|
||||
assert "MyService.sub_services_list[0].my_other_task changed to {}" in caplog.text
|
||||
assert "MyService.sub_services_list[1].my_task changed to {}" in caplog.text
|
||||
assert "MyService.sub_services_list[1].my_other_task changed to {}" in caplog.text
|
||||
|
@ -1,46 +1,42 @@
|
||||
from pytest import CaptureFixture
|
||||
from typing import Any
|
||||
|
||||
from pytest import LogCaptureFixture
|
||||
|
||||
from pydase import DataService
|
||||
|
||||
|
||||
def test_class_list_attribute(capsys: CaptureFixture) -> None:
|
||||
def test_class_list_attribute(caplog: LogCaptureFixture) -> None:
|
||||
class ServiceClass(DataService):
|
||||
attr = [0, 1]
|
||||
|
||||
service_instance = ServiceClass()
|
||||
|
||||
service_instance.attr[0] = 1337
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "ServiceClass.attr[0] = 1337\n"
|
||||
assert "ServiceClass.attr[0] changed to 1337" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
|
||||
def test_instance_list_attribute(capsys: CaptureFixture) -> None:
|
||||
def test_instance_list_attribute(caplog: LogCaptureFixture) -> None:
|
||||
class SubClass(DataService):
|
||||
name = "SubClass"
|
||||
|
||||
class ServiceClass(DataService):
|
||||
def __init__(self) -> None:
|
||||
self.attr = [0, SubClass()]
|
||||
self.attr: list[Any] = [0, SubClass()]
|
||||
super().__init__()
|
||||
|
||||
service_instance = ServiceClass()
|
||||
|
||||
_ = capsys.readouterr()
|
||||
|
||||
service_instance.attr[0] = "Hello"
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "ServiceClass.attr[0] = Hello\n"
|
||||
assert "ServiceClass.attr[0] changed to Hello" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
service_instance.attr[1] = SubClass()
|
||||
captured = capsys.readouterr()
|
||||
assert (
|
||||
captured.out.strip()
|
||||
== "ServiceClass.attr[1] = {'name': {'type': 'str', 'value': 'SubClass',"
|
||||
" 'readonly': False, 'doc': None}}"
|
||||
)
|
||||
assert f"ServiceClass.attr[1] changed to {service_instance.attr[1]}" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
|
||||
def test_reused_instance_list_attribute(capsys: CaptureFixture) -> None:
|
||||
def test_reused_instance_list_attribute(caplog: LogCaptureFixture) -> None:
|
||||
some_list = [0, 1, 2]
|
||||
|
||||
class ServiceClass(DataService):
|
||||
@ -53,21 +49,14 @@ def test_reused_instance_list_attribute(capsys: CaptureFixture) -> None:
|
||||
service_instance = ServiceClass()
|
||||
|
||||
service_instance.attr[0] = 20
|
||||
captured = capsys.readouterr()
|
||||
|
||||
assert service_instance.attr == service_instance.attr_2
|
||||
assert service_instance.attr != service_instance.attr_3
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr[0] = 20",
|
||||
"ServiceClass.attr_2[0] = 20",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
|
||||
assert "ServiceClass.attr[0] changed to 20" in caplog.text
|
||||
assert "ServiceClass.attr_2[0] changed to 20" in caplog.text
|
||||
|
||||
|
||||
def test_nested_reused_instance_list_attribute(capsys: CaptureFixture) -> None:
|
||||
def test_nested_reused_instance_list_attribute(caplog: LogCaptureFixture) -> None:
|
||||
some_list = [0, 1, 2]
|
||||
|
||||
class SubClass(DataService):
|
||||
@ -85,23 +74,16 @@ def test_nested_reused_instance_list_attribute(capsys: CaptureFixture) -> None:
|
||||
|
||||
service_instance = ServiceClass()
|
||||
|
||||
_ = capsys.readouterr()
|
||||
service_instance.attr[0] = 20
|
||||
captured = capsys.readouterr()
|
||||
|
||||
assert service_instance.attr == service_instance.subclass.attr_list
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.subclass.attr_list_2[0] = 20",
|
||||
"ServiceClass.subclass.attr_list[0] = 20",
|
||||
"ServiceClass.attr[0] = 20",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
|
||||
assert "ServiceClass.attr[0] changed to 20" in caplog.text
|
||||
assert "ServiceClass.subclass.attr_list[0] changed to 20" in caplog.text
|
||||
assert "ServiceClass.subclass.attr_list_2[0] changed to 20" in caplog.text
|
||||
|
||||
|
||||
def test_protected_list_attribute(capsys: CaptureFixture) -> None:
|
||||
def test_protected_list_attribute(caplog: LogCaptureFixture) -> None:
|
||||
"""Changing protected lists should not emit notifications for the lists themselves, but
|
||||
still for all properties depending on them.
|
||||
"""
|
||||
@ -116,12 +98,4 @@ def test_protected_list_attribute(capsys: CaptureFixture) -> None:
|
||||
service_instance = ServiceClass()
|
||||
|
||||
service_instance._attr[0] = 1337
|
||||
captured = capsys.readouterr()
|
||||
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.list_dependend_property = 1337",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n")) # type: ignore
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.list_dependend_property changed to 1337" in caplog.text
|
||||
|
@ -1,9 +1,9 @@
|
||||
from pytest import CaptureFixture
|
||||
from pytest import LogCaptureFixture
|
||||
|
||||
from pydase import DataService
|
||||
|
||||
|
||||
def test_class_attributes(capsys: CaptureFixture) -> None:
|
||||
def test_class_attributes(caplog: LogCaptureFixture) -> None:
|
||||
class SubClass(DataService):
|
||||
name = "Hello"
|
||||
|
||||
@ -11,14 +11,12 @@ def test_class_attributes(capsys: CaptureFixture) -> None:
|
||||
attr_1 = SubClass()
|
||||
|
||||
service_instance = ServiceClass()
|
||||
_ = capsys.readouterr()
|
||||
service_instance.attr_1.name = "Hi"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == "ServiceClass.attr_1.name = Hi"
|
||||
assert "ServiceClass.attr_1.name changed to Hi" in caplog.text
|
||||
|
||||
|
||||
def test_instance_attributes(capsys: CaptureFixture) -> None:
|
||||
def test_instance_attributes(caplog: LogCaptureFixture) -> None:
|
||||
class SubClass(DataService):
|
||||
name = "Hello"
|
||||
|
||||
@ -28,25 +26,22 @@ def test_instance_attributes(capsys: CaptureFixture) -> None:
|
||||
super().__init__()
|
||||
|
||||
service_instance = ServiceClass()
|
||||
_ = capsys.readouterr()
|
||||
service_instance.attr_1.name = "Hi"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == "ServiceClass.attr_1.name = Hi"
|
||||
assert "ServiceClass.attr_1.name changed to Hi" in caplog.text
|
||||
|
||||
|
||||
def test_class_attribute(capsys: CaptureFixture) -> None:
|
||||
def test_class_attribute(caplog: LogCaptureFixture) -> None:
|
||||
class ServiceClass(DataService):
|
||||
attr = 0
|
||||
|
||||
service_instance = ServiceClass()
|
||||
|
||||
service_instance.attr = 1
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "ServiceClass.attr = 1\n"
|
||||
assert "ServiceClass.attr changed to 1" in caplog.text
|
||||
|
||||
|
||||
def test_instance_attribute(capsys: CaptureFixture) -> None:
|
||||
def test_instance_attribute(caplog: LogCaptureFixture) -> None:
|
||||
class ServiceClass(DataService):
|
||||
def __init__(self) -> None:
|
||||
self.attr = "Hello World"
|
||||
@ -55,11 +50,10 @@ def test_instance_attribute(capsys: CaptureFixture) -> None:
|
||||
service_instance = ServiceClass()
|
||||
|
||||
service_instance.attr = "Hello"
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "ServiceClass.attr = Hello\n"
|
||||
assert "ServiceClass.attr changed to Hello" in caplog.text
|
||||
|
||||
|
||||
def test_reused_instance_attributes(capsys: CaptureFixture) -> None:
|
||||
def test_reused_instance_attributes(caplog: LogCaptureFixture) -> None:
|
||||
class SubClass(DataService):
|
||||
name = "Hello"
|
||||
|
||||
@ -72,22 +66,14 @@ def test_reused_instance_attributes(capsys: CaptureFixture) -> None:
|
||||
super().__init__()
|
||||
|
||||
service_instance = ServiceClass()
|
||||
_ = capsys.readouterr()
|
||||
service_instance.attr_1.name = "Hi"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert service_instance.attr_1 == service_instance.attr_2
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr_1.name = Hi",
|
||||
"ServiceClass.attr_2.name = Hi",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr_1.name changed to Hi" in caplog.text
|
||||
assert "ServiceClass.attr_2.name changed to Hi" in caplog.text
|
||||
|
||||
|
||||
def test_reused_attributes_mixed(capsys: CaptureFixture) -> None:
|
||||
def test_reused_attributes_mixed(caplog: LogCaptureFixture) -> None:
|
||||
class SubClass(DataService):
|
||||
pass
|
||||
|
||||
@ -101,22 +87,14 @@ def test_reused_attributes_mixed(capsys: CaptureFixture) -> None:
|
||||
super().__init__()
|
||||
|
||||
service_instance = ServiceClass()
|
||||
_ = capsys.readouterr()
|
||||
service_instance.attr_1.name = "Hi"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert service_instance.attr_1 == service_instance.attr_2
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr_1.name = Hi",
|
||||
"ServiceClass.attr_2.name = Hi",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr_1.name changed to Hi" in caplog.text
|
||||
assert "ServiceClass.attr_2.name changed to Hi" in caplog.text
|
||||
|
||||
|
||||
def test_nested_class_attributes(capsys: CaptureFixture) -> None:
|
||||
def test_nested_class_attributes(caplog: LogCaptureFixture) -> None:
|
||||
class SubSubSubClass(DataService):
|
||||
name = "Hello"
|
||||
|
||||
@ -133,26 +111,18 @@ def test_nested_class_attributes(capsys: CaptureFixture) -> None:
|
||||
attr = SubClass()
|
||||
|
||||
service_instance = ServiceClass()
|
||||
_ = capsys.readouterr()
|
||||
service_instance.attr.attr.attr.name = "Hi"
|
||||
service_instance.attr.attr.name = "Hou"
|
||||
service_instance.attr.name = "foo"
|
||||
service_instance.name = "bar"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr.attr.attr.name = Hi",
|
||||
"ServiceClass.attr.attr.name = Hou",
|
||||
"ServiceClass.attr.name = foo",
|
||||
"ServiceClass.name = bar",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr.attr.attr.name changed to Hi" in caplog.text
|
||||
assert "ServiceClass.attr.attr.name changed to Hou" in caplog.text
|
||||
assert "ServiceClass.attr.name changed to foo" in caplog.text
|
||||
assert "ServiceClass.name changed to bar" in caplog.text
|
||||
|
||||
|
||||
def test_nested_instance_attributes(capsys: CaptureFixture) -> None:
|
||||
def test_nested_instance_attributes(caplog: LogCaptureFixture) -> None:
|
||||
class SubSubSubClass(DataService):
|
||||
name = "Hello"
|
||||
|
||||
@ -175,26 +145,18 @@ def test_nested_instance_attributes(capsys: CaptureFixture) -> None:
|
||||
super().__init__()
|
||||
|
||||
service_instance = ServiceClass()
|
||||
_ = capsys.readouterr()
|
||||
service_instance.attr.attr.attr.name = "Hi"
|
||||
service_instance.attr.attr.name = "Hou"
|
||||
service_instance.attr.name = "foo"
|
||||
service_instance.name = "bar"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr.attr.attr.name = Hi",
|
||||
"ServiceClass.attr.attr.name = Hou",
|
||||
"ServiceClass.attr.name = foo",
|
||||
"ServiceClass.name = bar",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr.attr.attr.name changed to Hi" in caplog.text
|
||||
assert "ServiceClass.attr.attr.name changed to Hou" in caplog.text
|
||||
assert "ServiceClass.attr.name changed to foo" in caplog.text
|
||||
assert "ServiceClass.name changed to bar" in caplog.text
|
||||
|
||||
|
||||
def test_advanced_nested_class_attributes(capsys: CaptureFixture) -> None:
|
||||
def test_advanced_nested_class_attributes(caplog: LogCaptureFixture) -> None:
|
||||
class SubSubSubClass(DataService):
|
||||
name = "Hello"
|
||||
|
||||
@ -209,32 +171,17 @@ def test_advanced_nested_class_attributes(capsys: CaptureFixture) -> None:
|
||||
subattr = SubSubClass()
|
||||
|
||||
service_instance = ServiceClass()
|
||||
_ = capsys.readouterr()
|
||||
service_instance.attr.attr.attr.name = "Hi"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr.attr.attr.name = Hi",
|
||||
"ServiceClass.subattr.attr.name = Hi",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr.attr.attr.name changed to Hi" in caplog.text
|
||||
assert "ServiceClass.subattr.attr.name changed to Hi" in caplog.text
|
||||
service_instance.subattr.attr.name = "Ho"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr.attr.attr.name = Ho",
|
||||
"ServiceClass.subattr.attr.name = Ho",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr.attr.attr.name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.subattr.attr.name changed to Ho" in caplog.text
|
||||
|
||||
|
||||
def test_advanced_nested_instance_attributes(capsys: CaptureFixture) -> None:
|
||||
def test_advanced_nested_instance_attributes(caplog: LogCaptureFixture) -> None:
|
||||
class SubSubSubClass(DataService):
|
||||
name = "Hello"
|
||||
|
||||
@ -257,32 +204,19 @@ def test_advanced_nested_instance_attributes(capsys: CaptureFixture) -> None:
|
||||
super().__init__()
|
||||
|
||||
service_instance = ServiceClass()
|
||||
_ = capsys.readouterr()
|
||||
|
||||
service_instance.attr.attr.attr.name = "Hi"
|
||||
assert "ServiceClass.attr.attr.attr.name changed to Hi" in caplog.text
|
||||
assert "ServiceClass.subattr.attr.name changed to Hi" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr.attr.attr.name = Hi",
|
||||
"ServiceClass.subattr.attr.name = Hi",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
service_instance.subattr.attr.name = "Ho"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr.attr.attr.name = Ho",
|
||||
"ServiceClass.subattr.attr.name = Ho",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr.attr.attr.name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.subattr.attr.name changed to Ho" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
|
||||
def test_advanced_nested_attributes_mixed(capsys: CaptureFixture) -> None:
|
||||
def test_advanced_nested_attributes_mixed(caplog: LogCaptureFixture) -> None:
|
||||
class SubSubClass(DataService):
|
||||
name = "Hello"
|
||||
|
||||
@ -310,44 +244,28 @@ def test_advanced_nested_attributes_mixed(capsys: CaptureFixture) -> None:
|
||||
# instances of SubSubClass are unequal
|
||||
assert service_instance.attr.attr_1 != service_instance.class_attr.class_attr
|
||||
|
||||
_ = capsys.readouterr()
|
||||
|
||||
service_instance.class_attr.class_attr.name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.class_attr.class_attr.name = Ho",
|
||||
"ServiceClass.attr.class_attr.name = Ho",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.class_attr.class_attr.name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.attr.class_attr.name changed to Ho" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
service_instance.class_attr.attr_1.name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(["ServiceClass.class_attr.attr_1.name = Ho"])
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.class_attr.attr_1.name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.attr.attr_1.name changed to Ho" not in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
service_instance.attr.class_attr.name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr.class_attr.name = Ho",
|
||||
"ServiceClass.class_attr.class_attr.name = Ho",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.class_attr.class_attr.name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.attr.class_attr.name changed to Ho" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
service_instance.attr.attr_1.name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(["ServiceClass.attr.attr_1.name = Ho"])
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr.attr_1.name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.class_attr.attr_1.name changed to Ho" not in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
|
||||
def test_class_list_attributes(capsys: CaptureFixture) -> None:
|
||||
def test_class_list_attributes(caplog: LogCaptureFixture) -> None:
|
||||
class SubClass(DataService):
|
||||
name = "Hello"
|
||||
|
||||
@ -359,59 +277,36 @@ def test_class_list_attributes(capsys: CaptureFixture) -> None:
|
||||
attr = subclass_instance
|
||||
|
||||
service_instance = ServiceClass()
|
||||
_ = capsys.readouterr()
|
||||
|
||||
assert service_instance.attr_list[0] != service_instance.attr_list[1]
|
||||
|
||||
service_instance.attr_list[0].name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr_list[0].name = Ho",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr_list[0].name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.attr_list[1].name changed to Ho" not in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
service_instance.attr_list[1].name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr_list[1].name = Ho",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr_list[0].name changed to Ho" not in caplog.text
|
||||
assert "ServiceClass.attr_list[1].name changed to Ho" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
assert service_instance.attr_list_2[0] == service_instance.attr
|
||||
assert service_instance.attr_list_2[0] == service_instance.attr_list_2[1]
|
||||
|
||||
service_instance.attr_list_2[0].name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr_list_2[0].name = Ho",
|
||||
"ServiceClass.attr_list_2[1].name = Ho",
|
||||
"ServiceClass.attr.name = Ho",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr_list_2[0].name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.attr_list_2[1].name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.attr.name changed to Ho" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
service_instance.attr_list_2[1].name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr_list_2[0].name = Ho",
|
||||
"ServiceClass.attr_list_2[1].name = Ho",
|
||||
"ServiceClass.attr.name = Ho",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr_list_2[0].name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.attr_list_2[1].name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.attr.name changed to Ho" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
|
||||
def test_nested_class_list_attributes(capsys: CaptureFixture) -> None:
|
||||
def test_nested_class_list_attributes(caplog: LogCaptureFixture) -> None:
|
||||
class SubSubClass(DataService):
|
||||
name = "Hello"
|
||||
|
||||
@ -425,34 +320,21 @@ def test_nested_class_list_attributes(capsys: CaptureFixture) -> None:
|
||||
subattr = subsubclass_instance
|
||||
|
||||
service_instance = ServiceClass()
|
||||
_ = capsys.readouterr()
|
||||
|
||||
assert service_instance.attr[0].attr_list[0] == service_instance.subattr
|
||||
|
||||
service_instance.attr[0].attr_list[0].name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr[0].attr_list[0].name = Ho",
|
||||
"ServiceClass.subattr.name = Ho",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr[0].attr_list[0].name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.subattr.name changed to Ho" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
service_instance.subattr.name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr[0].attr_list[0].name = Ho",
|
||||
"ServiceClass.subattr.name = Ho",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr[0].attr_list[0].name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.subattr.name changed to Ho" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
|
||||
def test_instance_list_attributes(capsys: CaptureFixture) -> None:
|
||||
def test_instance_list_attributes(caplog: LogCaptureFixture) -> None:
|
||||
class SubClass(DataService):
|
||||
name = "Hello"
|
||||
|
||||
@ -466,63 +348,42 @@ def test_instance_list_attributes(capsys: CaptureFixture) -> None:
|
||||
super().__init__()
|
||||
|
||||
service_instance = ServiceClass()
|
||||
_ = capsys.readouterr()
|
||||
|
||||
assert service_instance.attr_list[0] != service_instance.attr_list[1]
|
||||
|
||||
service_instance.attr_list[0].name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(["ServiceClass.attr_list[0].name = Ho"])
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr_list[0].name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.attr_list[1].name changed to Ho" not in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
service_instance.attr_list[1].name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(["ServiceClass.attr_list[1].name = Ho"])
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr_list[0].name changed to Ho" not in caplog.text
|
||||
assert "ServiceClass.attr_list[1].name changed to Ho" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
assert service_instance.attr_list_2[0] == service_instance.attr
|
||||
assert service_instance.attr_list_2[0] == service_instance.attr_list_2[1]
|
||||
|
||||
service_instance.attr_list_2[0].name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr.name = Ho",
|
||||
"ServiceClass.attr_list_2[0].name = Ho",
|
||||
"ServiceClass.attr_list_2[1].name = Ho",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr.name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.attr_list_2[0].name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.attr_list_2[1].name changed to Ho" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
service_instance.attr_list_2[1].name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr.name = Ho",
|
||||
"ServiceClass.attr_list_2[0].name = Ho",
|
||||
"ServiceClass.attr_list_2[1].name = Ho",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr.name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.attr_list_2[0].name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.attr_list_2[1].name changed to Ho" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
service_instance.attr.name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr.name = Ho",
|
||||
"ServiceClass.attr_list_2[0].name = Ho",
|
||||
"ServiceClass.attr_list_2[1].name = Ho",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr.name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.attr_list_2[0].name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.attr_list_2[1].name changed to Ho" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
|
||||
def test_nested_instance_list_attributes(capsys: CaptureFixture) -> None:
|
||||
def test_nested_instance_list_attributes(caplog: LogCaptureFixture) -> None:
|
||||
class SubSubClass(DataService):
|
||||
name = "Hello"
|
||||
|
||||
@ -541,28 +402,15 @@ def test_nested_instance_list_attributes(capsys: CaptureFixture) -> None:
|
||||
super().__init__()
|
||||
|
||||
service_instance = ServiceClass()
|
||||
_ = capsys.readouterr()
|
||||
|
||||
assert service_instance.attr[0].attr_list[0] == service_instance.class_attr
|
||||
|
||||
service_instance.attr[0].attr_list[0].name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr[0].attr_list[0].name = Ho",
|
||||
"ServiceClass.class_attr.name = Ho",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr[0].attr_list[0].name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.class_attr.name changed to Ho" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
service_instance.class_attr.name = "Ho"
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.attr[0].attr_list[0].name = Ho",
|
||||
"ServiceClass.class_attr.name = Ho",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.attr[0].attr_list[0].name changed to Ho" in caplog.text
|
||||
assert "ServiceClass.class_attr.name changed to Ho" in caplog.text
|
||||
caplog.clear()
|
||||
|
@ -1,9 +1,9 @@
|
||||
from pytest import CaptureFixture
|
||||
from pytest import LogCaptureFixture
|
||||
|
||||
from pydase import DataService
|
||||
|
||||
|
||||
def test_properties(capsys: CaptureFixture) -> None:
|
||||
def test_properties(caplog: LogCaptureFixture) -> None:
|
||||
class ServiceClass(DataService):
|
||||
_voltage = 10.0
|
||||
_current = 1.0
|
||||
@ -31,30 +31,17 @@ def test_properties(capsys: CaptureFixture) -> None:
|
||||
test_service = ServiceClass()
|
||||
test_service.voltage = 1
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.power = 1.0",
|
||||
"ServiceClass.voltage = 1.0",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.power changed to 1.0" in caplog.text
|
||||
assert "ServiceClass.voltage changed to 1.0" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
test_service.current = 12.0
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.power = 12.0",
|
||||
"ServiceClass.current = 12.0",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.power changed to 12.0" in caplog.text
|
||||
assert "ServiceClass.current changed to 12.0" in caplog.text
|
||||
|
||||
|
||||
def test_nested_properties(capsys: CaptureFixture) -> None:
|
||||
def test_nested_properties(caplog: LogCaptureFixture) -> None:
|
||||
class SubSubClass(DataService):
|
||||
name = "Hello"
|
||||
|
||||
@ -77,45 +64,31 @@ def test_nested_properties(capsys: CaptureFixture) -> None:
|
||||
test_service = ServiceClass()
|
||||
test_service.name = "Peepz"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.name = Peepz",
|
||||
"ServiceClass.sub_name = Hello Peepz",
|
||||
"ServiceClass.subsub_name = Hello Peepz",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.name changed to Peepz" in caplog.text
|
||||
assert "ServiceClass.sub_name changed to Hello Peepz" in caplog.text
|
||||
assert "ServiceClass.subsub_name changed to Hello Peepz" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
test_service.class_attr.name = "Hi"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.sub_name = Hi Peepz",
|
||||
"ServiceClass.subsub_name = Hello Peepz", # registers subclass changes
|
||||
"ServiceClass.class_attr.name = Hi",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.sub_name changed to Hi Peepz" in caplog.text
|
||||
assert (
|
||||
"ServiceClass.subsub_name changed to Hello Peepz" in caplog.text
|
||||
) # registers subclass changes
|
||||
assert "ServiceClass.class_attr.name changed to Hi" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
test_service.class_attr.class_attr.name = "Ciao"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.sub_name = Hi Peepz", # registers subclass changes
|
||||
"ServiceClass.subsub_name = Ciao Peepz",
|
||||
"ServiceClass.class_attr.class_attr.name = Ciao",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert (
|
||||
"ServiceClass.sub_name changed to Hi Peepz" in caplog.text
|
||||
) # registers subclass changes
|
||||
assert "ServiceClass.subsub_name changed to Ciao Peepz" in caplog.text
|
||||
assert "ServiceClass.class_attr.class_attr.name changed to Ciao" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
|
||||
def test_simple_list_properties(capsys: CaptureFixture) -> None:
|
||||
def test_simple_list_properties(caplog: LogCaptureFixture) -> None:
|
||||
class ServiceClass(DataService):
|
||||
list = ["Hello", "Ciao"]
|
||||
name = "World"
|
||||
@ -127,30 +100,17 @@ def test_simple_list_properties(capsys: CaptureFixture) -> None:
|
||||
test_service = ServiceClass()
|
||||
test_service.name = "Peepz"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.name = Peepz",
|
||||
"ServiceClass.total_name = Hello Peepz",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.name changed to Peepz" in caplog.text
|
||||
assert "ServiceClass.total_name changed to Hello Peepz" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
test_service.list[0] = "Hi"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.total_name = Hi Peepz",
|
||||
"ServiceClass.list[0] = Hi",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.total_name changed to Hi Peepz" in caplog.text
|
||||
assert "ServiceClass.list[0] changed to Hi" in caplog.text
|
||||
|
||||
|
||||
def test_class_list_properties(capsys: CaptureFixture) -> None:
|
||||
def test_class_list_properties(caplog: LogCaptureFixture) -> None:
|
||||
class SubClass(DataService):
|
||||
name = "Hello"
|
||||
|
||||
@ -165,30 +125,17 @@ def test_class_list_properties(capsys: CaptureFixture) -> None:
|
||||
test_service = ServiceClass()
|
||||
test_service.name = "Peepz"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.name = Peepz",
|
||||
"ServiceClass.total_name = Hello Peepz",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.name changed to Peepz" in caplog.text
|
||||
assert "ServiceClass.total_name changed to Hello Peepz" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
test_service.list[0].name = "Hi"
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.total_name = Hi Peepz",
|
||||
"ServiceClass.list[0].name = Hi",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n"))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.total_name changed to Hi Peepz" in caplog.text
|
||||
assert "ServiceClass.list[0].name changed to Hi" in caplog.text
|
||||
|
||||
|
||||
def test_subclass_properties(capsys: CaptureFixture) -> None:
|
||||
def test_subclass_properties(caplog: LogCaptureFixture) -> None:
|
||||
class SubClass(DataService):
|
||||
name = "Hello"
|
||||
_voltage = 10.0
|
||||
@ -224,21 +171,15 @@ def test_subclass_properties(capsys: CaptureFixture) -> None:
|
||||
test_service = ServiceClass()
|
||||
test_service.class_attr.voltage = 10.0
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
{
|
||||
"ServiceClass.class_attr.voltage = 10.0",
|
||||
"ServiceClass.class_attr.power = 10.0",
|
||||
"ServiceClass.voltage = 10.0",
|
||||
}
|
||||
)
|
||||
# using a set here as "ServiceClass.voltage = 10.0" is emitted twice. Once for
|
||||
# changing voltage, and once for changing power.
|
||||
actual_output = sorted(set(captured.out.strip().split("\n")))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.class_attr.voltage changed to 10.0" in caplog.text
|
||||
assert "ServiceClass.class_attr.power changed to 10.0" in caplog.text
|
||||
assert "ServiceClass.voltage changed to 10.0" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
|
||||
def test_subclass_properties_2(capsys: CaptureFixture) -> None:
|
||||
def test_subclass_properties_2(caplog: LogCaptureFixture) -> None:
|
||||
class SubClass(DataService):
|
||||
name = "Hello"
|
||||
_voltage = 10.0
|
||||
@ -274,24 +215,17 @@ def test_subclass_properties_2(capsys: CaptureFixture) -> None:
|
||||
test_service = ServiceClass()
|
||||
test_service.class_attr[1].current = 10.0
|
||||
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
{
|
||||
"ServiceClass.class_attr[1].current = 10.0",
|
||||
"ServiceClass.class_attr[1].power = 100.0",
|
||||
"ServiceClass.voltage = 10.0",
|
||||
}
|
||||
)
|
||||
# using a set here as "ServiceClass.voltage = 10.0" is emitted twice. Once for
|
||||
# changing current, and once for changing power. Note that the voltage property is
|
||||
# only dependent on class_attr[0] but still emits an update notification. This is
|
||||
# because every time any item in the list `test_service.class_attr` is changed,
|
||||
# a notification will be emitted.
|
||||
actual_output = sorted(set(captured.out.strip().split("\n")))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.class_attr[1].current changed to 10.0" in caplog.text
|
||||
assert "ServiceClass.class_attr[1].power changed to 100.0" in caplog.text
|
||||
assert "ServiceClass.voltage changed to 10.0" in caplog.text
|
||||
|
||||
|
||||
def test_subsubclass_properties(capsys: CaptureFixture) -> None:
|
||||
def test_subsubclass_properties(caplog: LogCaptureFixture) -> None:
|
||||
class SubSubClass(DataService):
|
||||
_voltage = 10.0
|
||||
|
||||
@ -321,21 +255,18 @@ def test_subsubclass_properties(capsys: CaptureFixture) -> None:
|
||||
test_service = ServiceClass()
|
||||
|
||||
test_service.class_attr[1].class_attr.voltage = 100.0
|
||||
captured = capsys.readouterr()
|
||||
expected_output = sorted(
|
||||
{
|
||||
"ServiceClass.class_attr[0].class_attr.voltage = 100.0",
|
||||
"ServiceClass.class_attr[1].class_attr.voltage = 100.0",
|
||||
"ServiceClass.class_attr[0].power = 50.0",
|
||||
"ServiceClass.class_attr[1].power = 50.0",
|
||||
"ServiceClass.power = 50.0",
|
||||
}
|
||||
assert (
|
||||
"ServiceClass.class_attr[0].class_attr.voltage changed to 100.0" in caplog.text
|
||||
)
|
||||
actual_output = sorted(set(captured.out.strip().split("\n")))
|
||||
assert actual_output == expected_output
|
||||
assert (
|
||||
"ServiceClass.class_attr[1].class_attr.voltage changed to 100.0" in caplog.text
|
||||
)
|
||||
assert "ServiceClass.class_attr[0].power changed to 50.0" in caplog.text
|
||||
assert "ServiceClass.class_attr[1].power changed to 50.0" in caplog.text
|
||||
assert "ServiceClass.power changed to 50.0" in caplog.text
|
||||
|
||||
|
||||
def test_subsubclass_instance_properties(capsys: CaptureFixture) -> None:
|
||||
def test_subsubclass_instance_properties(caplog: LogCaptureFixture) -> None:
|
||||
class SubSubClass(DataService):
|
||||
def __init__(self) -> None:
|
||||
self._voltage = 10.0
|
||||
@ -369,16 +300,9 @@ def test_subsubclass_instance_properties(capsys: CaptureFixture) -> None:
|
||||
test_service = ServiceClass()
|
||||
|
||||
test_service.class_attr[1].attr[0].voltage = 100.0
|
||||
captured = capsys.readouterr()
|
||||
# again, changing an item in a list will trigger the callbacks. This is why a
|
||||
# notification for `ServiceClass.power` is emitted although it did not change its
|
||||
# value
|
||||
expected_output = sorted(
|
||||
{
|
||||
"ServiceClass.class_attr[1].attr[0].voltage = 100.0",
|
||||
"ServiceClass.class_attr[1].power = 50.0",
|
||||
"ServiceClass.power = 5.0",
|
||||
}
|
||||
)
|
||||
actual_output = sorted(set(captured.out.strip().split("\n")))
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.class_attr[1].attr[0].voltage changed to 100.0" in caplog.text
|
||||
assert "ServiceClass.class_attr[1].power changed to 50.0" in caplog.text
|
||||
assert "ServiceClass.power changed to 5.0" in caplog.text
|
||||
|
@ -1,12 +1,12 @@
|
||||
from typing import Any
|
||||
|
||||
from pytest import CaptureFixture
|
||||
from pytest import LogCaptureFixture
|
||||
|
||||
import pydase.units as u
|
||||
from pydase.data_service.data_service import DataService
|
||||
|
||||
|
||||
def test_DataService_setattr(capsys: CaptureFixture) -> None:
|
||||
def test_DataService_setattr(caplog: LogCaptureFixture) -> None:
|
||||
class ServiceClass(DataService):
|
||||
voltage = 1.0 * u.units.V
|
||||
_current: u.Quantity = 1.0 * u.units.mA
|
||||
@ -28,31 +28,17 @@ def test_DataService_setattr(capsys: CaptureFixture) -> None:
|
||||
|
||||
assert service.voltage == 10.0 * u.units.V # type: ignore
|
||||
assert service.current == 1.5 * u.units.mA
|
||||
captured = capsys.readouterr()
|
||||
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.voltage = 10.0 V",
|
||||
"ServiceClass.current = 1.5 mA",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n")) # type: ignore
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.voltage changed to 10.0 V" in caplog.text
|
||||
assert "ServiceClass.current changed to 1.5 mA" in caplog.text
|
||||
|
||||
service.voltage = 12.0 * u.units.V # type: ignore
|
||||
service.current = 1.51 * u.units.A
|
||||
assert service.voltage == 12.0 * u.units.V # type: ignore
|
||||
assert service.current == 1.51 * u.units.A
|
||||
captured = capsys.readouterr()
|
||||
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.voltage = 12.0 V",
|
||||
"ServiceClass.current = 1.51 A",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n")) # type: ignore
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.voltage changed to 12.0 V" in caplog.text
|
||||
assert "ServiceClass.current changed to 1.51 A" in caplog.text
|
||||
|
||||
|
||||
def test_convert_to_quantity() -> None:
|
||||
@ -62,7 +48,7 @@ def test_convert_to_quantity() -> None:
|
||||
assert u.convert_to_quantity(1.0 * u.units.mV) == 1.0 * u.units.mV
|
||||
|
||||
|
||||
def test_update_DataService_attribute(capsys: CaptureFixture) -> None:
|
||||
def test_update_DataService_attribute(caplog: LogCaptureFixture) -> None:
|
||||
class ServiceClass(DataService):
|
||||
voltage = 1.0 * u.units.V
|
||||
_current: u.Quantity = 1.0 * u.units.mA
|
||||
@ -80,39 +66,18 @@ def test_update_DataService_attribute(capsys: CaptureFixture) -> None:
|
||||
service.update_DataService_attribute(
|
||||
path_list=[], attr_name="voltage", value=1.0 * u.units.mV
|
||||
)
|
||||
captured = capsys.readouterr()
|
||||
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.voltage = 1.0 mV",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n")) # type: ignore
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.voltage changed to 1.0 mV" in caplog.text
|
||||
|
||||
service.update_DataService_attribute(path_list=[], attr_name="voltage", value=2)
|
||||
captured = capsys.readouterr()
|
||||
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.voltage = 2.0 mV",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n")) # type: ignore
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.voltage changed to 2.0 mV" in caplog.text
|
||||
|
||||
service.update_DataService_attribute(
|
||||
path_list=[], attr_name="voltage", value={"magnitude": 123, "unit": "kV"}
|
||||
)
|
||||
captured = capsys.readouterr()
|
||||
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.voltage = 123.0 kV",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n")) # type: ignore
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.voltage changed to 123.0 kV" in caplog.text
|
||||
|
||||
|
||||
def test_autoconvert_offset_to_baseunit() -> None:
|
||||
@ -126,7 +91,7 @@ def test_autoconvert_offset_to_baseunit() -> None:
|
||||
assert False, f"Offset unit raises exception {exc}"
|
||||
|
||||
|
||||
def test_loading_from_json(capsys: CaptureFixture) -> None:
|
||||
def test_loading_from_json(caplog: LogCaptureFixture) -> None:
|
||||
"""This function tests if the quantity read from the json description is actually
|
||||
passed as a quantity to the property setter."""
|
||||
JSON_DICT = {
|
||||
@ -156,12 +121,4 @@ def test_loading_from_json(capsys: CaptureFixture) -> None:
|
||||
|
||||
service.load_DataService_from_JSON(JSON_DICT)
|
||||
|
||||
captured = capsys.readouterr()
|
||||
|
||||
expected_output = sorted(
|
||||
[
|
||||
"ServiceClass.some_unit = 10.0 A",
|
||||
]
|
||||
)
|
||||
actual_output = sorted(captured.out.strip().split("\n")) # type: ignore
|
||||
assert actual_output == expected_output
|
||||
assert "ServiceClass.some_unit changed to 10.0 A" in caplog.text
|
||||
|
Loading…
x
Reference in New Issue
Block a user