コード例 #1
0
def test_insert_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:
    #
    # IterationGroupCommand
    #     SequencerWhileCommand
    #         ObjectIteratorCommand
    #         IteratorConfigCommand
    #         LoadTemplateCommand
    #         IteratorValidateCommand
    # LoadTemplateCommand

    pkg = "spirent.methodology"
    mm_pkg = pkg + ".manager"
    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)
    assert net_prof_cmd2 is not None
    sequencer.SetCollection("CommandList", [group_cmd.GetObjectHandle(), net_prof_cmd2.GetObjectHandle()])

    # Insert the MethodologyGroupCommand
    MethodologyGroupCommandUtils.insert_top_level_group_command()

    # Validate the new sequence
    new_cmd_hnd_list = sequencer.GetCollection("CommandList")
    assert len(new_cmd_hnd_list) == 1
    tlgc_hnd = new_cmd_hnd_list[0]
    assert tlgc_hnd is not 0
    tlgc = hnd_reg.Find(tlgc_hnd)
    assert tlgc is not None
    assert tlgc.IsTypeOf(mm_pkg + ".MethodologyGroupCommand")

    # The sequence should not have changed.
    new_group_cmd_list = tlgc.GetCollection("CommandList")
    assert new_group_cmd_list == [group_cmd.GetObjectHandle(), net_prof_cmd2.GetObjectHandle()]
    assert 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()