Beispiel #1
0
def test_BaseRecordPackage_guess_io(example_singular_tmc_chains, tc_type,
                                    sing_index, final_io):
    # chain must be broken into singular
    record = BaseRecordPackage(851, example_singular_tmc_chains[sing_index])
    logger.debug(str(record.chain.last.pragma.config))
    # tc_type is assignable because it isn't implemented in BaseElement
    # this field must be added because it is typically derived from the .tmc
    record.chain.last.tc_type = tc_type
    record.generate_naive_config()
    assert record.guess_io() is True
    print(record.cfg.config)
    [field] = record.cfg.get_config_lines('io')
    assert field['tag'] == final_io
Beispiel #2
0
def test_BaseRecordPackage_cfg_as_dict():
    brp = BaseRecordPackage(851)
    brp.cfg.add_config_line('pv', 'example_pv')
    brp.cfg.add_config_line('type', 'ao')
    brp.cfg.add_config_field('ABC', 'test 0')
    assert brp.cfg_as_dict() == {
        'pv': 'example_pv',
        'type': 'ao',
        'info': False,
        'field': {
            'ABC': 'test 0'
        }
    }
Beispiel #3
0
def test_BaseRecordPackage_apply_config_valid(sample_TmcChain):
    test_chain = sample_TmcChain.build_singular_chains()[0]
    brp = BaseRecordPackage(851, test_chain)
    brp.generate_naive_config()
    for x in brp.cfg.config:
        print(x)

    brp.validation_list = [
        {
            'path': [],
            'target': 3
        },
    ]
    assert brp.apply_config_validation() == [
        {
            'path': [],
            'target': 3
        },
    ]

    brp.validation_list = [
        {
            'path': ['tag', 'f_name'],
            'target': 'SCAN'
        },
        {
            'path': ['title'],
            'target': 'pv'
        },
    ]
    assert len(brp.apply_config_validation()) == 0
Beispiel #4
0
def test_BaseRecordPackage_guess_DTYP(example_singular_tmc_chains, tc_type, io,
                                      is_array, final_DTYP):
    # chain must be broken into singular
    record = BaseRecordPackage(851, example_singular_tmc_chains[0])
    logger.debug((record.chain.last.pragma.config))
    # tc_type is assignable because it isn't implemented in BaseElement
    # this field must be added because it is typically derived from the .tmc
    record.chain.last.tc_type = tc_type
    record.chain.last.is_array = is_array
    record.generate_naive_config()
    record.cfg.add_config_line('io', io, overwrite=True)
    assert record.guess_DTYP() is True
    logger.debug((record.cfg.config))
    [field] = record.cfg.get_config_fields('DTYP')
    assert field['tag']['f_set'] == final_DTYP
Beispiel #5
0
def test_BaseRecordPackage_generate_naive_config(sample_TmcChain):
    test_chain = sample_TmcChain.build_singular_chains()[0]
    brp = BaseRecordPackage(851, test_chain)
    brp.generate_naive_config()
    assert brp.cfg.config[0:3] == [
        {
            'title': 'pv',
            'tag': 'MIDDLE:FIRST:TEST:MAIN:NEW_VAR_OUT'
        },
        {
            'title': 'aux',
            'tag': 'nothing'
        },
        {
            'title': 'type',
            'tag': 'bo'
        },
    ]
Beispiel #6
0
def test_BaseRecordPackage_render_record():
    brp = BaseRecordPackage(851)
    brp.cfg.add_config_line('pv', 'example_pv')
    brp.cfg.add_config_line('type', 'ao')
    brp.cfg.add_config_field('DTYP', '"MyDTYP"')
    brp.cfg.add_config_field("PINI", '"1"')
    brp.cfg.add_config_field("NELM", 3)
    brp.cfg.add_config_field('ABC', '"test 0"')
    target_response = """\
    record(ao,"example_pv"){
      field(DTYP, "MyDTYP")
      field(PINI, "1")
      field(NELM, 3)
      field(ABC, "test 0")
    }\
    """
    target_response = textwrap.dedent(target_response).strip()
    assert target_response == brp.render_record()
Beispiel #7
0
def test_BaseRecordPackage_guess_FTVL(example_singular_tmc_chains, tc_type, io,
                                      is_str, is_arr, final_FTVL):
    record = BaseRecordPackage(851, example_singular_tmc_chains[0])
    record.chain.last.tc_type = tc_type
    record.chain.last.is_array = is_arr
    record.chain.last.is_str = is_str
    record.generate_naive_config()
    record.cfg.add_config_line('io', io, overwrite=True)
    result = record.guess_FTVL()
    print(record.cfg.config)
    if final_FTVL is None:
        assert result is False
        with pytest.raises(ValueError):
            [out] = record.cfg.get_config_fields("FTVL")
    else:
        assert result is True
        [out] = record.cfg.get_config_fields("FTVL")
        assert out['tag']['f_set'] == final_FTVL
Beispiel #8
0
def test_BaseRecordPackage_guess_NELM(example_singular_tmc_chains, tc_type,
                                      sing_index, is_str, is_arr, final_NELM):
    record = BaseRecordPackage(851, example_singular_tmc_chains[sing_index])
    record.chain.last.tc_type = tc_type
    record.chain.last.is_array = is_arr
    record.chain.last.is_str = is_str
    record.chain.last.iterable_length = final_NELM
    record.generate_naive_config()
    result = record.guess_NELM()
    print(record.cfg.config)
    if final_NELM is None:
        assert result is False
        with pytest.raises(ValueError):
            [out] = record.cfg.get_config_fields("NELM")
    else:
        assert result is True
        [out] = record.cfg.get_config_fields("NELM")
        assert out['tag']['f_set'] == final_NELM
Beispiel #9
0
def test_BaseRecordPackage_guess_OZ_NAM(example_singular_tmc_chains, tc_type,
                                        sing_index, final_ZNAM, final_ONAM,
                                        ret):
    record = BaseRecordPackage(851, example_singular_tmc_chains[sing_index])
    record.chain.last.tc_type = tc_type
    assert ret == record.guess_ONAM()
    assert ret == record.guess_ZNAM()
    o = record.cfg.get_config_fields('ONAM')
    z = record.cfg.get_config_fields('ZNAM')
    logger.debug(str(record.cfg.config))
    if final_ONAM is not None:
        assert o[0]['tag']['f_set'] == final_ONAM
    else:
        assert len(o) == 0
    if final_ZNAM is not None:
        assert z[0]['tag']['f_set'] == final_ZNAM
    else:
        assert len(z) == 0
Beispiel #10
0
def test_BaseRecordPackage_guess_type(example_singular_tmc_chains, tc_type, io,
                                      is_array, final_type):
    # chain must be broken into singular
    # for x in example_singular_tmc_chains:
    #     z = BaseRecordPackage(x)
    #     print(z.cfg.config)
    #     z.generate_naive_config()
    #     print(z.cfg.config)
    # assert False
    record = BaseRecordPackage(851, example_singular_tmc_chains[0])
    logger.debug(str(record.chain.last.pragma.config))
    # tc_type is assignable because it isn't implemented in BaseElement
    # this field must be added because it is typically derived from the .tmc
    record.chain.last.tc_type = tc_type
    record.chain.last.is_array = is_array
    record.generate_naive_config()
    record.cfg.add_config_line('io', io, overwrite=True)

    assert record.guess_type() is True
    [field] = record.cfg.get_config_lines('type')
    assert field['tag'] == final_type
Beispiel #11
0
def test_TmcFile_configure_packages(example_singular_tmc_chains):
    tmc = TmcFile(None)
    check_list = []
    # build artificial tmcChains and generate fake names
    for idx, tc_type in zip([0, 2, 4, 6], ["BOOL", "INT", "LREAL", "STRING"]):
        cn = example_singular_tmc_chains[idx]
        for element, ix in zip(cn.chain, range(len(cn.chain))):
            element.name = chr(97 + ix)

        cn.last.tc_type = tc_type

        tmc.all_TmcChains.append(cn)

        # create the check_set
        rec = BaseRecordPackage(None, cn)
        rec.generate_naive_config()
        rec.guess_all()
        logger.debug(str(rec.chain.last.pragma.config))
        check_list.append(rec)

    tmc.create_chains()
    tmc.isolate_chains()
    tmc.create_packages()
    tmc.configure_packages()

    assert len(tmc.all_RecordPackages) == 4
    for check, rec in zip(check_list, tmc.all_RecordPackages):
        assert check.cfg.config == rec.cfg.config
        assert check.chain.chain == rec.chain.chain
Beispiel #12
0
def test_BaseRecordPackage_guess_PREC(example_singular_tmc_chains, tc_type,
                                      sing_index, final_PREC, ret):
    record = BaseRecordPackage(851, example_singular_tmc_chains[sing_index])
    record.chain.last.tc_type = tc_type
    record.generate_naive_config()
    print(record.cfg.config)
    record.guess_type()
    if final_PREC is None:
        assert record.guess_PREC() is False
        with pytest.raises(ValueError):
            [out] = record.cfg.get_config_fields("PREC")
    else:
        assert record.guess_PREC() is True
        [out] = record.cfg.get_config_fields("PREC")
        assert out['tag']['f_set'] == '"3"'
Beispiel #13
0
def test_TmcFile_render(generic_tmc_path):
    tmc = TmcFile(None)
    brp1 = BaseRecordPackage(851)
    brp1.cfg.add_config_line('pv', 'example_pv')
    brp1.cfg.add_config_line('type', 'ao')
    brp1.cfg.add_config_field("DTYP", '"MyDTYP"')
    brp1.cfg.add_config_field("PINI", '"VX"')
    brp1.cfg.add_config_field("NELM", 3)
    brp1.cfg.add_config_field('ABC', '"test 0"')
    brp2 = BaseRecordPackage(851)
    brp2.cfg.add_config_line('pv', 'example_pv2')
    brp2.cfg.add_config_line('type', 'bi')
    brp2.cfg.add_config_field("DTYP", '"MyDTYP"')
    brp2.cfg.add_config_field("PINI", '"1"')
    brp2.cfg.add_config_field("NELM", 2)
    brp2.cfg.add_config_field('ABC', '"test k"')

    tmc.all_RecordPackages.append(brp1)
    tmc.all_RecordPackages.append(brp2)

    target_response = """\
    record(ao,"example_pv"){
      field(DTYP, "MyDTYP")
      field(PINI, "VX")
      field(NELM, 3)
      field(ABC, "test 0")
    }

    record(bi,"example_pv2"){
      field(DTYP, "MyDTYP")
      field(PINI, "1")
      field(NELM, 2)
      field(ABC, "test k")
    }

    """
    target_response = textwrap.dedent(target_response)
    assert target_response == tmc.render()
Beispiel #14
0
def test_BaseRecordPackage_ID_type():
    brp = BaseRecordPackage(851)
    brp.cfg.add_config_line('pv', 'example_pv')
    brp.cfg.add_config_line('type', 'ao')
    brp.cfg.add_config_field("PINI", "1")
    assert brp.ID_type() == 'standard'

    brp = BaseRecordPackage(851)
    brp.cfg.add_config_line('pv', 'example_pv')
    brp.cfg.add_config_line('type', 'motor')
    brp.cfg.add_config_field("PINI", "1")
    assert brp.ID_type() == 'motor'
Beispiel #15
0
def test_BaseRecordPackage_guess_all(example_singular_tmc_chains, tc_type,
                                     sing_index, is_str, is_arr, final_NELM,
                                     spot_check, result):
    record = BaseRecordPackage(851, example_singular_tmc_chains[sing_index])
    record.chain.last.tc_type = tc_type
    record.chain.last.is_array = is_arr
    record.chain.last.is_str = is_str
    record.chain.last.iterable_length = final_NELM
    for element, idx in zip(record.chain.chain,
                            range(len(record.chain.chain))):
        element.name = chr(97 + idx)
    record.generate_naive_config()
    record.guess_all()
    for ln in record.cfg.config:
        print(ln)
    [out] = record.cfg.get_config_fields(spot_check)
    assert out['tag']['f_set'] == result
Beispiel #16
0
def test_BaseRecordPackage_guess_INP_OUT(example_singular_tmc_chains, tc_type,
                                         sing_index, field_type,
                                         final_INP_OUT):
    # chain must be broken into singular
    record = BaseRecordPackage(851, example_singular_tmc_chains[sing_index])
    # tc_type is assignable because it isn't implemented in BaseElement
    # this field must be added because it is typically derived from the .tmc
    record.chain.last.tc_type = tc_type
    if tc_type == "STRING":
        record.chain.last.is_str = True
    for element, idx in zip(record.chain.chain, range(3)):
        element.name = chr(97 + idx)
    record.generate_naive_config()
    record.guess_io()
    assert record.guess_INP_OUT() is True
    print(record.cfg.config)

    [field] = record.cfg.get_config_fields(field_type)
    if field_type == "OUT":
        assert record.cfg.get_config_fields('INP') == []
    if field_type == "INP":
        assert record.cfg.get_config_fields('OUT') == []

    assert field['tag']['f_set'] == final_INP_OUT
Beispiel #17
0
def test_BaseRecordPackage_guess_PINI():
    brp = BaseRecordPackage(851)
    assert brp.guess_PINI() is True
    print(brp.cfg.config)
    [pini] = brp.cfg.get_config_fields('PINI')
    assert pini['tag']['f_set'] == '"1"'
Beispiel #18
0
def test_BaseRecordPackage_guess_TSE():
    brp = BaseRecordPackage(851)
    assert brp.guess_TSE() is True
    [tse] = brp.cfg.get_config_fields('TSE')
    assert tse['tag']['f_set'] == '-2'