def test_one_iterator(stc, resource_cleanup):
    RI.create_test()
    RI.start_test()
    framesizelist = [64, 128, 256]
    fs_itr_id = 1
    fs_iterator_handle = 12123
    for fs in framesizelist:
        RI.set_iterator_current_value(fs_iterator_handle, 'FrameSize', fs, fs_itr_id)
        RI.add_provider_result(test_utils.dummy_verify_result_failed)
        fs_itr_id += 1
        RI.complete_iteration()
    RI.end_iterator()
    RI.end_test()
    RI.stop_test()
    file_data = vu.get_report_file_list()
    vu.validate_result_file_list(file_data['fileList'], test_utils.result_file_list_1)
    vu.validate_result_file_Schema(file_data)
    sum_data = vu.verify_summary_file_info()
    assert ru.compare_dict_data_using_json_string(test_utils.status_exec_complete_5,
                                                  sum_data[pc.STATUS]) is True
    # get iterator result
    fz_data = ru.get_data_from_dictionary(sum_data, 'data.children.0.data.children.0')
    assert fz_data[pc.CLASS] == EnumDataClass.iterator_result
    assert fz_data[pc.DATA_FORMAT] == EnumDataFormat.group
    assert fz_data[pc.INFO]['param'] == 'FrameSize'
    assert ru.compare_dict_data_using_json_string(test_utils.status_iterator_6,
                                                  fz_data[pc.STATUS]) is True
    # iteration results
    itr_list = fz_data[pc.DATA][rc.CHILDREN]
    assert len(itr_list) == len(framesizelist)
    vu.verify_summary_iteration_result_type1(itr_list,
                                             framesizelist,
                                             test_utils.result_file_list_1)
def test_end_iterator_without_iteration(stc, resource_cleanup):
    RI.create_test()
    RI.start_test()
    RI.complete_iteration()
    RI.end_iterator()
    RI.end_test()
    RI.stop_test()
    data = vu.validate_report_schema()
    assert ru.compare_dict_data_using_json_string(test_utils.status_exec_complete_1,
                                                  data[pc.STATUS]) is True
    assert ru.compare_dict_data_using_json_string(test_utils.data_empty_1,
                                                  data[pc.DATA]) is True
def test_multiple_iterator_abort_outer_loop_stop(stc, resource_cleanup):
    """
    test must complete 2 iterations and generate report with summary.
    1. framesize = 64, load = 10
    2. framesize = 64, load = 20
    """
    RI.create_test()
    RI.start_test()
    framesizelist = [64, 128, 256]
    loadlist = [10, 20]
    fs_itr_id = 1
    fs_iterator_handle = 12123
    load_handle = 5555
    for fs in framesizelist:
        RI.set_iterator_current_value(fs_iterator_handle, 'FrameSize', fs, fs_itr_id)
        load_id = 1
        for load in loadlist:
            RI.set_iterator_current_value(load_handle, 'Load', load, load_id)
            RI.add_provider_result(test_utils.dummy_verify_result_failed)
            RI.add_provider_result(test_utils.dummy_verify_result_passed)
            load_id += 1
            RI.complete_iteration()
        break
    # RI.end_test()
    RI.stop_test()
    file_data = vu.get_report_file_list()
    vu.validate_result_file_list(file_data['fileList'], test_utils.result_file_list_4)
    vu.validate_result_file_Schema(file_data)
    sum_data = vu.verify_summary_file_info()
    assert ru.compare_dict_data_using_json_string(test_utils.status_exec_stopped_8,
                                                  sum_data[pc.STATUS]) is True
def verify_summary_file_info():
    report_data = ru.get_report_data_as_dictionary()
    assert report_data[pc.DATA_FORMAT] == EnumDataFormat.group
    assert report_data[pc.CLASS] == EnumDataClass.test_report
    data = report_data[pc.INFO]
    assert ('startTime' in data) is True
    assert ('endTime' in data) is True
    assert ('version' in data) is True
    return report_data
def verify_summary_iteration_result_type2(result_list, fs_list, load_list, file_list):
    fz_index = 0
    file_index = 1
    for result in result_list:
        assert result[pc.DATA_FORMAT] == EnumDataFormat.group
        assert result[pc.CLASS] == EnumDataClass.iteration_result
        info_data = result[pc.INFO]
        assert ('startTime' in info_data) is True
        assert ('endTime' in info_data) is True
        assert ('version' in info_data) is False
        assert ('resultFile' in info_data) is False
        assert info_data['param'] == 'FrameSize'
        assert info_data['value'] == fs_list[fz_index]
        fz_index += 1
        assert info_data['id'] == fz_index
        assert ru.compare_dict_data_using_json_string(test_utils.status_exec_complete_5,
                                                      result[pc.STATUS]) is True
        # load iterator
        assert len(result[pc.DATA][rc.CHILDREN]) == 1
        load_data = ru.get_data_from_dictionary(result, 'data.children.0')
        assert load_data[pc.CLASS] == EnumDataClass.iterator_result
        assert load_data[pc.DATA_FORMAT] == EnumDataFormat.group
        assert load_data[pc.INFO]['param'] == 'Load'
        assert ru.compare_dict_data_using_json_string(test_utils.status_exec_complete_5,
                                                      load_data[pc.STATUS]) is True
        itr_list = load_data[pc.DATA][rc.CHILDREN]
        assert len(itr_list) == len(load_list)
        load_index = 0
        for itr_load in itr_list:
            assert itr_load[pc.DATA_FORMAT] == EnumDataFormat.none
            assert itr_load[pc.CLASS] == EnumDataClass.iteration_result
            load_info = itr_load[pc.INFO]
            assert ('startTime' in load_info) is True
            assert ('endTime' in load_info) is True
            assert ('version' in load_info) is False
            assert load_info['param'] == 'Load'
            assert load_info['value'] == load_list[load_index]
            load_index += 1
            assert load_info['id'] == load_index
            assert load_info['resultFile'] == file_list[file_index]
            assert ru.compare_dict_data_using_json_string(test_utils.status_failed_7,
                                                          itr_load[pc.STATUS]) is True
            file_index += 1
def validate_report_schema(filename=None):
    if filename is None:
        report_data = ru.get_report_data_as_dictionary()
    else:
        with open(filename) as file:
            report_data = json.load(file)
    assert report_data is not {}
    with open(report_schema_file) as rschema:
        schema = json.load(rschema)
    jsonschema.validate(report_data, schema)
    return report_data
def test_multiple_iterator_add_root_result(stc, resource_cleanup):
    RI.create_test()
    RI.start_test()
    framesizelist = [64]
    loadlist = [10]
    fs_itr_id = 1
    fs_iterator_handle = 12123
    load_handle = 5555
    for fs in framesizelist:
        RI.set_iterator_current_value(fs_iterator_handle, 'FrameSize', fs, fs_itr_id)
        load_id = 1
        for load in loadlist:
            RI.set_iterator_current_value(load_handle, 'Load', load, load_id)
            RI.add_provider_result(test_utils.dummy_verify_result_failed)
            RI.add_provider_result(test_utils.dummy_verify_result_passed)
            # add to root
            RI.add_provider_result_to_root(test_utils.dummy_verify_result_passed)
            load_id += 1
            RI.complete_iteration()
        RI.end_iterator()
        # frame size
        fs_itr_id += 1
        RI.complete_iteration()
    RI.end_iterator()
    RI.end_test()
    RI.stop_test()
    file_data = vu.get_report_file_list()
    vu.validate_result_file_list(file_data['fileList'], test_utils.result_file_list_3)
    vu.validate_result_file_Schema(file_data)
    sum_data = vu.verify_summary_file_info()
    assert ru.compare_dict_data_using_json_string(test_utils.status_pass_2,
                                                  sum_data[pc.STATUS]) is True
    # 2 root results, iterator and added root result
    root_list = sum_data[pc.DATA][rc.CHILDREN]
    assert len(root_list) == 2
    result_data = ru.get_data_from_dictionary(root_list, '0.data.children.0')
    fz_data = ru.get_data_from_dictionary(root_list, '1.data.children.0')
    assert fz_data[pc.INFO]['param'] == 'FrameSize'
    # verify result data
    expected_string = ru.get_json_string(test_utils.dummy_verify_result_passed)
    assert ru.compare_dict_data_using_json_string(expected_string, result_data) is True
def verify_summary_iteration_result_type1(result_list, fs_list, file_list):
    index = 0
    for result in result_list:
        assert result[pc.DATA_FORMAT] == EnumDataFormat.none
        assert result[pc.CLASS] == EnumDataClass.iteration_result
        info_data = result[pc.INFO]
        assert ('startTime' in info_data) is True
        assert ('endTime' in info_data) is True
        assert ('version' in info_data) is False
        assert info_data['param'] == 'FrameSize'
        assert info_data['value'] == fs_list[index]
        index += 1
        assert info_data['id'] == index
        assert info_data['resultFile'] == file_list[index]
        assert ru.compare_dict_data_using_json_string(test_utils.status_failed_7,
                                                      result[pc.STATUS]) is True
def test_one_iterator_stop(stc, resource_cleanup):
    RI.create_test()
    RI.start_test()
    framesizelist = [64, 128, 256]
    fs_itr_id = 1
    fs_iterator_handle = 12123
    for fs in framesizelist:
        RI.set_iterator_current_value(fs_iterator_handle, 'FrameSize', fs, fs_itr_id)
        RI.add_provider_result(test_utils.dummy_verify_result_failed)
        fs_itr_id += 1
        RI.complete_iteration()
    RI.end_iterator()
    RI.stop_test()
    file_data = vu.get_report_file_list()
    vu.validate_result_file_list(file_data['fileList'], test_utils.result_file_list_1)
    vu.validate_result_file_Schema(file_data)
    # verify exec status stopped
    sum_data = vu.verify_summary_file_info()
    assert ru.compare_dict_data_using_json_string(test_utils.status_exec_stopped_8,
                                                  sum_data[pc.STATUS]) is True