Skip to content

Commit 6caaf1a

Browse files
authored
Merge pull request #25 from dls-controls/improve_coverage
Improve coverage
2 parents 12967f8 + 2878076 commit 6caaf1a

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

tests/sim_asyncio_ioc.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import time
55
import sys
66

7-
from softioc import softioc, builder, asyncio_dispatcher, pvlog
7+
from softioc import alarm, softioc, builder, asyncio_dispatcher, pvlog
88

99

1010
if __name__ == "__main__":
@@ -17,13 +17,20 @@
1717
import sim_records
1818

1919
async def callback(value):
20+
# Set the ao value, which will trigger on_update for it
21+
sim_records.t_ao.set(value)
2022
await asyncio.sleep(0.5)
21-
print("async update %s" % value)
23+
print("async update %s (%s)" % (value, sim_records.t_ai.get()))
2224
# Make sure it goes as epicsExit will not flush this for us
2325
sys.stdout.flush()
24-
sim_records.t_ai.set(value)
26+
# Set the ai alarm, but keep the value
27+
sim_records.t_ai.set_alarm(int(value) % 4, alarm.STATE_ALARM)
2528

26-
t_ao = builder.aOut('AO2', on_update=callback)
29+
# Set a different initial value
30+
sim_records.t_ai.set(23.45)
31+
32+
# Create a record to set the alarm
33+
t_ao = builder.aOut('ALARM', on_update=callback)
2734

2835
# Run the IOC
2936
builder.LoadDatabase()

tests/sim_records.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def on_update_name(value, name):
3535
t_stringout = stringOut(
3636
'STRINGOUT', initial_value='watevah', on_update=on_update)
3737
t_mbbo = mbbOut(
38-
'MBBO', 'Ein', 'Zwei', 'Drei', initial_value=1, on_update=on_update)
38+
'MBBO', 'Ein', 'Zwei', 'Drei', initial_value=1)
3939

4040
def update_sin_wf(value):
4141
print('update_sin_wf', value)

tests/test_asyncio.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import atexit
99
import pytest
10+
import time
1011

1112
PV_PREFIX = "".join(random.choice(string.ascii_uppercase) for _ in range(12))
1213

@@ -33,7 +34,7 @@ def asyncio_ioc():
3334
@pytest.mark.asyncio
3435
async def test_asyncio_ioc(asyncio_ioc):
3536
import asyncio
36-
from aioca import caget, caput, camonitor, CANothing, _catools, FORMAT_CTRL
37+
from aioca import caget, caput, camonitor, CANothing, _catools, FORMAT_TIME
3738
# Unregister the aioca atexit handler as it conflicts with the one installed
3839
# by cothread. If we don't do this we get a seg fault. This is not a problem
3940
# in production as we won't mix aioca and cothread, but we do mix them in
@@ -48,19 +49,25 @@ async def test_asyncio_ioc(asyncio_ioc):
4849
m = camonitor(PV_PREFIX + ":SIN", q.put, notify_disconnect=True)
4950
assert len(await asyncio.wait_for(q.get(), 1)) == 4
5051
# AO
51-
ao_val = await caget(PV_PREFIX + ":AO2", format=FORMAT_CTRL)
52+
ao_val = await caget(PV_PREFIX + ":ALARM", format=FORMAT_TIME)
5253
assert ao_val == 0
5354
assert ao_val.severity == 3 # INVALID
5455
assert ao_val.status == 17 # UDF
55-
await caput(PV_PREFIX + ":AO2", 3.56, wait=True)
56+
await caput(PV_PREFIX + ":ALARM", 3, wait=True)
5657
await asyncio.sleep(0.1)
57-
assert await caget(PV_PREFIX + ":AI") == 12.34
58+
ai_val = await caget(PV_PREFIX + ":AI", format=FORMAT_TIME)
59+
assert ai_val == 23.45
60+
assert ai_val.severity == 0
61+
assert ai_val.status == 0
5862
await asyncio.sleep(0.8)
59-
assert await caget(PV_PREFIX + ":AI") == 3.56
63+
ai_val = await caget(PV_PREFIX + ":AI", format=FORMAT_TIME)
64+
assert ai_val == 23.45
65+
assert ai_val.severity == 3
66+
assert ai_val.status == 7 # STATE_ALARM
6067
# Check pvaccess works
6168
from p4p.client.asyncio import Context
6269
with Context("pva") as ctx:
63-
assert await ctx.get(PV_PREFIX + ":AI") == 3.56
70+
assert await ctx.get(PV_PREFIX + ":AI") == 23.45
6471
# Wait for a bit longer for the print output to flush
6572
await asyncio.sleep(2)
6673
# Stop
@@ -73,8 +80,9 @@ async def test_asyncio_ioc(asyncio_ioc):
7380
# check closed and output
7481
assert "%s:SINN.VAL 1024 -> 4" % PV_PREFIX in out
7582
assert 'update_sin_wf 4' in out
76-
assert "%s:AO2.VAL 0 -> 3.56" % PV_PREFIX in out
77-
assert 'async update 3.56' in out
83+
assert "%s:ALARM.VAL 0 -> 3" % PV_PREFIX in out
84+
assert 'on_update %s:AO : 3.0' % PV_PREFIX in out
85+
assert 'async update 3.0 (23.45)' in out
7886
assert 'Starting iocInit' in err
7987
assert 'iocRun: All initialization complete' in err
8088
assert '(InteractiveConsole)' in err

0 commit comments

Comments
 (0)