Exemple #1
0
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
Exemple #2
0
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]
Exemple #3
0
def test_promote_type(ctx):
    pvn = pvnames.double_pv
    chid = ctx.create_channel(pvn)
    yield from ctx.connect_channel(chid)
    print('CA promote type (%s)' % (pvn))
    f_t = dbr.promote_type(ca.field_type(chid), use_time=True)
    f_c = dbr.promote_type(ca.field_type(chid), use_ctrl=True)
    assert f_t == dbr.ChannelType.TIME_DOUBLE
    assert f_c == dbr.ChannelType.CTRL_DOUBLE
Exemple #4
0
def test_promoted_type(ntype):
    mreg = MockRegistry()
    ncb = MonitorCallback(mreg, chid=0, ftype=ntype)

    ptype = dbr.promote_type(ntype, use_ctrl=True)
    pcb = MonitorCallback(mreg, chid=0, ftype=ptype)
    check_order(lesser=ncb, greater=pcb)

    ptype = dbr.promote_type(ntype, use_time=True)
    pcb = MonitorCallback(mreg, chid=0, ftype=ptype)
    check_order(lesser=ncb, greater=pcb)
Exemple #5
0
def test_array_callbacks(ctx, arrayname, array_type, length, element_type):
    """ Helper function to subscribe to a PV array and check it
    receives at least one subscription callback w/ specified type,
    length & uniform element type. Checks separately for normal,
    TIME & CTRL subscription variants. Returns the array or fails
    an assertion."""
    results = {}
    for form in ['normal', 'time', 'ctrl']:
        chid = ctx.create_channel(arrayname)
        yield from ctx.connect_channel(chid)
        ftype = dbr.promote_type(ca.field_type(chid),
                                 use_time=(form == 'time'),
                                 use_ctrl=(form == 'ctrl'))
        handler, cbid = ctx.subscribe(sig='monitor',
                                      chid=chid,
                                      ftype=ftype,
                                      func=onChanges)

        _change_dict.pop(arrayname, None)
        timeout = 0
        # wait up to 6 seconds, if no callback probably due to simulator.py
        # not running...
        while timeout < 120 and not arrayname in _change_dict:
            yield from asyncio.sleep(0.05)
            timeout = timeout + 1
        val = _change_dict.get(arrayname, None)
        ctx.unsubscribe(cbid)
        assert val is not None
        assert type(val) == array_type
        assert len(val) == length
        assert type(val[0]) == element_type
        assert all(type(e) == element_type for e in val)
        results[form] = val
    return results
Exemple #6
0
def test_mask(ntype, mask1, mask2):
    mreg = MockRegistry()

    ptype = dbr.promote_type(ntype, use_ctrl=True)

    native_m1 = MonitorCallback(mreg, chid=0, ftype=ntype, mask=mask1)
    promoted_m1 = MonitorCallback(mreg, chid=0, ftype=ptype, mask=mask1)

    native_m2 = MonitorCallback(mreg, chid=0, ftype=ntype, mask=mask2)
    promoted_m2 = MonitorCallback(mreg, chid=0, ftype=ptype, mask=mask2)

    if mask1 != mask2:
        check_order(lesser=native_m1, greater=native_m2)
        check_order(lesser=promoted_m1, greater=promoted_m2)
        check_order(lesser=native_m1, greater=promoted_m1)
        check_order(lesser=native_m1, greater=promoted_m2)
    else:
        assert native_m1 <= native_m2
        assert native_m2 >= native_m1
        assert native_m2 == native_m1

        assert promoted_m1 <= promoted_m2
        assert promoted_m2 >= promoted_m1
        assert promoted_m2 == promoted_m1

    assert list(sorted([native_m2, native_m1])) == [native_m1, native_m2]
    assert list(sorted([promoted_m2,
                        promoted_m1])) == [promoted_m1, promoted_m2]
Exemple #7
0
def test_promote_time(ntype):
    ptype = ChType(promote_type(ntype, use_time=True))
    assert ptype.name == 'TIME_' + ntype.name
Exemple #8
0
def test_promote_ctrl_time(ntype):
    ptype = ChType(promote_type(ntype, use_ctrl=True, use_time=True))
    if ntype == ChType.STRING:
        assert ptype.name == 'TIME_' + ntype.name
    else:
        assert ptype.name == 'CTRL_' + ntype.name