summaryrefslogtreecommitdiffstats
path: root/Lib/json/tests/test_unicode.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-05-02 12:36:44 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-05-02 12:36:44 (GMT)
commitc6b607d4a9e4d60fb506034ce67fc89734bb68a7 (patch)
treeb4f27e81ab25a9dfe6a97433f4d25c263b59f6cc /Lib/json/tests/test_unicode.py
parent7255f18556ae70fc28b563a345577d3ec8f6f0ba (diff)
downloadcpython-c6b607d4a9e4d60fb506034ce67fc89734bb68a7.zip
cpython-c6b607d4a9e4d60fb506034ce67fc89734bb68a7.tar.gz
cpython-c6b607d4a9e4d60fb506034ce67fc89734bb68a7.tar.bz2
port simplejson upgrade from the trunk #4136
json also now works only with unicode strings Patch by Antoine Pitrou; updated by me
Diffstat (limited to 'Lib/json/tests/test_unicode.py')
-rw-r--r--Lib/json/tests/test_unicode.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/Lib/json/tests/test_unicode.py b/Lib/json/tests/test_unicode.py
index 00bf58e..12de83c 100644
--- a/Lib/json/tests/test_unicode.py
+++ b/Lib/json/tests/test_unicode.py
@@ -4,20 +4,8 @@ import json
from collections import OrderedDict
class TestUnicode(TestCase):
- def test_encoding1(self):
- encoder = json.JSONEncoder(encoding='utf-8')
- u = '\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
- s = u.encode('utf-8')
- ju = encoder.encode(u)
- js = encoder.encode(s)
- self.assertEquals(ju, js)
-
- def test_encoding2(self):
- u = '\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
- s = u.encode('utf-8')
- ju = json.dumps(u, encoding='utf-8')
- js = json.dumps(s, encoding='utf-8')
- self.assertEquals(ju, js)
+ # test_encoding1 and test_encoding2 from 2.x are irrelevant (only str
+ # is supported as input, not bytes).
def test_encoding3(self):
u = '\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
@@ -52,8 +40,22 @@ class TestUnicode(TestCase):
def test_unicode_decode(self):
for i in range(0, 0xd7ff):
u = chr(i)
- js = '"\\u{0:04x}"'.format(i)
- self.assertEquals(json.loads(js), u)
+ s = '"\\u{0:04x}"'.format(i)
+ self.assertEquals(json.loads(s), u)
+
+ def test_unicode_preservation(self):
+ self.assertEquals(type(json.loads('""')), str)
+ self.assertEquals(type(json.loads('"a"')), str)
+ self.assertEquals(type(json.loads('["a"]')[0]), str)
+
+ def test_bytes_encode(self):
+ self.assertRaises(TypeError, json.dumps, b"hi")
+ self.assertRaises(TypeError, json.dumps, [b"hi"])
+
+ def test_bytes_decode(self):
+ self.assertRaises(TypeError, json.loads, b'"hi"')
+ self.assertRaises(TypeError, json.loads, b'["hi"]')
+
def test_object_pairs_hook_with_unicode(self):
s = '{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'