[Python-checkins] cpython (3.2): #16559: Add more tests for the json module. Patch by Serhiy Storchaka.

ezio.melotti python-checkins at python.org
Mon Nov 26 18:28:12 CET 2012


http://hg.python.org/cpython/rev/4f21a9b7decf
changeset: 80599:4f21a9b7decf
branch: 3.2
parent: 80595:cde59c6acf98
user: Ezio Melotti <ezio.melotti at gmail.com>
date: Mon Nov 26 19:24:20 2012 +0200
summary:
 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
files:
 Lib/test/json_tests/test_fail.py | 24 ++++++++++++++++--
 Lib/test/json_tests/test_float.py | 15 +++++++++++
 Lib/test/json_tests/test_pass1.py | 20 ++++++---------
 Misc/NEWS | 3 ++
 4 files changed, 47 insertions(+), 15 deletions(-)
diff --git a/Lib/test/json_tests/test_fail.py b/Lib/test/json_tests/test_fail.py
--- a/Lib/test/json_tests/test_fail.py
+++ b/Lib/test/json_tests/test_fail.py
@@ -1,13 +1,13 @@
 from test.json_tests import PyTest, CTest
 
-# Fri Dec 30 18:57:26 2005
+# 2007年10月05日
 JSONDOCS = [
 # http://json.org/JSON_checker/test/fail1.json
 '"A JSON payload should be an object or array, not a string."',
 # http://json.org/JSON_checker/test/fail2.json
 '["Unclosed array"',
 # http://json.org/JSON_checker/test/fail3.json
- '{unquoted_key: "keys must be quoted}',
+ '{unquoted_key: "keys must be quoted"}',
 # http://json.org/JSON_checker/test/fail4.json
 '["extra comma",]',
 # http://json.org/JSON_checker/test/fail5.json
@@ -33,7 +33,7 @@
 # http://json.org/JSON_checker/test/fail15.json
 '["Illegal backslash escape: \\x15"]',
 # http://json.org/JSON_checker/test/fail16.json
- '["Illegal backslash escape: \\\'"]',
+ '[\\naked]',
 # http://json.org/JSON_checker/test/fail17.json
 '["Illegal backslash escape: \017円"]',
 # http://json.org/JSON_checker/test/fail18.json
@@ -50,6 +50,24 @@
 '["Bad value", truth]',
 # http://json.org/JSON_checker/test/fail24.json
 "['single quote']",
+ # http://json.org/JSON_checker/test/fail25.json
+ '["\ttab\tcharacter\tin\tstring\t"]',
+ # http://json.org/JSON_checker/test/fail26.json
+ '["tab\\ character\\ in\\ string\\ "]',
+ # http://json.org/JSON_checker/test/fail27.json
+ '["line\nbreak"]',
+ # http://json.org/JSON_checker/test/fail28.json
+ '["line\\\nbreak"]',
+ # http://json.org/JSON_checker/test/fail29.json
+ '[0e]',
+ # http://json.org/JSON_checker/test/fail30.json
+ '[0e+]',
+ # http://json.org/JSON_checker/test/fail31.json
+ '[0e+-1]',
+ # http://json.org/JSON_checker/test/fail32.json
+ '{"Comma instead if closing brace": true,',
+ # http://json.org/JSON_checker/test/fail33.json
+ '["mismatch"}',
 # http://code.google.com/p/simplejson/issues/detail?id=3
 '["A\u001FZ control characters in string"]',
 ]
diff --git a/Lib/test/json_tests/test_float.py b/Lib/test/json_tests/test_float.py
--- a/Lib/test/json_tests/test_float.py
+++ b/Lib/test/json_tests/test_float.py
@@ -13,6 +13,21 @@
 self.assertEqual(self.dumps(num), str(num))
 self.assertEqual(int(self.dumps(num)), num)
 
+ def test_out_of_range(self):
+ self.assertEqual(self.loads('[23456789012E666]'), [float('inf')])
+ self.assertEqual(self.loads('[-23456789012E666]'), [float('-inf')])
+
+ def test_allow_nan(self):
+ for val in (float('inf'), float('-inf'), float('nan')):
+ out = self.dumps([val])
+ if val == val: # inf
+ self.assertEqual(self.loads(out), [val])
+ else: # nan
+ res = self.loads(out)
+ self.assertEqual(len(res), 1)
+ self.assertNotEqual(res[0], res[0])
+ self.assertRaises(ValueError, self.dumps, [val], allow_nan=False)
+
 
 class TestPyFloat(TestFloat, PyTest): pass
 class TestCFloat(TestFloat, CTest): pass
diff --git a/Lib/test/json_tests/test_pass1.py b/Lib/test/json_tests/test_pass1.py
--- a/Lib/test/json_tests/test_pass1.py
+++ b/Lib/test/json_tests/test_pass1.py
@@ -17,7 +17,7 @@
 "real": -9876.543210,
 "e": 0.123456789e-12,
 "E": 1.234567890E+34,
- "": 23456789012E666,
+ "": 23456789012E66,
 "zero": 0,
 "one": 1,
 "space": " ",
@@ -28,6 +28,7 @@
 "alpha": "abcdefghijklmnopqrstuvwyz",
 "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
 "digit": "0123456789",
+ "0123456789": "digit",
 "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
 "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
 "true": true,
@@ -43,8 +44,7 @@
 
 ,
 
-4 , 5 , 6 ,7 ],
- "compact": [1,2,3,4,5,6,7],
+4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7],
 "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
 "quotes": "" \u0022 %22 0x22 034 &#x22;",
 "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
@@ -55,9 +55,11 @@
 99.44
 ,
 
-1066
-
-
+1066,
+1e1,
+0.1e1,
+1e-1,
+1e00,2e+00,2e-00
 ,"rosebud"]
 '''
 
@@ -67,12 +69,6 @@
 res = self.loads(JSON)
 out = self.dumps(res)
 self.assertEqual(res, self.loads(out))
- try:
- self.dumps(res, allow_nan=False)
- except ValueError:
- pass
- else:
- self.fail("23456789012E666 should be out of range")
 
 
 class TestPyPass1(TestPass1, PyTest): pass
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -641,6 +641,9 @@
 Tests
 -----
 
+- Issue #16559: Add more tests for the json module, including some from the
+ official test suite at json.org. Patch by Serhiy Storchaka.
+
 - Issue #15304: Fix warning message when os.chdir() fails inside
 test.support.temp_cwd(). Patch by Chris Jerdonek.
 
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /