Beispiel #1
0
def assert_not_equal_by_dpath(response,
                              dpath,
                              second,
                              msg=None,
                              values=True,
                              formatter=None):
    """Fail if given objects are equal as determined by the '==' operator."""
    first = get_value_by_path(response, dpath)
    _debug_response(response, dpath, first, second)
    if first == second:
        _report_inequality(first, second, '==', msg, values, formatter)
Beispiel #2
0
def assert_none_by_dpath(response, dpath, msg=None, values=True):
    """Fail the test if given object is not None."""
    obj = get_value_by_path(response, dpath)
    _debug_response(response, dpath, obj)
    _msg = '%r is not None' % obj
    if obj is not None:
        if msg is None:
            msg = _msg
        elif values is True:
            msg = '%s: %s' % (msg, _msg)
        _report_failure(msg)
def save_variable_from_reponse(response, dpath, save_var_name, save_var_type='suite'):
    """
    1. get value from response
    2. set value into variable: set suite variable default
    """
    logger.info(response, dpath, save_var_name)
    _real_value = get_value_by_path(response, dpath)
    bi = BuiltIn()
    if save_var_name == 'test':
        bi.set_test_variable(save_var_name, _real_value)
    elif save_var_type == 'global':
        bi.set_global_variable(save_var_name, _real_value)
    else:

        bi.set_suite_variable(save_var_name, _real_value)
Beispiel #4
0
def assert_not_almost_equal_by_dpath(response,
                                     dpath,
                                     second,
                                     places=7,
                                     msg=None,
                                     values=True):
    """Fail if the two objects are unequal after rounded to given places.

    Equality is determined by object's difference rounded to to the
    given number of decimal places (default 7) and comparing to zero.
    Note that decimal places (from zero) are usually not the same as
    significant digits (measured from the most significant digit).
    """
    first = get_value_by_path(response, dpath)
    _debug_response(response, dpath, first, second)
    if round(second - first, places) == 0:
        extra = 'within %r places' % places
        _report_inequality(first, second, '==', msg, values, extra=extra)
Beispiel #5
0
def save_function_result_into_variables(config_functions_infos, kw_name,
                                        kw_args):
    ''' 
        1. get function result by dpath and save it into robot variable
        2. saved variable type only support global, suite, test, common variable
        3. run keyword with robot variable
    '''
    from robot_yaml.datas.yaml_fields import NAME, DPATH, KEYWORD, KW_ARGS, KW_TYPE, SAVE_VAR_NAME
    from robot_yaml.parsing.dpath_json import get_value_by_path
    from robot_yaml.utils.commons import run_keyword
    # bi.log(config_functions_infos)

    for func in config_functions_infos:
        name = func.get(KEYWORD)
        args = func.get(KW_ARGS)
        save_var_type = func.get(KW_TYPE)
        save_var_names = func.get(SAVE_VAR_NAME)

        results = run_keyword(name, args)
        # if not results:
        #     continue
        logger.info("the receive: {}".format(save_var_names))
        logger.info("the return value: {}".format(results))
        if len(results) < len(save_var_names):
            raise Exception(
                "return number must be bigger or equal with receive number")

        for index, item in enumerate(save_var_names):
            _name = item[NAME]
            _path = item.get(DPATH)
            if not _path:
                # if not dpath, then save function result into variable directory
                args = [_name, results]
            else:
                args = [_name, get_value_by_path(results, _path)]

            if not save_var_type:
                run_keyword('set_test_variable', args)
            else:
                run_keyword(save_var_type, args)
    if kw_name:
        run_keyword(kw_name, kw_args)
Beispiel #6
0
def assert_true_by_dpath(response, dpath, msg=None):
    """Fail the test unless the expression is True."""
    expr = get_value_by_path(response, dpath)
    _debug_response(response, dpath, expr)
    if not expr:
        _report_failure(msg)
def extract_variable_from_reponse(response, dpath):
    """
    """
    return get_value_by_path(response, dpath)