コード例 #1
0
def test_remove_top_level_group_command(stc):
    plLogger = PLLogger.GetLogger("methodology")
    plLogger.LogInfo("start")
    ctor = CScriptableCreator()
    stc_sys = CStcSystem.Instance()
    assert stc_sys is not None
    sequencer = stc_sys.GetObject("Sequencer")
    hnd_reg = CHandleRegistry.Instance()

    # Sequencer Command List will look as follows:
    #
    # MethodologyGroupCommand
    #     IterationGroupCommand
    #         SequencerWhileCommand
    #             ObjectIteratorCommand
    #             IteratorConfigCommand
    #             LoadTemplateCommand
    #             IteratorValidateCommand
    #     LoadTemplateCommand

    pkg = "spirent.methodology"
    mm_pkg = pkg + ".manager"

    tlgc = ctor.Create(mm_pkg + ".MethodologyGroupCommand", sequencer)
    assert tlgc is not None
    group_cmd = ctor.Create(pkg + ".IterationGroupCommand", sequencer)
    assert group_cmd is not None

    # IteratorCommand
    while_cmd = ctor.Create("SequencerWhileCommand", group_cmd)
    assert while_cmd is not None
    iter_cmd = ctor.Create(pkg + ".ObjectIteratorCommand", while_cmd)
    assert iter_cmd is not None
    config_cmd = ctor.Create(pkg + ".IteratorConfigCommand", while_cmd)
    assert config_cmd is not None
    net_prof_cmd = ctor.Create(pkg + ".LoadTemplateCommand", while_cmd)
    assert net_prof_cmd is not None
    valid_cmd = ctor.Create(pkg + ".IteratorValidateCommand", while_cmd)
    assert valid_cmd is not None
    while_cmd.Set("ExpressionCommand", iter_cmd.GetObjectHandle())
    while_cmd.SetCollection(
        "CommandList", [config_cmd.GetObjectHandle(), net_prof_cmd.GetObjectHandle(), valid_cmd.GetObjectHandle()]
    )
    group_cmd.SetCollection("CommandList", [while_cmd.GetObjectHandle()])

    net_prof_cmd2 = ctor.Create(pkg + ".LoadTemplateCommand", sequencer)
    tlgc.SetCollection("CommandList", [group_cmd.GetObjectHandle(), net_prof_cmd2.GetObjectHandle()])
    sequencer.SetCollection("CommandList", [tlgc.GetObjectHandle()])

    # Remove the MethodologyGroupCommand
    MethodologyGroupCommandUtils.remove_top_level_group_command()

    # Validate the new sequence
    new_cmd_hnd_list = sequencer.GetCollection("CommandList")
    assert len(new_cmd_hnd_list) == 2

    c_group_cmd_hnd = new_cmd_hnd_list[0]
    c_net_prof_cmd_hnd2 = new_cmd_hnd_list[1]
    assert c_group_cmd_hnd is not 0
    assert c_net_prof_cmd_hnd2 is not 0

    c_group_cmd = hnd_reg.Find(c_group_cmd_hnd)
    c_net_prof_cmd2 = hnd_reg.Find(c_net_prof_cmd_hnd2)
    assert c_group_cmd is not None
    assert c_net_prof_cmd2 is not None

    assert c_group_cmd.GetObjectHandle() == group_cmd.GetObjectHandle()
    assert c_net_prof_cmd2.GetObjectHandle() == net_prof_cmd2.GetObjectHandle()

    # The sequence should not have changed
    assert c_group_cmd.GetCollection("CommandList") == [while_cmd.GetObjectHandle()]
    assert while_cmd.GetCollection("CommandList") == [
        config_cmd.GetObjectHandle(),
        net_prof_cmd.GetObjectHandle(),
        valid_cmd.GetObjectHandle(),
    ]
    assert while_cmd.Get("ExpressionCommand") == iter_cmd.GetObjectHandle()