Skip to content

Commit 89e627a

Browse files
author
James Souter
committed
Move test_initial_values_set_in_ca to own file, use task instead of subprocess for serve
1 parent a98df60 commit 89e627a

File tree

4 files changed

+115
-114
lines changed

4 files changed

+115
-114
lines changed

tests/conftest.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from tests.assertable_controller import MyTestAttributeIORef, MyTestController
2727
from tests.example_p4p_ioc import run as _run_p4p_ioc
2828
from tests.example_softioc import run as _run_softioc
29-
from tests.example_softioc import run_initial_value as _run_initial
3029

3130

3231
@pytest.fixture(scope="function", autouse=True)
@@ -172,12 +171,6 @@ def softioc_subprocess():
172171
yield from run_ioc_as_subprocess(_run_softioc, multiprocessing.get_context())
173172

174173

175-
@pytest.fixture(scope="module")
176-
def initial_softioc_subprocess():
177-
multiprocessing.set_start_method("spawn", force=True)
178-
yield from run_ioc_as_subprocess(_run_initial, multiprocessing.get_context())
179-
180-
181174
@pytest.fixture(scope="session")
182175
def tango_system():
183176
subprocess.run(

tests/example_softioc.py

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
import enum
2-
3-
import numpy as np
4-
51
from fastcs.attributes import AttrR, AttrRW, AttrW
62
from fastcs.controller import Controller
7-
from fastcs.datatypes import Bool, Enum, Float, Int, String, Waveform
3+
from fastcs.datatypes import Int
84
from fastcs.launch import FastCS
95
from fastcs.transport.epics.ca.transport import EpicsCATransport
106
from fastcs.transport.epics.options import EpicsIOCOptions
117
from fastcs.wrappers import command
128

139

14-
class InitialEnum(enum.Enum):
15-
A = 0
16-
B = 1
17-
C = 2
18-
19-
2010
class ParentController(Controller):
2111
a: AttrR = AttrR(Int())
2212
b: AttrRW = AttrRW(Int())
@@ -30,33 +20,6 @@ async def d(self):
3020
pass
3121

3222

33-
class InitialValuesController(Controller):
34-
int = AttrRW(Int(), initial_value=4)
35-
float = AttrRW(Float(), initial_value=3.1)
36-
bool = AttrRW(Bool(), initial_value=True)
37-
enum = AttrRW(Enum(InitialEnum), initial_value=InitialEnum.B)
38-
str = AttrRW(String(), initial_value="initial")
39-
waveform = AttrRW(
40-
Waveform(np.int64, shape=(10,)),
41-
initial_value=np.array(range(10), dtype=np.int64),
42-
)
43-
int_r = AttrR(Int(), initial_value=5)
44-
float_r = AttrR(Float(), initial_value=4.1)
45-
bool_r = AttrR(Bool(), initial_value=False)
46-
enum_r = AttrR(Enum(InitialEnum), initial_value=InitialEnum.C)
47-
str_r = AttrR(String(), initial_value="initial_r")
48-
waveform_r = AttrR(
49-
Waveform(np.int64, shape=(10,)),
50-
initial_value=np.array(range(10, 20), dtype=np.int64),
51-
)
52-
int_w = AttrW(Int())
53-
float_w = AttrW(Float())
54-
bool_w = AttrW(Bool())
55-
enum_w = AttrW(Enum(InitialEnum))
56-
str_w = AttrW(String())
57-
waveform_w = AttrW(Waveform(np.int64, shape=(10,)))
58-
59-
6023
def run(pv_prefix="SOFTIOC_TEST_DEVICE"):
6124
controller = ParentController()
6225
controller.child = ChildController()
@@ -66,13 +29,5 @@ def run(pv_prefix="SOFTIOC_TEST_DEVICE"):
6629
fastcs.run(interactive=False)
6730

6831

69-
def run_initial_value(pv_prefix="SOFTIOC_INITIAL_DEVICE"):
70-
controller = InitialValuesController()
71-
fastcs = FastCS(
72-
controller, [EpicsCATransport(ca_ioc=EpicsIOCOptions(pv_prefix=pv_prefix))]
73-
)
74-
fastcs.run()
75-
76-
7732
if __name__ == "__main__":
7833
run()
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import asyncio
2+
import enum
3+
4+
import numpy as np
5+
import pytest
6+
from aioca import caget
7+
8+
from fastcs.attributes import AttrR, AttrRW, AttrW
9+
from fastcs.controller import Controller
10+
from fastcs.datatypes import Bool, Enum, Float, Int, String, Waveform
11+
from fastcs.launch import FastCS
12+
from fastcs.transport.epics.ca.transport import EpicsCATransport
13+
from fastcs.transport.epics.options import EpicsIOCOptions
14+
15+
16+
class InitialEnum(enum.Enum):
17+
A = 0
18+
B = 1
19+
C = 2
20+
21+
22+
class InitialValuesController(Controller):
23+
int = AttrRW(Int(), initial_value=4)
24+
float = AttrRW(Float(), initial_value=3.1)
25+
bool = AttrRW(Bool(), initial_value=True)
26+
enum = AttrRW(Enum(InitialEnum), initial_value=InitialEnum.B)
27+
str = AttrRW(String(), initial_value="initial")
28+
waveform = AttrRW(
29+
Waveform(np.int64, shape=(10,)),
30+
initial_value=np.array(range(10), dtype=np.int64),
31+
)
32+
int_r = AttrR(Int(), initial_value=5)
33+
float_r = AttrR(Float(), initial_value=4.1)
34+
bool_r = AttrR(Bool(), initial_value=False)
35+
enum_r = AttrR(Enum(InitialEnum), initial_value=InitialEnum.C)
36+
str_r = AttrR(String(), initial_value="initial_r")
37+
waveform_r = AttrR(
38+
Waveform(np.int64, shape=(10,)),
39+
initial_value=np.array(range(10, 20), dtype=np.int64),
40+
)
41+
int_w = AttrW(Int())
42+
float_w = AttrW(Float())
43+
bool_w = AttrW(Bool())
44+
enum_w = AttrW(Enum(InitialEnum))
45+
str_w = AttrW(String())
46+
waveform_w = AttrW(Waveform(np.int64, shape=(10,)))
47+
48+
49+
@pytest.mark.asyncio
50+
async def test_initial_values_set_in_ca():
51+
pv_prefix = "SOFTIOC_INITIAL_DEVICE"
52+
53+
loop = asyncio.get_event_loop()
54+
fastcs = FastCS(
55+
InitialValuesController(),
56+
[EpicsCATransport(ca_ioc=EpicsIOCOptions(pv_prefix=pv_prefix))],
57+
loop,
58+
)
59+
60+
task = asyncio.create_task(fastcs.serve(interactive=False))
61+
# combine cagets to reduce timeouts
62+
63+
# AttrRWs
64+
scalar_sets = await caget(
65+
[
66+
f"{pv_prefix}:Int",
67+
f"{pv_prefix}:Float",
68+
f"{pv_prefix}:Bool",
69+
f"{pv_prefix}:Enum",
70+
]
71+
)
72+
assert scalar_sets == [4, 3.1, 1, 1]
73+
scalar_rbvs = await caget(
74+
[
75+
f"{pv_prefix}:Int_RBV",
76+
f"{pv_prefix}:Float_RBV",
77+
f"{pv_prefix}:Bool_RBV",
78+
f"{pv_prefix}:Enum_RBV",
79+
]
80+
)
81+
assert scalar_rbvs == [4, 3.1, 1, 1]
82+
assert (await caget(f"{pv_prefix}:Str")).tobytes() == b"initial\0"
83+
assert np.array_equal((await caget(f"{pv_prefix}:Waveform")), list(range(10)))
84+
assert (await caget(f"{pv_prefix}:Str_RBV")).tobytes() == b"initial\0"
85+
assert np.array_equal((await caget(f"{pv_prefix}:Waveform_RBV")), list(range(10)))
86+
87+
# AttrRs
88+
scalars = await caget(
89+
[
90+
f"{pv_prefix}:IntR",
91+
f"{pv_prefix}:FloatR",
92+
f"{pv_prefix}:BoolR",
93+
f"{pv_prefix}:EnumR",
94+
]
95+
)
96+
assert scalars == [5, 4.1, 0, 2]
97+
assert (await caget(f"{pv_prefix}:StrR")).tobytes() == b"initial_r\0"
98+
assert np.array_equal((await caget(f"{pv_prefix}:WaveformR")), list(range(10, 20)))
99+
100+
# Check AttrWs use the datatype initial value
101+
w_scalars = await caget(
102+
[
103+
f"{pv_prefix}:IntW",
104+
f"{pv_prefix}:FloatW",
105+
f"{pv_prefix}:BoolW",
106+
f"{pv_prefix}:EnumW",
107+
]
108+
)
109+
assert w_scalars == [0, 0, 0, 0]
110+
assert (await caget(f"{pv_prefix}:StrW")).tobytes() == b"\0"
111+
# initial waveforms not set with zeros
112+
assert np.array_equal((await caget(f"{pv_prefix}:WaveformW")), [])
113+
114+
task.cancel()
Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
from multiprocessing import Queue
22

3-
import numpy as np
4-
import pytest
5-
from aioca import caget
63
from p4p import Value
74
from p4p.client.thread import Context
85

@@ -32,61 +29,3 @@ def test_ioc(softioc_subprocess: tuple[str, Queue]):
3229
"c": {"w": f"{pv_prefix}:Child:C"},
3330
"d": {"x": f"{pv_prefix}:Child:D"},
3431
}
35-
36-
37-
@pytest.mark.asyncio
38-
async def test_initial_values_set_in_ca(initial_softioc_subprocess):
39-
pv_prefix, _ = initial_softioc_subprocess
40-
# combine cagets to reduce timeouts
41-
42-
# AttrRWs
43-
44-
scalar_sets = await caget(
45-
[
46-
f"{pv_prefix}:Int",
47-
f"{pv_prefix}:Float",
48-
f"{pv_prefix}:Bool",
49-
f"{pv_prefix}:Enum",
50-
]
51-
)
52-
assert scalar_sets == [4, 3.1, 1, 1]
53-
scalar_rbvs = await caget(
54-
[
55-
f"{pv_prefix}:Int_RBV",
56-
f"{pv_prefix}:Float_RBV",
57-
f"{pv_prefix}:Bool_RBV",
58-
f"{pv_prefix}:Enum_RBV",
59-
]
60-
)
61-
assert scalar_rbvs == [4, 3.1, 1, 1]
62-
assert (await caget(f"{pv_prefix}:Str")).tobytes() == b"initial\0"
63-
assert np.array_equal((await caget(f"{pv_prefix}:Waveform")), list(range(10)))
64-
assert (await caget(f"{pv_prefix}:Str_RBV")).tobytes() == b"initial\0"
65-
assert np.array_equal((await caget(f"{pv_prefix}:Waveform_RBV")), list(range(10)))
66-
67-
# AttrRs
68-
scalars = await caget(
69-
[
70-
f"{pv_prefix}:IntR",
71-
f"{pv_prefix}:FloatR",
72-
f"{pv_prefix}:BoolR",
73-
f"{pv_prefix}:EnumR",
74-
]
75-
)
76-
assert scalars == [5, 4.1, 0, 2]
77-
assert (await caget(f"{pv_prefix}:StrR")).tobytes() == b"initial_r\0"
78-
assert np.array_equal((await caget(f"{pv_prefix}:WaveformR")), list(range(10, 20)))
79-
80-
# Check AttrWs use the datatype initial value
81-
w_scalars = await caget(
82-
[
83-
f"{pv_prefix}:IntW",
84-
f"{pv_prefix}:FloatW",
85-
f"{pv_prefix}:BoolW",
86-
f"{pv_prefix}:EnumW",
87-
]
88-
)
89-
return
90-
assert w_scalars == [0, 0, 0, 0]
91-
assert (await caget(f"{pv_prefix}:StrW")).tobytes() == b"\0"
92-
assert np.array_equal((await caget(f"{pv_prefix}:WaveformW")), 10 * [0])

0 commit comments

Comments
 (0)