def test_type_converions_2(ctx): print("CA type conversions arrays") pvlist = (pvnames.char_arr_pv, pvnames.long_arr_pv, pvnames.double_arr_pv) chids = [] for name in pvlist: chid = ctx.create_channel(name) yield from ctx.connect_channel(chid) chids.append((chid, name)) # yield from asyncio.sleep(0.1) values = {} for chid, name in chids: values[name] = yield from coroutines.get(chid) for promotion in ('ctrl', 'time'): for chid, pvname in chids: print('=== %s chid=%s as %s' % (ca.name(chid), repr(chid), promotion)) yield from asyncio.sleep(0.01) if promotion == 'ctrl': ntype = dbr.promote_type(ca.field_type(chid), use_ctrl=True) else: ntype = dbr.promote_type(ca.field_type(chid), use_time=True) val = yield from coroutines.get(chid, ftype=ntype) yield from coroutines.get(chid, as_string=True) for a, b in zip(val, values[pvname]): assert a == b
def test_type_conversions_1(ctx): print("CA type conversions scalars") pvlist = (pvnames.str_pv, pvnames.int_pv, pvnames.float_pv, pvnames.enum_pv, pvnames.long_pv, pvnames.double_pv2) chids = [] for name in pvlist: chid = ctx.create_channel(name) yield from ctx.connect_channel(chid) chids.append((chid, name)) # yield from asyncio.sleep(0.1) values = {} for chid, name in chids: values[name] = yield from coroutines.get(chid, as_string=True) for promotion in ('ctrl', 'time'): for chid, pvname in chids: print('=== %s chid=%s as %s' % (ca.name(chid), repr(chid), promotion)) yield from asyncio.sleep(0.01) if promotion == 'ctrl': ntype = dbr.promote_type(ca.field_type(chid), use_ctrl=True) else: ntype = dbr.promote_type(ca.field_type(chid), use_time=True) val = yield from coroutines.get(chid, ftype=ntype) cval = yield from coroutines.get(chid, as_string=True) if ca.element_count(chid) > 1: val = val[:12] assert cval == values[pvname]
def test_xArray1(ctx): chid = ctx.create_channel(pvnames.double_arrays[0]) val0 = yield from coroutines.get(chid) # aval = yield from coroutines.get(chid, wait=False) # assert aval is None # NOTE: not a useful test anymore val1 = yield from coroutines.get(chid) assert all(val0 == val1)
def test_xArray3(ctx): print('Array Test: get char array as string') chid = ctx.create_channel(pvnames.char_arrays[0]) val = yield from coroutines.get(chid) assert isinstance(val, numpy.ndarray) char_val = yield from coroutines.get(chid, as_string=True) assert isinstance(char_val, str) conv = ''.join([chr(i) for i in val]) assert conv == char_val
def test_putwait(ctx): 'test put with wait' pvn = pvnames.non_updating_pv chid = ctx.create_channel(pvn) yield from ctx.connect_channel(chid) yield from coroutines.put(chid, -1) val = yield from coroutines.get(chid) assert val == -1 yield from coroutines.put(chid, 2) val = yield from coroutines.get(chid) assert val == 2
def test_xArray2(ctx): print('Array Test: get fewer than max vals using ca.get(count=0)') chid = ctx.create_channel(pvnames.double_arrays[0]) maxpts = ca.element_count(chid) npts = int(max(2, maxpts / 2.3 - 1)) print('max points is %s' % (maxpts, )) dat = numpy.random.normal(size=npts) print('setting array to a length of npts=%s' % (npts, )) yield from coroutines.put(chid, dat) out1 = yield from coroutines.get(chid) assert isinstance(out1, numpy.ndarray) assert len(out1) == npts out2 = yield from coroutines.get(chid, count=0) assert isinstance(out2, numpy.ndarray) assert len(out2) == npts
def test_Array0(ctx): print( 'Array Test: get double array as numpy array, ctypes Array, and list') chid = ctx.create_channel(pvnames.double_arrays[0]) yield from ctx.connect_channel(chid) aval = yield from coroutines.get(chid) cval = yield from coroutines.get(chid, as_numpy=False) assert isinstance(aval, numpy.ndarray) assert len(aval) > 2 assert isinstance(cval, ctypes.Array) assert len(cval) > 2 lval = list(cval) assert isinstance(lval, list) assert len(lval) > 2 assert lval == list(aval)
def testA_CreateChidWithConn(ctx): print('Simple Test: create chid with conn callback') chid = ctx.create_channel(pvnames.int_pv, callback=onConnect) print('created') yield from ctx.connect_channel(chid) print('connected') yield from coroutines.get(chid) print('got') conn = _connection_dict.get(pvnames.int_pv, None) print('conn dat is', _connection_dict) assert conn
def test_Values(ctx): print('CA test Values (compare 5 values with caget)') os.system('rm ./caget.tst') vals = {} for pvn in (pvnames.str_pv, pvnames.int_pv, pvnames.float_pv, pvnames.enum_pv, pvnames.long_pv): os.system('caget -n -f5 %s >> ./caget.tst' % pvn) chid = ctx.create_channel(pvn) yield from ctx.connect_channel(chid) vals[pvn] = yield from coroutines.get(chid) rlines = open('./caget.tst', 'r').readlines() for line in rlines: pvn, sval = [i.strip() for i in line[:-1].split(' ', 1)] tval = str(vals[pvn]) if pvn in (pvnames.float_pv, pvnames.double_pv): # use float precision! tval = "%.5f" % vals[pvn] assert tval == sval
def testA_GetNonExistentPV(ctx): print('Simple Test: get on a non-existent PV') chid = ctx.create_channel('Definitely-Not-A-Real-PV') with pytest.raises(ChannelAccessException): yield from coroutines.get(chid)