From: Cyril Roelandt Date: Mon, 12 Oct 2015 14:07:54 +0000 (+0200) Subject: Python 3: skip test_json_with_utf8 on Py3 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=cfc87662cc87e51e96251383a9776343f99a5b3a;p=openstack-build%2Fneutron-build.git 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 --- diff --git a/neutron/tests/unit/test_wsgi.py b/neutron/tests/unit/test_wsgi.py index c6d4ee961..190299967 100644 --- a/neutron/tests/unit/test_wsgi.py +++ b/neutron/tests/unit/test_wsgi.py @@ -494,8 +494,9 @@ class JSONDictSerializerTest(base.BaseTestCase): 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"]}}'