def test_TmcFile_recursive_explore(generic_tmc_path): tmc = TmcFile(generic_tmc_path) tmc.isolate_all() root_path = [tmc.all_SubItems['iterator']['extra1']] response = tmc.recursive_explore(root_path) assert response == [ [ tmc.all_SubItems['iterator']['extra1'], tmc.all_SubItems['DUT_STRUCT']['struct_var'] ], [ tmc.all_SubItems['iterator']['extra1'], tmc.all_SubItems['DUT_STRUCT']['struct_var2'] ], ] root_path = [tmc.all_Symbols['MAIN.struct_extra']] response = tmc.recursive_explore(root_path) print(response) assert response == [ [ tmc.all_Symbols['MAIN.struct_extra'], tmc.all_SubItems['DUT_STRUCT']['struct_var'] ], [ tmc.all_Symbols['MAIN.struct_extra'], tmc.all_SubItems['DUT_STRUCT']['struct_var2'] ], [ tmc.all_Symbols['MAIN.struct_extra'], tmc.all_SubItems['DUT_EXTENSION_STRUCT']['tertiary'] ], ]
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
def test_TmcFile_isolate_all(generic_tmc_path): tmc = TmcFile(generic_tmc_path) tmc.isolate_all() assert "MAIN.ulimit" in tmc.all_Symbols assert "MAIN.count" in tmc.all_Symbols assert "MAIN.NEW_VAR" in tmc.all_Symbols assert "MAIN.test_iterator" in tmc.all_Symbols assert "Constants.RuntimeVersion" in tmc.all_Symbols assert len(tmc.all_Symbols) == 25 assert "iterator" in tmc.all_DataTypes assert "VERSION" in tmc.all_DataTypes assert len(tmc.all_DataTypes) == 11 assert 'increment' in tmc.all_SubItems['iterator'] assert 'out' in tmc.all_SubItems['iterator'] assert 'value' in tmc.all_SubItems['iterator'] assert 'lim' in tmc.all_SubItems['iterator'] assert 'extra1' in tmc.all_SubItems['iterator'] assert 'extra2' in tmc.all_SubItems['iterator'] assert len(tmc.all_SubItems['iterator']) == 6 assert tmc.all_Symbols['MAIN.dtype_samples_enum'].is_enum assert tmc.all_SubItems['DUT_CONTAINER']['dtype_enum'].is_enum
def test_TmcFile_isolate_DataTypes(generic_tmc_path): tmc = TmcFile(generic_tmc_path) tmc.isolate_DataTypes() assert "iterator" in tmc.all_DataTypes assert "VERSION" in tmc.all_DataTypes assert len(tmc.all_DataTypes) == 11
def test_TmcFile_fullbuild(string_tmc_path): tmc = TmcFile(string_tmc_path) tmc.create_chains() tmc.isolate_chains() tmc.create_packages() tmc.configure_packages() z = tmc.render() print(z)
def test_TmcFile_resolve_enums(generic_tmc_path): tmc = TmcFile(generic_tmc_path) tmc.isolate_Symbols() tmc.isolate_DataTypes() assert not tmc.all_Symbols['MAIN.dtype_samples_enum'].is_enum assert not tmc.all_SubItems['DUT_CONTAINER']['dtype_enum'].is_enum tmc.resolve_enums() assert tmc.all_Symbols['MAIN.dtype_samples_enum'].is_enum assert tmc.all_SubItems['DUT_CONTAINER']['dtype_enum'].is_enum
def test_TmcFile_recursive_list_SubItems(generic_tmc_path): tmc = TmcFile(generic_tmc_path) tmc.isolate_all() response = tmc.recursive_list_SubItems( tmc.all_DataTypes['DUT_EXTENSION_STRUCT']) assert response == [ tmc.all_SubItems['DUT_STRUCT']['struct_var'], tmc.all_SubItems['DUT_STRUCT']['struct_var2'], tmc.all_SubItems['DUT_EXTENSION_STRUCT']['tertiary'], ]
def test_TmcFile_isolate_Symbols(generic_tmc_path): tmc = TmcFile(generic_tmc_path) tmc.isolate_Symbols() assert "MAIN.ulimit" in tmc.all_Symbols assert "MAIN.count" in tmc.all_Symbols assert "MAIN.NEW_VAR" in tmc.all_Symbols assert "MAIN.test_iterator" in tmc.all_Symbols assert "Constants.RuntimeVersion" in tmc.all_Symbols assert len(tmc.all_Symbols) == 25
def test_TmcFile_isolate_SubItems(generic_tmc_path): tmc = TmcFile(generic_tmc_path) tmc.isolate_DataTypes(process_subitems=False) tmc.isolate_SubItems('iterator') assert 'increment' in tmc.all_SubItems['iterator'] assert 'out' in tmc.all_SubItems['iterator'] assert 'value' in tmc.all_SubItems['iterator'] assert 'lim' in tmc.all_SubItems['iterator'] assert 'extra1' in tmc.all_SubItems['iterator'] assert 'extra2' in tmc.all_SubItems['iterator'] assert len(tmc.all_SubItems['iterator']) == 6
def test_TmcFile_explore_all(generic_tmc_path): tmc = TmcFile(generic_tmc_path) tmc.isolate_all() complete_chain_list = tmc.explore_all() #assert len(complete_chain_list) == 27 assert [tmc.all_Symbols['MAIN.ulimit']] in complete_chain_list target = [ tmc.all_Symbols['MAIN.test_iterator'], tmc.all_SubItems['iterator']['extra1'], tmc.all_SubItems['DUT_STRUCT']['struct_var'] ] assert target in complete_chain_list
def test_TmcFile_create_chains(generic_tmc_path): tmc = TmcFile(generic_tmc_path) tmc.create_chains() target = [tmc.all_Symbols['MAIN.ulimit']] accept = False for row in tmc.all_TmcChains: if row.chain == target: accept = True break assert accept target = [ tmc.all_Symbols['MAIN.test_iterator'], tmc.all_SubItems['iterator']['extra1'], tmc.all_SubItems['DUT_STRUCT']['struct_var'] ] accept = False for row in tmc.all_TmcChains: if row.chain == target: accept = True break assert accept
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()
def test_TmcFile_isolate_chains(generic_tmc_path): tmc = TmcFile(generic_tmc_path) tmc.create_chains() tmc.isolate_chains() print(len(tmc.all_TmcChains)) print(len(tmc.all_singular_TmcChains)) target = [ tmc.all_Symbols['MAIN.test_iterator'], tmc.all_SubItems['iterator']['extra1'], tmc.all_SubItems['DUT_STRUCT']['struct_var'] ] accept = False count = 0 for row in tmc.all_singular_TmcChains: if row.chain[0].name == 'MAIN.container_struct': if row.chain[1].name == 'dtype_samples_iter_array': if row.chain[2].name == 'extra1': if row.chain[3].name == 'struct_var': count += 1 assert count == 4
def test_TmcFile_instantiation(generic_tmc_path, generic_tmc_root): try: tmc = TmcFile(generic_tmc_path) except Exception: pytest.fail("Instantiation of TmcFile should not generate errors")
def test_TmcFile_ads_port(tmc_filename): tmc = TmcFile(tmc_filename) assert tmc.ads_port == 851
def generic_file(): return TmcFile(TMC_ROOT / "generic.tmc")