示例#1
0
def _idval(val, argname, idx, idfn, config=None):
    if idfn:
        s = None
        try:
            s = idfn(val)
        except Exception:
            # See issue https://github.com/pytest-dev/pytest/issues/2169
            import warnings
            msg = "Raised while trying to determine id of parameter %s at position %d." % (
                argname, idx)
            msg += '\nUpdate your code as this will raise an error in pytest-4.0.'
            warnings.warn(msg, DeprecationWarning)
        if s:
            return _ascii_escaped(s)

    if config:
        hook_id = config.hook.pytest_make_parametrize_id(config=config,
                                                         val=val,
                                                         argname=argname)
        if hook_id:
            return hook_id

    if isinstance(val, STRING_TYPES):
        return _ascii_escaped(val)
    elif isinstance(val, (float, int, bool, NoneType)):
        return str(val)
    elif isinstance(val, REGEX_TYPE):
        return _ascii_escaped(val.pattern)
    elif enum is not None and isinstance(val, enum.Enum):
        return str(val)
    elif isclass(val) and hasattr(val, '__name__'):
        return val.__name__
    return str(argname) + str(idx)
示例#2
0
文件: python.py 项目: rmariano/pytest
def _idval(val, argname, idx, idfn, config=None):
    if idfn:
        s = None
        try:
            s = idfn(val)
        except Exception:
            # See issue https://github.com/pytest-dev/pytest/issues/2169
            import warnings
            msg = "Raised while trying to determine id of parameter %s at position %d." % (argname, idx)
            msg += '\nUpdate your code as this will raise an error in pytest-4.0.'
            warnings.warn(msg, DeprecationWarning)
        if s:
            return _ascii_escaped(s)

    if config:
        hook_id = config.hook.pytest_make_parametrize_id(
            config=config, val=val, argname=argname)
        if hook_id:
            return hook_id

    if isinstance(val, STRING_TYPES):
        return _ascii_escaped(val)
    elif isinstance(val, (float, int, bool, NoneType)):
        return str(val)
    elif isinstance(val, REGEX_TYPE):
        return _ascii_escaped(val.pattern)
    elif enum is not None and isinstance(val, enum.Enum):
        return str(val)
    elif isclass(val) and hasattr(val, '__name__'):
        return val.__name__
    return str(argname) + str(idx)
示例#3
0
文件: python.py 项目: rmariano/pytest
def _idvalset(idx, parameterset, argnames, idfn, ids, config=None):
    if parameterset.id is not None:
        return parameterset.id
    if ids is None or (idx >= len(ids) or ids[idx] is None):
        this_id = [_idval(val, argname, idx, idfn, config)
                   for val, argname in zip(parameterset.values, argnames)]
        return "-".join(this_id)
    else:
        return _ascii_escaped(ids[idx])
示例#4
0
def _idvalset(idx, parameterset, argnames, idfn, ids, config=None):
    if parameterset.id is not None:
        return parameterset.id
    if ids is None or (idx >= len(ids) or ids[idx] is None):
        this_id = [
            _idval(val, argname, idx, idfn, config)
            for val, argname in zip(parameterset.values, argnames)
        ]
        return "-".join(this_id)
    else:
        return _ascii_escaped(ids[idx])