]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commit
Python 3: skip test_json_with_utf8 on Py3
authorCyril Roelandt <cyril@redhat.com>
Mon, 12 Oct 2015 14:07:54 +0000 (16:07 +0200)
committerCedric Brandily <zzelle@gmail.com>
Thu, 15 Oct 2015 08:44:53 +0000 (08:44 +0000)
commitcfc87662cc87e51e96251383a9776343f99a5b3a
treedf1e2220ce8b898972e15289e40ab7f97d27484c
parent9da4dfae56f22414e389bff560a9ee10991e1d7d
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
neutron/tests/unit/test_wsgi.py