mirror of
https://github.com/bec-project/ophyd_devices.git
synced 2025-07-10 18:51:53 +02:00
feat: added basic function tests
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import copy
|
import copy
|
||||||
|
import traceback
|
||||||
from io import TextIOWrapper
|
from io import TextIOWrapper
|
||||||
|
|
||||||
import ophyd
|
import ophyd
|
||||||
@ -147,15 +148,42 @@ class StaticDeviceTest:
|
|||||||
int: 0 if all checks passed, 1 otherwise
|
int: 0 if all checks passed, 1 otherwise
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
obj, _ = device_manager.construct_device_obj(conf, None)
|
conf_in = copy.deepcopy(conf)
|
||||||
|
conf_in["name"] = name
|
||||||
|
obj, _ = device_manager.construct_device_obj(conf_in, None)
|
||||||
|
|
||||||
device_manager.connect_device(obj, wait_for_all=True)
|
device_manager.connect_device(obj, wait_for_all=True)
|
||||||
|
assert obj.connected is True
|
||||||
|
self.check_basic_ophyd_methods(obj)
|
||||||
|
obj.destroy()
|
||||||
|
if hasattr(obj, "component_names") and obj.component_names:
|
||||||
|
assert obj.connected is False
|
||||||
|
assert obj._destroyed is True
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
except Exception as e:
|
except Exception:
|
||||||
self.print_and_write(f"ERROR: {name} is not connectable: {e}")
|
content = traceback.format_exc()
|
||||||
|
self.print_and_write(f"ERROR: {name} is not connectable: {content}")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
def check_basic_ophyd_methods(self, obj: ophyd.OphydObject) -> int:
|
||||||
|
"""
|
||||||
|
Check if the basic ophyd methods work
|
||||||
|
|
||||||
|
Args:
|
||||||
|
obj(ophyd.OphydObject): device object
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
assert isinstance(obj.name, str)
|
||||||
|
assert isinstance(obj.read(), dict)
|
||||||
|
assert isinstance(obj.read_configuration(), dict)
|
||||||
|
assert isinstance(obj.describe(), dict)
|
||||||
|
assert isinstance(obj.describe_configuration(), dict)
|
||||||
|
assert isinstance(obj.hints, dict)
|
||||||
|
|
||||||
def validate_schema(self, name: str, conf: dict) -> None:
|
def validate_schema(self, name: str, conf: dict) -> None:
|
||||||
"""
|
"""
|
||||||
Validate the device config against the BEC DB schema
|
Validate the device config against the BEC DB schema
|
||||||
|
Reference in New Issue
Block a user