ยปCore Development>Code coverage>Lib/test/test_json/__init__.py

Python code coverage for Lib/test/test_json/__init__.py

#countcontent
1n/aimport os
2n/aimport json
3n/aimport doctest
4n/aimport unittest
5n/a
6n/afrom test import support
7n/a
8n/a# import json with and without accelerations
9n/acjson = support.import_fresh_module('json', fresh=['_json'])
10n/apyjson = support.import_fresh_module('json', blocked=['_json'])
11n/a# JSONDecodeError is cached inside the _json module
12n/acjson.JSONDecodeError = cjson.decoder.JSONDecodeError = json.JSONDecodeError
13n/a
14n/a# create two base classes that will be used by the other tests
15n/aclass PyTest(unittest.TestCase):
16n/a json = pyjson
17n/a loads = staticmethod(pyjson.loads)
18n/a dumps = staticmethod(pyjson.dumps)
19n/a JSONDecodeError = staticmethod(pyjson.JSONDecodeError)
20n/a
21n/a@unittest.skipUnless(cjson, 'requires _json')
22n/aclass CTest(unittest.TestCase):
23n/a if cjson is not None:
24n/a json = cjson
25n/a loads = staticmethod(cjson.loads)
26n/a dumps = staticmethod(cjson.dumps)
27n/a JSONDecodeError = staticmethod(cjson.JSONDecodeError)
28n/a
29n/a# test PyTest and CTest checking if the functions come from the right module
30n/aclass TestPyTest(PyTest):
31n/a def test_pyjson(self):
32n/a self.assertEqual(self.json.scanner.make_scanner.__module__,
33n/a 'json.scanner')
34n/a self.assertEqual(self.json.decoder.scanstring.__module__,
35n/a 'json.decoder')
36n/a self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__,
37n/a 'json.encoder')
38n/a
39n/aclass TestCTest(CTest):
40n/a def test_cjson(self):
41n/a self.assertEqual(self.json.scanner.make_scanner.__module__, '_json')
42n/a self.assertEqual(self.json.decoder.scanstring.__module__, '_json')
43n/a self.assertEqual(self.json.encoder.c_make_encoder.__module__, '_json')
44n/a self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__,
45n/a '_json')
46n/a
47n/a
48n/adef load_tests(loader, _, pattern):
49n/a suite = unittest.TestSuite()
50n/a for mod in (json, json.encoder, json.decoder):
51n/a suite.addTest(doctest.DocTestSuite(mod))
52n/a suite.addTest(TestPyTest('test_pyjson'))
53n/a suite.addTest(TestCTest('test_cjson'))
54n/a
55n/a pkg_dir = os.path.dirname(__file__)
56n/a return support.load_package_tests(pkg_dir, loader, suite, pattern)