Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(29858)

Side by Side Diff: Lib/test/test_json/__init__.py

Issue 19361: Specialize exceptions thrown by JSON parser
Patch Set: Created 4 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/json/__init__.py ('k') | Lib/test/test_json/test_decode.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import os 1 import os
2 import sys 2 import sys
3 import json 3 import json
4 import doctest 4 import doctest
5 import unittest 5 import unittest
6 6
7 from test import support 7 from test import support
8 8
9 # import json with and without accelerations 9 # import json with and without accelerations
10 cjson = support.import_fresh_module('json', fresh=['_json']) 10 cjson = support.import_fresh_module('json', fresh=['_json'])
11 pyjson = support.import_fresh_module('json', blocked=['_json']) 11 pyjson = support.import_fresh_module('json', blocked=['_json'])
12 # JSONDecodeError is cached inside the _json module
13 cjson.JSONDecodeError = cjson.decoder.JSONDecodeError = json.JSONDecodeError
12 14
13 # create two base classes that will be used by the other tests 15 # create two base classes that will be used by the other tests
14 class PyTest(unittest.TestCase): 16 class PyTest(unittest.TestCase):
15 json = pyjson 17 json = pyjson
16 loads = staticmethod(pyjson.loads) 18 loads = staticmethod(pyjson.loads)
17 dumps = staticmethod(pyjson.dumps) 19 dumps = staticmethod(pyjson.dumps)
20 JSONDecodeError = staticmethod(pyjson.JSONDecodeError)
18 21
19 @unittest.skipUnless(cjson, 'requires _json') 22 @unittest.skipUnless(cjson, 'requires _json')
20 class CTest(unittest.TestCase): 23 class CTest(unittest.TestCase):
21 if cjson is not None: 24 if cjson is not None:
22 json = cjson 25 json = cjson
23 loads = staticmethod(cjson.loads) 26 loads = staticmethod(cjson.loads)
24 dumps = staticmethod(cjson.dumps) 27 dumps = staticmethod(cjson.dumps)
28 JSONDecodeError = staticmethod(cjson.JSONDecodeError)
25 29
26 # test PyTest and CTest checking if the functions come from the right module 30 # test PyTest and CTest checking if the functions come from the right module
27 class TestPyTest(PyTest): 31 class TestPyTest(PyTest):
28 def test_pyjson(self): 32 def test_pyjson(self):
29 self.assertEqual(self.json.scanner.make_scanner.__module__, 33 self.assertEqual(self.json.scanner.make_scanner.__module__,
30 'json.scanner') 34 'json.scanner')
31 self.assertEqual(self.json.decoder.scanstring.__module__, 35 self.assertEqual(self.json.decoder.scanstring.__module__,
32 'json.decoder') 36 'json.decoder')
33 self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, 37 self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__,
34 'json.encoder') 38 'json.encoder')
35 39
36 class TestCTest(CTest): 40 class TestCTest(CTest):
37 def test_cjson(self): 41 def test_cjson(self):
38 self.assertEqual(self.json.scanner.make_scanner.__module__, '_json') 42 self.assertEqual(self.json.scanner.make_scanner.__module__, '_json')
39 self.assertEqual(self.json.decoder.scanstring.__module__, '_json') 43 self.assertEqual(self.json.decoder.scanstring.__module__, '_json')
40 self.assertEqual(self.json.encoder.c_make_encoder.__module__, '_json') 44 self.assertEqual(self.json.encoder.c_make_encoder.__module__, '_json')
41 self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, 45 self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__,
42 '_json') 46 '_json')
43 47
44 48
45 def load_tests(loader, _, pattern): 49 def load_tests(loader, _, pattern):
46 suite = unittest.TestSuite() 50 suite = unittest.TestSuite()
47 for mod in (json, json.encoder, json.decoder): 51 for mod in (json, json.encoder, json.decoder):
48 suite.addTest(doctest.DocTestSuite(mod)) 52 suite.addTest(doctest.DocTestSuite(mod))
49 suite.addTest(TestPyTest('test_pyjson')) 53 suite.addTest(TestPyTest('test_pyjson'))
50 suite.addTest(TestCTest('test_cjson')) 54 suite.addTest(TestCTest('test_cjson'))
51 55
52 pkg_dir = os.path.dirname(__file__) 56 pkg_dir = os.path.dirname(__file__)
53 return support.load_package_tests(pkg_dir, loader, suite, pattern) 57 return support.load_package_tests(pkg_dir, loader, suite, pattern)
OLDNEW
« no previous file with comments | « Lib/json/__init__.py ('k') | Lib/test/test_json/test_decode.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+