diff --git a/tests/components/test_image.py b/tests/components/test_image.py new file mode 100644 index 0000000..4a42c42 --- /dev/null +++ b/tests/components/test_image.py @@ -0,0 +1,141 @@ +import logging + +import pydase +import pydase.components +from pydase.data_service.data_service_observer import DataServiceObserver +from pydase.data_service.state_manager import StateManager +from pydase.utils.serializer import dump +from pytest import LogCaptureFixture + +logger = logging.getLogger(__name__) + + +def test_image_functions(caplog: LogCaptureFixture) -> None: + class MyService(pydase.DataService): + def __init__(self) -> None: + super().__init__() + self.my_image = pydase.components.Image() + + service_instance = MyService() + state_manager = StateManager(service_instance) + DataServiceObserver(state_manager) + + service_instance.my_image.load_from_url("https://cataas.com/cat") + + caplog.clear() + + +def test_image_serialization() -> None: + class MyService(pydase.DataService): + def __init__(self) -> None: + super().__init__() + self.my_image = pydase.components.Image() + + assert dump(MyService()) == { + "name": "MyService", + "type": "DataService", + "value": { + "my_image": { + "name": "Image", + "type": "Image", + "value": { + "format": { + "type": "str", + "value": "", + "readonly": True, + "doc": None, + }, + "load_from_base64": { + "type": "method", + "value": None, + "readonly": True, + "doc": None, + "async": False, + "signature": { + "parameters": { + "value_": { + "annotation": "", + "default": {}, + }, + "format_": { + "annotation": "str | None", + "default": { + "type": "NoneType", + "value": None, + "readonly": False, + "doc": None, + }, + }, + }, + "return_annotation": {}, + }, + "frontend_render": False, + }, + "load_from_matplotlib_figure": { + "type": "method", + "value": None, + "readonly": True, + "doc": None, + "async": False, + "signature": { + "parameters": { + "fig": {"annotation": "Figure", "default": {}}, + "format_": { + "annotation": "", + "default": { + "type": "str", + "value": "png", + "readonly": False, + "doc": None, + }, + }, + }, + "return_annotation": {}, + }, + "frontend_render": False, + }, + "load_from_path": { + "type": "method", + "value": None, + "readonly": True, + "doc": None, + "async": False, + "signature": { + "parameters": { + "path": { + "annotation": "pathlib.Path | str", + "default": {}, + } + }, + "return_annotation": {}, + }, + "frontend_render": False, + }, + "load_from_url": { + "type": "method", + "value": None, + "readonly": True, + "doc": None, + "async": False, + "signature": { + "parameters": { + "url": {"annotation": "", "default": {}} + }, + "return_annotation": {}, + }, + "frontend_render": False, + }, + "value": { + "type": "str", + "value": "", + "readonly": True, + "doc": None, + }, + }, + "readonly": False, + "doc": None, + } + }, + "readonly": False, + "doc": None, + }