コード例 #1
0
def test_run_pass_in_json(stc):
    plLogger = PLLogger.GetLogger('methodology')
    plLogger.LogInfo("begin test_run")

    stc_sys = CStcSystem.Instance()
    sequencer = stc_sys.GetObject("Sequencer")
    ctor = CScriptableCreator()
    common_data_path = stc_sys.GetApplicationCommonDataPath()

    # Create exposed properties for the ports
    project = stc_sys.GetObject('Project')
    left_tag = tag_utils.get_tag_object('Left_Port_Group')
    ep_cfg = ctor.Create('ExposedConfig', project)
    ep = ctor.Create('ExposedProperty', ep_cfg)
    ep.Set('EPNameId', 'LeftPortGroup')
    ep.Set('EPClassId', 'tag')
    ep.Set('EPPropertyId', 'scriptable.name')
    ep.AddObject(left_tag, RelationType('ScriptableExposedProperty'))

    meth_name = "RFC2544THROUGHPUT_SAMPLE_BASIC"
    test_name = "test_run"

    # Clean up the fake installed methodology (if it exists)
    if os.path.exists(os.path.join(common_data_path,
                                   mgr_const.MM_TEST_METH_DIR,
                                   meth_name)):
        meth_man_utils.methodology_rmdir(meth_name)

    # Create a fake installed methodology
    home_dir = meth_man_utils.get_methodology_home_dir()
    assert home_dir is not None
    meth_dir = meth_man_utils.methodology_mkdir(meth_name)
    assert meth_dir is not None
    test_dir = meth_man_utils.methodology_test_case_mkdir(meth_name, test_name)
    assert test_dir is not None

    # Add a fake sequence file
    seq_file = os.path.join(meth_dir, mgr_const.MM_SEQUENCER_FILE_NAME)
    f = open(seq_file, "w")
    f.write("<?xml version=\"1.0\" encoding=\"windows-1252\"?>")
    f.close()

    # Add a fake TXML file
    meta_file = os.path.join(meth_dir, mgr_const.MM_META_FILE_NAME)
    f = open(meta_file, "w")
    data = UnitTestUtils.gen_test_info_header("unit test meth disp name",
                                              meth_name,
                                              "unit test meth test case",
                                              "")
    data = data + UnitTestUtils.UTU_FOOTER
    f.write(data)
    f.close()

    # Initialize the methodology manager by calling update
    cmd = ctor.CreateCommand(PKG +
                             ".UpdateTestMethodologyManagerCommand")
    cmd.Execute()
    cmd.MarkDelete()

    # meth_man = meth_man_utils.get_meth_manager()
    # assert meth_man
    # test_meth_obj_list = meth_man.GetObjects("StmMethodology")
    # assert len(test_meth_obj_list) > 0

    # test_meth = None
    # for test_meth_obj in test_meth_obj_list:
    #     act_meth_key = test_meth_obj.Get("MethodologyKey")
    #     plLogger.LogDebug("meth_name: " + test_meth_obj.Get("Name"))
    #     plLogger.LogDebug("meth_key: " + test_meth_obj.Get("MethodologyKey"))
    #     if act_meth_key == meth_name:
    #         test_meth = test_meth_obj
    #         break

    # Add MethodologyGroupCommand to the sequencer
    meth_group_cmd = ctor.Create(PKG + ".MethodologyGroupCommand", sequencer)
    sequencer.SetCollection("CommandList", [meth_group_cmd.GetObjectHandle()])
    key_value_json = meth_group_cmd.Get("KeyValueJson")
    assert key_value_json == ""

    cmd = ctor.Create(PKG + ".RunMethodologyTestCommand", sequencer)
    RunCmd.get_this_cmd = MagicMock(return_value=cmd)
    RunCmd.load_config = MagicMock()
    # TODO: set it up so we don't have to mock this function
    RunCmd.set_active_test_case = MagicMock()

    # Call run with all empty
    # res = RunCmd.run("", "", "", "", False)
    # assert not res
    # assert 'MethodologyJson does not conform to the schema' in cmd.Get("Status")
    # assert cmd.Get("OutputTestCaseKey") == ''
    # cmd.Set("Status", '')

    # Call run with invalid meth key
    # res = RunCmd.run("", "", "blah", "", False)
    # assert not res
    # assert 'MethodologyJson does not conform to the schema' in cmd.Get("Status")
    # assert cmd.Get("OutputTestCaseKey") == ''
    # cmd.Set("Status", '')

    # Call run with empty json
    # res = RunCmd.run("", "", meth_name, "", False)
    # assert not res
    # assert 'MethodologyJson does not conform to the schema' in cmd.Get("Status")
    # assert cmd.Get("OutputTestCaseKey") == ''
    # cmd.Set("Status", '')

    # Call run with invalid json
    # res = RunCmd.run("", "", meth_name, "invalid json", False)
    # assert not res
    # assert 'MethodologyJson does not conform to the schema' in cmd.Get("Status")
    # assert cmd.Get("OutputTestCaseKey") == ''
    # cmd.Set("Status", '')

    # Call the run function with valid meth key and json
    res = RunCmd.run("", "", meth_name, get_sample_2544_json_basic(), False)
    assert res
    assert cmd.Get("Status") == ''
    assert cmd.Get("OutputTestCaseKey") == meth_name + '-1'

    # The KeyValueJson should be populated after running the command
    key_value_json = meth_group_cmd.Get("KeyValueJson")
    assert key_value_json != ""
    err_str, key_value_dict = json_utils.load_json(key_value_json)
    assert err_str == ""
    assert key_value_dict is not None

    assert len(key_value_dict.items()) == 1
    assert key_value_dict["AddressStartValue"] == "1.1.1.1"

    # Clean up the fake installed methodology
    if os.path.exists(os.path.join(common_data_path,
                                   mgr_const.MM_TEST_METH_DIR,
                                   meth_name)):
        meth_man_utils.methodology_rmdir(meth_name)
コード例 #2
0
def test_find_file_across_common_paths_no_active_meth(stc):
    ctor = CScriptableCreator()
    stc_sys = CStcSystem.Instance()
    project = stc_sys.GetObject("Project")
    plLogger = PLLogger.GetLogger('methodology')
    plLogger.LogInfo("test_find_file_across_common_paths_no_active_meth")

    meth_key = "UT_FIND_FILES_TEST_ACTIVE"

    # Clean up empty folders (if existing)
    meth_man_utils.methodology_rmdir(meth_key)

    # Can't use unit_test_utils here to create fake methodologies
    # due to the custom requirements of this particular methodology.
    install_dir = meth_man_utils.get_methodology_home_dir()
    test_meth_dir = os.path.join(install_dir, meth_key)
    assert not os.path.exists(test_meth_dir)
    os.makedirs(test_meth_dir)

    # Add a fake sequence file
    seq_file = os.path.join(test_meth_dir, mgr_const.MM_SEQUENCER_FILE_NAME)
    f = open(seq_file, "w")
    f.write("<?xml version=\"1.0\" encoding=\"windows-1252\"?>")
    f.close()

    # Add a fake TXML file
    meta_file = os.path.join(test_meth_dir, mgr_const.MM_META_FILE_NAME)
    f = open(meta_file, "w")
    data = UnitTestUtils.gen_test_info_header("unit test meth disp name",
                                              meth_key,
                                              "unit test meth test case",
                                              "")
    data = data + UnitTestUtils.UTU_FOOTER
    f.write(data)
    f.close()

    # Add a fake data file
    data_file_name = "fake_data_file.txt"
    data_file_path = os.path.join(test_meth_dir, data_file_name)
    f = open(data_file_path, "w")
    f.write("Unit Test Data File (end)")
    f.close()

    # Initialize the methodology manager by calling update
    cmd = ctor.CreateCommand(PKG_MGR +
                             ".UpdateTestMethodologyManagerCommand")
    cmd.Execute()
    cmd.MarkDelete()

    meth_manager = meth_man_utils.get_meth_manager()

    test_meth_obj_list = meth_manager.GetObjects("StmMethodology")
    assert len(test_meth_obj_list) > 0

    test_meth = None
    for test_meth_obj in test_meth_obj_list:
        act_meth_key = test_meth_obj.Get("MethodologyKey")
        plLogger.LogInfo("meth_name: " + test_meth_obj.Get("Name"))
        plLogger.LogInfo("meth_key: " + test_meth_obj.Get("MethodologyKey"))
        if act_meth_key == meth_key:
            test_meth = test_meth_obj
            break

    assert test_meth is not None

    meth_key = test_meth.Get("MethodologyKey")
    plLogger.LogInfo("meth_name: " + test_meth_obj.Get("Name"))
    plLogger.LogInfo("meth_key: " + test_meth_obj.Get("MethodologyKey"))

    # Check the path
    install_dir = os.path.join(stc_sys.GetApplicationCommonDataPath(),
                               mgr_const.MM_TEST_METH_DIR)
    exp_path = os.path.join(install_dir, meth_key)
    assert test_meth.Get("Path") == os.path.normpath(exp_path)

    # Test the find_file_across_common_paths function
    # (no active, not loaded from file)
    active_tc = meth_manager.GetObject("StmTestCase",
                                       RelationType("ActiveStmTestCase"))
    assert active_tc is None

    ret_val = meth_man_utils.find_file_across_common_paths(data_file_name)
    assert ret_val == ""

    # Test the find_file_across_common_paths function
    # (no active, loaded from file)
    project.Set("ConfigurationFileName", seq_file)
    ret_val = meth_man_utils.find_file_across_common_paths(data_file_name)
    assert ret_val == os.path.normpath(data_file_path)

    # Clean up
    cmd = ctor.CreateCommand(PKG_MGR + ".DeleteMethodologyCommand")
    cmd.Set("StmMethodology", test_meth.GetObjectHandle())
    cmd.Execute()