]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Python/Python-2.7.2/Lib/json/tests/__init__.py
7 from test
import test_support
9 # import json with and without accelerations
10 cjson
= test_support
.import_fresh_module('json', fresh
=['_json'])
11 pyjson
= test_support
.import_fresh_module('json', blocked
=['_json'])
13 # create two base classes that will be used by the other tests
14 class PyTest(unittest
.TestCase
):
16 loads
= staticmethod(pyjson
.loads
)
17 dumps
= staticmethod(pyjson
.dumps
)
19 @unittest.skipUnless(cjson
, 'requires _json')
20 class CTest(unittest
.TestCase
):
23 loads
= staticmethod(cjson
.loads
)
24 dumps
= staticmethod(cjson
.dumps
)
26 # test PyTest and CTest checking if the functions come from the right module
27 class TestPyTest(PyTest
):
28 def test_pyjson(self
):
29 self
.assertEqual(self
.json
.scanner
.make_scanner
.__module
__,
31 self
.assertEqual(self
.json
.decoder
.scanstring
.__module
__,
33 self
.assertEqual(self
.json
.encoder
.encode_basestring_ascii
.__module
__,
36 class TestCTest(CTest
):
38 self
.assertEqual(self
.json
.scanner
.make_scanner
.__module
__, '_json')
39 self
.assertEqual(self
.json
.decoder
.scanstring
.__module
__, '_json')
40 self
.assertEqual(self
.json
.encoder
.c_make_encoder
.__module
__, '_json')
41 self
.assertEqual(self
.json
.encoder
.encode_basestring_ascii
.__module
__,
45 here
= os
.path
.dirname(__file__
)
48 suite
= additional_tests()
49 loader
= unittest
.TestLoader()
50 for fn
in os
.listdir(here
):
51 if fn
.startswith("test") and fn
.endswith(".py"):
52 modname
= "json.tests." + fn
[:-3]
54 module
= sys
.modules
[modname
]
55 suite
.addTests(loader
.loadTestsFromModule(module
))
58 def additional_tests():
59 suite
= unittest
.TestSuite()
60 for mod
in (json
, json
.encoder
, json
.decoder
):
61 suite
.addTest(doctest
.DocTestSuite(mod
))
62 suite
.addTest(TestPyTest('test_pyjson'))
63 suite
.addTest(TestCTest('test_cjson'))
68 runner
= unittest
.TextTestRunner()
71 if __name__
== '__main__':
72 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
)))))