From 9b438d56e8cba5712cd5cc61786f9e527bb45880 Mon Sep 17 00:00:00 2001 From: Ceridwen Date: Fri, 1 Apr 2016 12:27:17 -0400 Subject: [PATCH] Fix a test_unicode_idval_python2 (now test_unicode_idval) and associated string handling on Python 3 --- _pytest/python.py | 4 ++-- testing/python/metafunc.py | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/_pytest/python.py b/_pytest/python.py index 3d71a0afe..53e11a348 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1138,9 +1138,9 @@ def _idval(val, argname, idx, idfn): except Exception: 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) - elif isinstance(val, (float, int, str, bool, NoneType)): + elif isinstance(val, (float, int, bool, NoneType)): return str(val) elif isinstance(val, REGEX_TYPE): return _escape_strings(val.pattern) diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index f0f3dbd4c..da4228ed8 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -121,20 +121,19 @@ class TestMetafunc: assert metafunc._calls[2].id == "x1-a" assert metafunc._calls[3].id == "x1-b" - @pytest.mark.skipif('sys.version_info[0] >= 3') - 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 + 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', 'a6'), - (u'josé@blah.com', 'a6'), - (u'δοκ.ιμή@παράδειγμα.δοκιμή', 'a6'), + (u'ação', 'a\\xe7\\xe3o'), + (u'josé@blah.com', 'jos\\xe9@blah.com'), + (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