Skip to content

Commit

Permalink
WIP: flesh out IOC tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shilorigins committed Aug 16, 2024
1 parent 0147713 commit 8ae915c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 2 additions & 4 deletions superscore/tests/ioc/ioc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from multiprocessing import Process
from typing import Iterable, Mapping, Union

from caproto import ChannelString
from caproto.server import PVGroup, pvproperty
from caproto.server import run as run_ioc
from epicscorelibs.ca import dbr

from superscore.model import Entry, Nestable, Parameter, Readback, Setpoint

Expand Down Expand Up @@ -39,8 +39,6 @@ def from_entries(entries: Iterable[Entry], **ioc_options) -> PVGroup:
"""
attrs = IOCFactory.prepare_attrs(entries)
IOC = type("IOC", (TempIOC,), attrs)
#ioc = IOC(**ioc_options)
#return ioc
return IOC

@staticmethod
Expand All @@ -67,7 +65,7 @@ def prepare_attrs(entries: Iterable[Entry]) -> Mapping[str, pvproperty]:
attrs = {}
for entry in pvs:
value = entry.data if isinstance(entry, (Setpoint, Readback)) else None
pv = pvproperty(name=entry.pv_name, doc=entry.description, value=value)
pv = pvproperty(name=entry.pv_name, doc=entry.description, value=value, dtype=dbr.DBR_STRING if isinstance(entry.data, str) else None)
attr = "".join([c.lower() for c in entry.pv_name if c != ':'])
attrs[attr] = pv
return attrs
18 changes: 12 additions & 6 deletions superscore/tests/test_ioc.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
from epicscorelibs.ca import dbr

from superscore.control_layers.core import ControlLayer


def test_ioc(linac_ioc):
cl = ControlLayer()
assert cl.get("SCORETEST:MGNT:GUNB:TEST0").data == 1
cl.put("SCORETEST:MGNT:GUNB:TEST0", False)
cl.put("SCORETEST:MGNT:GUNB:TEST0", 0)
assert cl.get("SCORETEST:MGNT:GUNB:TEST0").data == 0

assert cl.get("SCORETEST:VAC:GUNB:TEST1").data.tobytes().decode() == "Ion Pump"
cl.put("SCORETEST:VAC:GUNB:TEST1", "new value".encode())
assert cl.get("SCORETEST:VAC:GUNB:TEST1").data.tobytes().decode() == "new value"
assert cl.get("SCORETEST:VAC:GUNB:TEST1").data == "Ion Pump"
cl.put("SCORETEST:VAC:GUNB:TEST1", "new value")
assert cl.get("SCORETEST:VAC:GUNB:TEST1").data == "new value"

assert cl.get("SCORETEST:LASR:GUNB:TEST2").data == 5
cl.put("SCORETEST:LASR:GUNB:TEST2", 10)
assert cl.get("SCORETEST:LASR:GUNB:TEST2").data == 10

assert cl.get("SCORETEST:LASR:IN10:TEST0").data == 645.26
cl.put("SCORETEST:LASR:IN10:TEST0", 600.0)
assert cl.get("SCORETEST:LASR:IN10:TEST0").data == 600.0

0 comments on commit 8ae915c

Please sign in to comment.