11# Will be ignored on Python2 by conftest.py settings
22
3- import atexit
43import signal
54import pytest
6- from tests .conftest import SubprocessIOC , PV_PREFIX
7-
8-
9- def aioca_cleanup ():
10- from aioca import purge_channel_caches , _catools
11- # Unregister the aioca atexit handler as it conflicts with the one installed
12- # by cothread. If we don't do this we get a seg fault. This is not a problem
13- # in production as we won't mix aioca and cothread, but we do mix them in
14- # the tests so need to do this.
15- atexit .unregister (_catools ._catools_atexit )
16- # purge the channels before the event loop goes
17- purge_channel_caches ()
18-
19-
20- @pytest .fixture
21- def asyncio_ioc ():
22- ioc = SubprocessIOC ("sim_asyncio_ioc.py" )
23- yield ioc .proc
24- ioc .kill ()
25- aioca_cleanup ()
265
276
287@pytest .mark .asyncio
@@ -31,73 +10,67 @@ async def test_asyncio_ioc(asyncio_ioc):
3110 from aioca import caget , caput , camonitor , CANothing , _catools , FORMAT_TIME
3211
3312 # Start
34- assert (await caget (PV_PREFIX + ":UPTIME" )).startswith ("00:00:0" )
13+ pre = asyncio_ioc .pv_prefix
14+ assert (await caget (pre + ":UPTIME" )).startswith ("00:00:0" )
3515 # WAVEFORM
36- await caput (PV_PREFIX + ":SINN" , 4 , wait = True )
16+ await caput (pre + ":SINN" , 4 , wait = True )
3717 q = asyncio .Queue ()
38- m = camonitor (PV_PREFIX + ":SIN" , q .put , notify_disconnect = True )
18+ m = camonitor (pre + ":SIN" , q .put , notify_disconnect = True )
3919 assert len (await asyncio .wait_for (q .get (), 1 )) == 4
4020 # AO
41- ao_val = await caget (PV_PREFIX + ":ALARM" , format = FORMAT_TIME )
21+ ao_val = await caget (pre + ":ALARM" , format = FORMAT_TIME )
4222 assert ao_val == 0
4323 assert ao_val .severity == 3 # INVALID
4424 assert ao_val .status == 17 # UDF
45- await caput (PV_PREFIX + ":ALARM" , 3 , wait = True )
25+ await caput (pre + ":ALARM" , 3 , wait = True )
4626 await asyncio .sleep (0.1 )
47- ai_val = await caget (PV_PREFIX + ":AI" , format = FORMAT_TIME )
27+ ai_val = await caget (pre + ":AI" , format = FORMAT_TIME )
4828 assert ai_val == 23.45
4929 assert ai_val .severity == 0
5030 assert ai_val .status == 0
5131 await asyncio .sleep (0.8 )
52- ai_val = await caget (PV_PREFIX + ":AI" , format = FORMAT_TIME )
32+ ai_val = await caget (pre + ":AI" , format = FORMAT_TIME )
5333 assert ai_val == 23.45
5434 assert ai_val .severity == 3
5535 assert ai_val .status == 7 # STATE_ALARM
5636 # Check pvaccess works
5737 from p4p .client .asyncio import Context
5838 with Context ("pva" ) as ctx :
59- assert await ctx .get (PV_PREFIX + ":AI" ) == 23.45
39+ assert await ctx .get (pre + ":AI" ) == 23.45
6040 # Wait for a bit longer for the print output to flush
6141 await asyncio .sleep (2 )
6242 # Stop
63- out , err = asyncio_ioc .communicate (b"exit\n " , timeout = 5 )
43+ out , err = asyncio_ioc .proc . communicate (b"exit\n " , timeout = 5 )
6444 out = out .decode ()
6545 err = err .decode ()
6646 # Disconnect
6747 assert isinstance (await asyncio .wait_for (q .get (), 10 ), CANothing )
6848 m .close ()
6949 # check closed and output
70- assert "%s:SINN.VAL 1024 -> 4" % PV_PREFIX in out
50+ assert "%s:SINN.VAL 1024 -> 4" % pre in out
7151 assert 'update_sin_wf 4' in out
72- assert "%s:ALARM.VAL 0 -> 3" % PV_PREFIX in out
73- assert 'on_update %s:AO : 3.0' % PV_PREFIX in out
52+ assert "%s:ALARM.VAL 0 -> 3" % pre in out
53+ assert 'on_update %s:AO : 3.0' % pre in out
7454 assert 'async update 3.0 (23.45)' in out
7555 assert 'Starting iocInit' in err
7656 assert 'iocRun: All initialization complete' in err
7757 assert '(InteractiveConsole)' in err
7858
7959
80- @pytest .fixture
81- def asyncio_ioc_override ():
82- ioc = SubprocessIOC ("sim_asyncio_ioc_override.py" )
83- yield ioc .proc
84- ioc .kill ()
85- aioca_cleanup ()
86-
87-
8860@pytest .mark .asyncio
8961async def test_asyncio_ioc_override (asyncio_ioc_override ):
9062 from aioca import caget , caput
9163
9264 # Gain bo
93- assert (await caget (PV_PREFIX + ":GAIN" )) == 0
94- await caput (PV_PREFIX + ":GAIN" , "On" , wait = True )
95- assert (await caget (PV_PREFIX + ":GAIN" )) == 1
65+ pre = asyncio_ioc_override .pv_prefix
66+ assert (await caget (pre + ":GAIN" )) == 0
67+ await caput (pre + ":GAIN" , "On" , wait = True )
68+ assert (await caget (pre + ":GAIN" )) == 1
9669
9770 # Stop
98- asyncio_ioc_override .send_signal (signal .SIGINT )
71+ asyncio_ioc_override .proc . send_signal (signal .SIGINT )
9972 # check closed and output
100- out , err = asyncio_ioc_override .communicate ()
73+ out , err = asyncio_ioc_override .proc . communicate ()
10174 out = out .decode ()
10275 err = err .decode ()
10376 # check closed and output
0 commit comments