mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-20 08:20:02 +02:00
adds tests for Image component
This commit is contained in:
parent
b7926b730d
commit
c7d452d7db
141
tests/components/test_image.py
Normal file
141
tests/components/test_image.py
Normal file
@ -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": "<class 'bytes'>",
|
||||
"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": "<class 'str'>",
|
||||
"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": "<class 'str'>", "default": {}}
|
||||
},
|
||||
"return_annotation": {},
|
||||
},
|
||||
"frontend_render": False,
|
||||
},
|
||||
"value": {
|
||||
"type": "str",
|
||||
"value": "",
|
||||
"readonly": True,
|
||||
"doc": None,
|
||||
},
|
||||
},
|
||||
"readonly": False,
|
||||
"doc": None,
|
||||
}
|
||||
},
|
||||
"readonly": False,
|
||||
"doc": None,
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user