Beispiel #1
0
def test_motion_stcmd(capsys, project_filename):
    """
    Sanity check of motor setup in the st.cmd files

    For all plc projects:
        1. Is a controller created only when needed?
        2. Are the right number of axes created?

    Note: capsys is a built-in pytest fixture for capturing stdout and stderr
    """
    controller_func = 'EthercatMCCreateController'
    motor_func = 'EthercatMCCreateAxis'

    full_project = parser.parse(project_filename)

    for plc_name, plc_project in full_project.plcs_by_name.items():
        motors = list(plc_project.find(parser.Symbol_DUT_MotionStage))
        # Clear captured buffer just in case
        capsys.readouterr()
        stcmd_main(project_filename, plc_name=plc_name,
                   only_motor=True, allow_errors=True)
        output = capsys.readouterr().out

        if motors:
            assert controller_func in output
        else:
            assert controller_func not in output

        assert output.count(motor_func) == len(motors)
Beispiel #2
0
def test_allow_no_pragma():
    """
    Test for the existence of a variable included in the records, despite it
    lacking a proper set of pragmas.
    """
    tmc_file_name = TMC_ROOT / ("xtes_sxr_plc.tmc")

    tmc = parser.parse(tmc_file_name)

    records, exceptions = db_process(
        tmc, dbd_file=None, allow_errors=True,
        show_error_context=True, allow_no_pragma=False
    )

    all_records, exceptions = db_process(
        tmc, dbd_file=None, allow_errors=True,
        show_error_context=True, allow_no_pragma=True
    )
    good_records = 129
    total_records = 1002

    assert good_records == len(records)
    assert good_records == len(list(x.valid for x in records if x.valid))
    assert total_records == len(all_records)
    assert good_records == len(list(x.valid for x in all_records if x.valid))

    # this variable lacks a pragma
    target_variable = "GVL_DEVICES.MR2K3_GCC_1.rV"
    for x in all_records:
        print(x.tcname)
    assert any((target_variable == x.tcname) for x in all_records)
    assert exceptions == []
Beispiel #3
0
def test_route_parsing():
    # located in: C:\twincat\3.1\StaticRoutes.xml
    routes = parse(TEST_PATH / 'static_routes.xml')
    remote_connections = routes.RemoteConnections[0]
    assert remote_connections.by_name == {
        'LAMP-VACUUM': {
            'Name': 'LAMP-VACUUM',
            'Address': '172.21.37.140',
            'NetId': '5.21.50.18.1.1',
            'Type': 'TCP_IP'
        },
        'AMO-BASE': {
            'Name': 'AMO-BASE',
            'Address': '172.21.37.114',
            'NetId': '5.17.65.196.1.1',
            'Type': 'TCP_IP'
        },
    }

    assert remote_connections.by_address == {
        '172.21.37.114': {
            'Address': '172.21.37.114',
            'Name': 'AMO-BASE',
            'NetId': '5.17.65.196.1.1',
            'Type': 'TCP_IP'
        },
        '172.21.37.140': {
            'Address': '172.21.37.140',
            'Name': 'LAMP-VACUUM',
            'NetId': '5.21.50.18.1.1',
            'Type': 'TCP_IP'
        }
    }

    assert remote_connections.by_ams_id == {
        '5.17.65.196.1.1': {
            'Address': '172.21.37.114',
            'Name': 'AMO-BASE',
            'NetId': '5.17.65.196.1.1',
            'Type': 'TCP_IP'
        },
        '5.21.50.18.1.1': {
            'Address': '172.21.37.140',
            'Name': 'LAMP-VACUUM',
            'NetId': '5.21.50.18.1.1',
            'Type': 'TCP_IP'
        },
    }
Beispiel #4
0
def test_global_pinned_variables(tmc_file_name, target_pv):
    """
    Ensure that one of the pinned global variables can be found in the list of
    records created when parsing this tmc file. This tmc file was specifically
    created to contain the 'plcAttribute_pytmc' style <Name> fields in place of
    the normal 'pytmc'.
    """
    tmc = parser.parse(tmc_file_name)

    records, exceptions = db_process(
        tmc, dbd_file=None, allow_errors=False,
        show_error_context=True
    )

    assert any((target_pv in x.pvname) for x in records)
    assert exceptions == []
Beispiel #5
0
def project(project_filename):
    return parser.parse(project_filename)
Beispiel #6
0
def _generate_project_and_plcs():
    for project_filename in TSPROJ_PROJECTS:
        project = parser.parse(project_filename)
        for plc_name in project.plcs_by_name:
            yield project_filename, plc_name
def chain():
    tmc = parser.parse(conftest.TMC_ROOT / 'xtes_sxr_plc.tmc')
    symbols = list(pragmas.find_pytmc_symbols(tmc))
    return list(pragmas.chains_from_symbol(symbols[1]))[0]