Reviewed: https://review.openstack.org/233652 Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=cfc87662cc87e51e96251383a9776343f99a5b3a Submitter: Jenkins Branch: master
commit cfc87662cc87e51e96251383a9776343f99a5b3a Author: Cyril Roelandt <email address hidden> Date: Mon Oct 12 16:07:54 2015 +0200
Python 3: skip test_json_with_utf8 on Py3
The last skipped unit test should indeed be skipped: it does not make sense to run it with Python 3.
$ python 2 >>> import json; json.dumps({'a': u'\xe9'.encode('utf-8')}) '{"a": "\\u00e9"}'
$ python3 >>> import json; json.dumps({'a': u'\xe9'.encode('utf-8')}) Traceback (most recent call last): ... File "/usr/lib64/python3.4/json/encoder.py", line 173, in default raise TypeError(repr(o) + " is not JSON serializable") TypeError: b'\xc3\xa9' is not JSON serializable
In Python 2, the JSON encoder function to encode a string begins with a magic test to convert UTF-8 encoded string to Unicode:
if isinstance(s, str) and HAS_UTF8.search(s) is not None: s = s.decode('utf-8')
https://hg.python.org/cpython/file/4188cd5dc0c5/Lib/json/encoder.py#l42
This trick is gone in Python 3:
https://hg.python.org/cpython/file/288953a787ce/Lib/json/encoder.py#l49
Change-Id: Iddaaea4ebedf04c87f1ff9f9098163a15ffa78f7 Blueprint: neutron-python3 Closes-Bug: #1491824
Reviewed: https:/ /review. openstack. org/233652 /git.openstack. org/cgit/ openstack/ neutron/ commit/ ?id=cfc87662cc8 7e51e96251383a9 776343f99a5b3a
Committed: https:/
Submitter: Jenkins
Branch: master
commit cfc87662cc87e51 e96251383a97763 43f99a5b3a
Author: Cyril Roelandt <email address hidden>
Date: Mon Oct 12 16:07:54 2015 +0200
Python 3: skip test_json_with_utf8 on Py3
The last skipped unit test should indeed be skipped: it does not make
sense to run it with Python 3.
$ python 2 .encode( 'utf-8' )})
>>> import json; json.dumps({'a': u'\xe9'
'{"a": "\\u00e9"}'
$ python3 .encode( 'utf-8' )}) python3. 4/json/ encoder. py", line 173, in default
>>> import json; json.dumps({'a': u'\xe9'
Traceback (most recent call last):
...
File "/usr/lib64/
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'\xc3\xa9' is not JSON serializable
In Python 2, the JSON encoder function to encode a string begins with
a magic test to convert UTF-8 encoded string to Unicode:
if isinstance(s, str) and HAS_UTF8.search(s) is not None:
s = s.decode('utf-8')
https:/ /hg.python. org/cpython/ file/4188cd5dc0 c5/Lib/ json/encoder. py#l42
This trick is gone in Python 3:
https:/ /hg.python. org/cpython/ file/288953a787 ce/Lib/ json/encoder. py#l49
Change-Id: Iddaaea4ebedf04 c87f1ff9f909816 3a15ffa78f7
Blueprint: neutron-python3
Closes-Bug: #1491824