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
self.assertEqual(expected_json, result)
- # TODO(cbrandily): support this test in py3K
- @testtools.skipIf(six.PY3, "bug/1491824")
+ # The tested behaviour is only meant to be witnessed in Python 2, so it is
+ # OK to skip this test with Python 3.
+ @testtools.skipIf(six.PY3, "This test does not make sense in Python 3")
def test_json_with_utf8(self):
input_dict = dict(servers=dict(a=(2, '\xe7\xbd\x91\xe7\xbb\x9c')))
expected_json = b'{"servers":{"a":[2,"\\u7f51\\u7edc"]}}'