def mini_idvalset(argnames, argvalues, idx):
    """ mimic _pytest.python._idvalset """
    this_id = [
        _idval(val, argname, idx=idx, **_idval_kwargs)
        for val, argname in zip(argvalues, argnames)
    ]
    return "-".join(this_id)
Exemple #2
0
 def test_idval_hypothesis(self, value):
     from _pytest.python import _idval
     escaped = _idval(value, 'a', 6, None)
     assert isinstance(escaped, str)
     if PY3:
         escaped.encode('ascii')
     else:
         escaped.decode('ascii')
def mini_idval(
        val,  # type: object
        argname,  # type: str
        idx,  # type: int
):
    """
    A simplified version of idval where idfn, item and config do not need to be passed.

    :param val:
    :param argname:
    :param idx:
    :return:
    """
    return _idval(val=val, argname=argname, idx=idx, **_idval_kwargs)
Exemple #4
0
def mini_idvalset(argnames, argvalues, idx):
    """ mimic _pytest.python._idvalset but can handle lazyvalues used for tuples or args

    argvalues should not be a pytest.param (ParameterSet)
    This function returns a SINGLE id for a single test node
    """
    if len(argnames) > 1 and is_lazy(argvalues):
        # handle the case of LazyTuple used for several args
        return argvalues.get_id()

    this_id = [
        _idval(val, argname, idx=idx, **_idval_kwargs)
        for val, argname in zip(argvalues, argnames)
    ]
    return "-".join(this_id)
Exemple #5
0
 def test_bytes_idval(self):
     """unittest for the expected behavior to obtain ids for parametrized
     bytes values:
     - python2: non-ascii strings are considered bytes and formatted using
     "binary escape", where any byte < 127 is escaped into its hex form.
     - python3: bytes objects are always escaped using "binary escape".
     """
     from _pytest.python import _idval
     values = [
         (b'', ''),
         (b'\xc3\xb4\xff\xe4', '\\xc3\\xb4\\xff\\xe4'),
         (b'ascii', 'ascii'),
         (u'αρά'.encode('utf-8'), '\\xce\\xb1\\xcf\\x81\\xce\\xac'),
     ]
     for val, expected in values:
         assert _idval(val, 'a', 6, None) == expected
Exemple #6
0
    def test_unicode_idval(self):
        """This tests that Unicode strings outside the ASCII character set get
        escaped, using byte escapes if they're in that range or unicode
        escapes if they're not.

        """
        from _pytest.python import _idval
        values = [
            (u'', ''),
            (u'ascii', 'ascii'),
            (u'ação', 'a\\xe7\\xe3o'),
            (u'josé@blah.com', 'jos\\[email protected]'),
            (u'δοκ.ιμή@παράδειγμα.δοκιμή', '\\u03b4\\u03bf\\u03ba.\\u03b9\\u03bc\\u03ae@\\u03c0\\u03b1\\u03c1\\u03ac\\u03b4\\u03b5\\u03b9\\u03b3\\u03bc\\u03b1.\\u03b4\\u03bf\\u03ba\\u03b9\\u03bc\\u03ae'),
        ]
        for val, expected in values:
            assert _idval(val, 'a', 6, None) == expected
Exemple #7
0
 def test_unicode_idval_python2(self):
     """unittest for the expected behavior to obtain ids for parametrized
     unicode values in Python 2: if convertible to ascii, they should appear
     as ascii values, otherwise fallback to hide the value behind the name
     of the parametrized variable name. #1086
     """
     from _pytest.python import _idval
     values = [
         (u'', ''),
         (u'ascii', 'ascii'),
         (u'ação', 'a6'),
         (u'josé@blah.com', 'a6'),
         (u'δοκ.ιμή@παράδειγμα.δοκιμή', 'a6'),
     ]
     for val, expected in values:
         assert _idval(val, 'a', 6, None) == expected
Exemple #8
0
 def test_unicode_idval_python2(self):
     """unittest for the expected behavior to obtain ids for parametrized
     unicode values in Python 2: if convertible to ascii, they should appear
     as ascii values, otherwise fallback to hide the value behind the name
     of the parametrized variable name. #1086
     """
     from _pytest.python import _idval
     values = [
         (u'', ''),
         (u'ascii', 'ascii'),
         (u'ação', 'a6'),
         (u'josé@blah.com', 'a6'),
         (u'δοκ.ιμή@παράδειγμα.δοκιμή', 'a6'),
     ]
     for val, expected in values:
         assert _idval(val, 'a', 6, None) == expected