Skip to content

Commit c3f8d50

Browse files
authored
Add softioc functions to ca context (#191)
1 parent 5231029 commit c3f8d50

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/fastcs/transport/epics/ca/adapter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import asyncio
2+
from typing import Any
3+
4+
from softioc import softioc
25

36
from fastcs.controller_api import ControllerAPI
47
from fastcs.transport.adapter import TransportAdapter
@@ -40,3 +43,11 @@ def create_gui(self) -> None:
4043
async def serve(self) -> None:
4144
print(f"Running FastCS IOC: {self._pv_prefix}")
4245
self._ioc.run(self._loop)
46+
47+
@property
48+
def context(self) -> dict[str, Any]:
49+
return {
50+
command_name: getattr(softioc, command_name)
51+
for command_name in softioc.command_names
52+
if command_name != "exit"
53+
}

tests/transport/epics/ca/test_softioc.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55
import pytest
66
from pytest_mock import MockerFixture
7+
from softioc import softioc
78
from tests.assertable_controller import (
89
AssertableControllerAPI,
910
MyTestController,
@@ -19,6 +20,7 @@
1920
from fastcs.cs_methods import Command
2021
from fastcs.datatypes import Bool, Enum, Float, Int, String, Waveform
2122
from fastcs.exceptions import FastCSException
23+
from fastcs.transport.epics.ca.adapter import EpicsCATransport
2224
from fastcs.transport.epics.ca.ioc import (
2325
EPICS_MAX_NAME_LENGTH,
2426
EpicsCAIOC,
@@ -559,3 +561,15 @@ def test_update_datatype(mocker: MockerFixture):
559561
match="Attribute datatype must be of type <class 'fastcs.datatypes.Int'>",
560562
):
561563
attr_w.update_datatype(String()) # type: ignore
564+
565+
566+
def test_ca_context_contains_softioc_commands(mocker: MockerFixture):
567+
transport = EpicsCATransport(mocker.MagicMock(), mocker.MagicMock())
568+
569+
softioc_commands = {
570+
command: getattr(softioc, command) for command in softioc.command_names
571+
}
572+
# We exclude "exit" from the context
573+
softioc_commands.pop("exit")
574+
575+
assert transport.context == softioc_commands

0 commit comments

Comments
 (0)