Skip to content

Commit 016344f

Browse files
committed
tests: amend tests to use controller vetor
1 parent d520bbe commit 016344f

File tree

2 files changed

+54
-41
lines changed

2 files changed

+54
-41
lines changed

tests/transport/epics/ca/test_softioc_system.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,31 @@ def test_ioc(softioc_subprocess: tuple[str, Queue]):
1616
assert parent_pvi["value"] == {
1717
"a": {"r": f"{pv_prefix}:A"},
1818
"b": {"r": f"{pv_prefix}:B_RBV", "w": f"{pv_prefix}:B"},
19-
"child": {"d": f"{pv_prefix}:Child:PVI"},
19+
"childvector": {"d": f"{pv_prefix}:ChildVector:PVI"},
2020
}
2121

22-
child_pvi_pv = parent_pvi["value"]["child"]["d"]
22+
child_vector_pvi_pv = parent_pvi["value"]["childvector"]["d"]
23+
_child_vector_pvi = ctxt.get(child_vector_pvi_pv)
24+
assert isinstance(_child_vector_pvi, Value)
25+
_child_vector_pvi = _child_vector_pvi.todict()
26+
assert all(
27+
f in _child_vector_pvi for f in ("alarm", "display", "timeStamp", "value")
28+
)
29+
assert _child_vector_pvi["display"] == {
30+
"description": "The records in this controller"
31+
}
32+
assert _child_vector_pvi["value"] == {
33+
"childvector0": {"d": f"{pv_prefix}:ChildVector:0:PVI"},
34+
"childvector1": {"d": f"{pv_prefix}:ChildVector:1:PVI"},
35+
}
36+
37+
child_pvi_pv = _child_vector_pvi["value"]["childvector0"]["d"]
2338
_child_pvi = ctxt.get(child_pvi_pv)
2439
assert isinstance(_child_pvi, Value)
2540
child_pvi = _child_pvi.todict()
2641
assert all(f in child_pvi for f in ("alarm", "display", "timeStamp", "value"))
2742
assert child_pvi["display"] == {"description": "The records in this controller"}
2843
assert child_pvi["value"] == {
29-
"c": {"w": f"{pv_prefix}:Child:C"},
30-
"d": {"x": f"{pv_prefix}:Child:D"},
44+
"c": {"w": f"{pv_prefix}:ChildVector:0:C"},
45+
"d": {"x": f"{pv_prefix}:ChildVector:0:D"},
3146
}

tests/transport/epics/pva/test_p4p.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,42 @@ async def test_ioc(p4p_subprocess: tuple[str, Queue]):
3535
assert parent_pvi["value"] == {
3636
"a": {"rw": f"{pv_prefix}:A"},
3737
"b": {"w": f"{pv_prefix}:B"},
38-
"child": {
39-
"d": {
40-
"v1": f"{pv_prefix}:Child1:PVI",
41-
"v2": f"{pv_prefix}:Child2:PVI",
42-
}
43-
},
38+
"child": {"d": f"{pv_prefix}:Child:PVI"},
4439
"table": {
4540
"rw": f"{pv_prefix}:Table",
4641
},
4742
}
4843

49-
child_pvi_pv = parent_pvi["value"]["child"]["d"]["v1"]
44+
child_vector_pvi_pv = parent_pvi["value"]["child"]["d"]
45+
_child_vector_pvi = await ctxt.get(child_vector_pvi_pv)
46+
assert isinstance(_child_vector_pvi, Value)
47+
_child_vector_pvi = _child_vector_pvi.todict()
48+
assert all(
49+
f in _child_vector_pvi for f in ("alarm", "display", "timeStamp", "value")
50+
)
51+
assert _child_vector_pvi["display"] == {"description": "some child vector"}
52+
assert _child_vector_pvi["value"] == {
53+
"vector_attribute": {"r": f"{pv_prefix}:Child:VectorAttribute"},
54+
"child": {
55+
"d": {"v1": f"{pv_prefix}:Child:1:PVI", "v2": f"{pv_prefix}:Child:2:PVI"}
56+
},
57+
}
58+
59+
child_pvi_pv = _child_vector_pvi["value"]["child"]["d"]["v1"]
5060
_child_pvi = await ctxt.get(child_pvi_pv)
5161
assert isinstance(_child_pvi, Value)
5262
child_pvi = _child_pvi.todict()
5363
assert all(f in child_pvi for f in ("alarm", "display", "timeStamp", "value"))
5464
assert child_pvi["display"] == {"description": "some sub controller"}
5565
assert child_pvi["value"] == {
56-
"c": {"w": f"{pv_prefix}:Child1:C"},
57-
"d": {"x": f"{pv_prefix}:Child1:D"},
58-
"e": {"r": f"{pv_prefix}:Child1:E"},
59-
"f": {"rw": f"{pv_prefix}:Child1:F"},
60-
"g": {"rw": f"{pv_prefix}:Child1:G"},
61-
"h": {"rw": f"{pv_prefix}:Child1:H"},
62-
"i": {"x": f"{pv_prefix}:Child1:I"},
63-
"j": {"r": f"{pv_prefix}:Child1:J"},
66+
"c": {"w": f"{pv_prefix}:Child:1:C"},
67+
"d": {"x": f"{pv_prefix}:Child:1:D"},
68+
"e": {"r": f"{pv_prefix}:Child:1:E"},
69+
"f": {"rw": f"{pv_prefix}:Child:1:F"},
70+
"g": {"rw": f"{pv_prefix}:Child:1:G"},
71+
"h": {"rw": f"{pv_prefix}:Child:1:H"},
72+
"i": {"x": f"{pv_prefix}:Child:1:I"},
73+
"j": {"r": f"{pv_prefix}:Child:1:J"},
6474
}
6575

6676

@@ -74,7 +84,7 @@ async def test_scan_method(p4p_subprocess: tuple[str, Queue]):
7484
# time for the p4p transport to update, broadcast, get.
7585
latency = 1e8
7686

77-
e_monitor = ctxt.monitor(f"{pv_prefix}:Child1:E", e_values.put)
87+
e_monitor = ctxt.monitor(f"{pv_prefix}:Child:1:E", e_values.put)
7888
try:
7989
# Throw away the value on the ioc setup so we can compare timestamps
8090
_ = await e_values.get()
@@ -111,14 +121,14 @@ async def test_command_method(p4p_subprocess: tuple[str, Queue]):
111121
j_values = asyncio.Queue()
112122
ctxt = Context("pva")
113123

114-
d_monitor = ctxt.monitor(f"{pv_prefix}:Child1:D", d_values.put)
115-
i_monitor = ctxt.monitor(f"{pv_prefix}:Child1:I", i_values.put)
116-
j_monitor = ctxt.monitor(f"{pv_prefix}:Child1:J", j_values.put)
124+
d_monitor = ctxt.monitor(f"{pv_prefix}:Child:1:D", d_values.put)
125+
i_monitor = ctxt.monitor(f"{pv_prefix}:Child:1:I", i_values.put)
126+
j_monitor = ctxt.monitor(f"{pv_prefix}:Child:1:J", j_values.put)
117127

118128
try:
119129
j_initial_value = await j_values.get()
120130
assert (await d_values.get()).raw.value is False
121-
await ctxt.put(f"{pv_prefix}:Child1:D", True)
131+
await ctxt.put(f"{pv_prefix}:Child:1:D", True)
122132
assert (await d_values.get()).raw.value is True
123133
# D process hangs for 0.1s, so we wait slightly longer
124134
await asyncio.sleep(0.2)
@@ -132,7 +142,7 @@ async def test_command_method(p4p_subprocess: tuple[str, Queue]):
132142
assert before_command_value["value"] is False
133143
assert before_command_value["alarm"]["severity"] == 0
134144
assert before_command_value["alarm"]["message"] == ""
135-
await ctxt.put(f"{pv_prefix}:Child1:I", True)
145+
await ctxt.put(f"{pv_prefix}:Child:1:I", True)
136146
assert (await i_values.get()).raw.value is True
137147
await asyncio.sleep(0.2)
138148

@@ -146,7 +156,7 @@ async def test_command_method(p4p_subprocess: tuple[str, Queue]):
146156
assert j_values.empty()
147157

148158
# Second run succeeds
149-
await ctxt.put(f"{pv_prefix}:Child1:I", True)
159+
await ctxt.put(f"{pv_prefix}:Child:1:I", True)
150160
assert (await i_values.get()).raw.value is True
151161
await asyncio.sleep(0.2)
152162
after_command_value = (await i_values.get()).raw
@@ -270,9 +280,6 @@ class SomeController(Controller):
270280
{i: ChildController() for i in range(3)}
271281
)
272282

273-
for _, child in sub_controller_vector.children():
274-
child.add_sub_controller("ChildChild", ChildChildController())
275-
276283
controller.add_sub_controller("Child", sub_controller_vector)
277284

278285
sub_controller = ChildController()
@@ -348,17 +355,9 @@ class SomeController(Controller):
348355
"a_third_attr": {"w": f"{pv_prefix}:AThirdAttr"},
349356
"attr1": {"rw": f"{pv_prefix}:Attr1"},
350357
"child": {"d": f"{pv_prefix}:Child:PVI"},
351-
"child_attribute_same_name": {
352-
"d": f"{pv_prefix}:ChildAttributeSameName:PVI",
353-
"r": f"{pv_prefix}:ChildAttributeSameName",
354-
"child": {
355-
"d": {
356-
"v0": f"{pv_prefix}:Child0:PVI",
357-
"v1": f"{pv_prefix}:Child1:PVI",
358-
"v2": f"{pv_prefix}:Child2:PVI",
359-
}
360-
},
361-
},
358+
"child0": {"d": f"{pv_prefix}:Child0:PVI"},
359+
"child1": {"d": f"{pv_prefix}:Child1:PVI"},
360+
"child2": {"d": f"{pv_prefix}:Child2:PVI"},
362361
},
363362
}
364363
assert len(child_vector_controller_pvi) == 1
@@ -394,7 +393,6 @@ class SomeController(Controller):
394393
"attr_d": {
395394
"w": f"{pv_prefix}:Child:0:AttrD",
396395
},
397-
"child_child": {"d": f"{pv_prefix}:Child:0:ChildChild:PVI"},
398396
},
399397
}
400398

0 commit comments

Comments
 (0)