]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.10/Lib/json/tests/__init__.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.10 / Lib / json / tests / __init__.py
CommitLineData
3257aa99
DM
1import os\r
2import sys\r
3import json\r
4import doctest\r
5import unittest\r
6\r
7from test import test_support\r
8\r
9# import json with and without accelerations\r
10cjson = test_support.import_fresh_module('json', fresh=['_json'])\r
11pyjson = test_support.import_fresh_module('json', blocked=['_json'])\r
12\r
13# create two base classes that will be used by the other tests\r
14class PyTest(unittest.TestCase):\r
15 json = pyjson\r
16 loads = staticmethod(pyjson.loads)\r
17 dumps = staticmethod(pyjson.dumps)\r
18\r
19@unittest.skipUnless(cjson, 'requires _json')\r
20class CTest(unittest.TestCase):\r
21 if cjson is not None:\r
22 json = cjson\r
23 loads = staticmethod(cjson.loads)\r
24 dumps = staticmethod(cjson.dumps)\r
25\r
26# test PyTest and CTest checking if the functions come from the right module\r
27class TestPyTest(PyTest):\r
28 def test_pyjson(self):\r
29 self.assertEqual(self.json.scanner.make_scanner.__module__,\r
30 'json.scanner')\r
31 self.assertEqual(self.json.decoder.scanstring.__module__,\r
32 'json.decoder')\r
33 self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__,\r
34 'json.encoder')\r
35\r
36class TestCTest(CTest):\r
37 def test_cjson(self):\r
38 self.assertEqual(self.json.scanner.make_scanner.__module__, '_json')\r
39 self.assertEqual(self.json.decoder.scanstring.__module__, '_json')\r
40 self.assertEqual(self.json.encoder.c_make_encoder.__module__, '_json')\r
41 self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__,\r
42 '_json')\r
43\r
44\r
45here = os.path.dirname(__file__)\r
46\r
47def test_suite():\r
48 suite = additional_tests()\r
49 loader = unittest.TestLoader()\r
50 for fn in os.listdir(here):\r
51 if fn.startswith("test") and fn.endswith(".py"):\r
52 modname = "json.tests." + fn[:-3]\r
53 __import__(modname)\r
54 module = sys.modules[modname]\r
55 suite.addTests(loader.loadTestsFromModule(module))\r
56 return suite\r
57\r
58def additional_tests():\r
59 suite = unittest.TestSuite()\r
60 for mod in (json, json.encoder, json.decoder):\r
61 suite.addTest(doctest.DocTestSuite(mod))\r
62 suite.addTest(TestPyTest('test_pyjson'))\r
63 suite.addTest(TestCTest('test_cjson'))\r
64 return suite\r
65\r
66def main():\r
67 suite = test_suite()\r
68 runner = unittest.TextTestRunner()\r
69 runner.run(suite)\r
70\r
71if __name__ == '__main__':\r
72 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))\r
73 main()\r