Fix a test_unicode_idval_python2 (now test_unicode_idval) and associated string handling on Python 3
This commit is contained in:
parent
1f46015de5
commit
9b438d56e8
|
@ -1138,9 +1138,9 @@ def _idval(val, argname, idx, idfn):
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if isinstance(val, bytes) or (_PY2 and isinstance(val, unicode)):
|
if isinstance(val, (bytes, str)) or (_PY2 and isinstance(val, unicode)):
|
||||||
return _escape_strings(val)
|
return _escape_strings(val)
|
||||||
elif isinstance(val, (float, int, str, bool, NoneType)):
|
elif isinstance(val, (float, int, bool, NoneType)):
|
||||||
return str(val)
|
return str(val)
|
||||||
elif isinstance(val, REGEX_TYPE):
|
elif isinstance(val, REGEX_TYPE):
|
||||||
return _escape_strings(val.pattern)
|
return _escape_strings(val.pattern)
|
||||||
|
|
|
@ -121,20 +121,19 @@ class TestMetafunc:
|
||||||
assert metafunc._calls[2].id == "x1-a"
|
assert metafunc._calls[2].id == "x1-a"
|
||||||
assert metafunc._calls[3].id == "x1-b"
|
assert metafunc._calls[3].id == "x1-b"
|
||||||
|
|
||||||
@pytest.mark.skipif('sys.version_info[0] >= 3')
|
def test_unicode_idval(self):
|
||||||
def test_unicode_idval_python2(self):
|
"""This tests that Unicode strings outside the ASCII character set get
|
||||||
"""unittest for the expected behavior to obtain ids for parametrized
|
escaped, using byte escapes if they're in that range or unicode
|
||||||
unicode values in Python 2: if convertible to ascii, they should appear
|
escapes if they're not.
|
||||||
as ascii values, otherwise fallback to hide the value behind the name
|
|
||||||
of the parametrized variable name. #1086
|
|
||||||
"""
|
"""
|
||||||
from _pytest.python import _idval
|
from _pytest.python import _idval
|
||||||
values = [
|
values = [
|
||||||
(u'', ''),
|
(u'', ''),
|
||||||
(u'ascii', 'ascii'),
|
(u'ascii', 'ascii'),
|
||||||
(u'ação', 'a6'),
|
(u'ação', 'a\\xe7\\xe3o'),
|
||||||
(u'josé@blah.com', 'a6'),
|
(u'josé@blah.com', 'jos\\xe9@blah.com'),
|
||||||
(u'δοκ.ιμή@παράδειγμα.δοκιμή', 'a6'),
|
(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:
|
for val, expected in values:
|
||||||
assert _idval(val, 'a', 6, None) == expected
|
assert _idval(val, 'a', 6, None) == expected
|
||||||
|
|
Loading…
Reference in New Issue