PATH:
usr
/
lib64
/
python2.7
/
json
/
tests
import decimal from StringIO import StringIO from collections import OrderedDict from json.tests import PyTest, CTest class TestDecode(object): def test_decimal(self): rval = self.loads('1.1', parse_float=decimal.Decimal) self.assertTrue(isinstance(rval, decimal.Decimal)) self.assertEqual(rval, decimal.Decimal('1.1')) def test_float(self): rval = self.loads('1', parse_int=float) self.assertTrue(isinstance(rval, float)) self.assertEqual(rval, 1.0) def test_decoder_optimizations(self): # Several optimizations were made that skip over calls to # the whitespace regex, so this test is designed to try and # exercise the uncommon cases. The array cases are already covered. rval = self.loads('{ "key" : "value" , "k":"v" }') self.assertEqual(rval, {"key":"value", "k":"v"}) def test_empty_objects(self): self.assertEqual(self.loads('{}'), {}) self.assertEqual(self.loads('[]'), []) self.assertEqual(self.loads('""'), u"") self.assertIsInstance(self.loads('""'), unicode) def test_object_pairs_hook(self): s = '{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}' p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4), ("qrt", 5), ("pad", 6), ("hoy", 7)] self.assertEqual(self.loads(s), eval(s)) self.assertEqual(self.loads(s, object_pairs_hook=lambda x: x), p) self.assertEqual(self.json.load(StringIO(s), object_pairs_hook=lambda x: x), p) od = self.loads(s, object_pairs_hook=OrderedDict) self.assertEqual(od, OrderedDict(p)) self.assertEqual(type(od), OrderedDict) # the object_pairs_hook takes priority over the object_hook self.assertEqual(self.loads(s, object_pairs_hook=OrderedDict, object_hook=lambda x: None), OrderedDict(p)) # check that empty object literals work (see #17368) self.assertEqual(self.loads('{}', object_pairs_hook=OrderedDict), OrderedDict()) self.assertEqual(self.loads('{"empty": {}}', object_pairs_hook=OrderedDict), OrderedDict([('empty', OrderedDict())])) def test_extra_data(self): s = '[1, 2, 3]5' msg = 'Extra data' self.assertRaisesRegexp(ValueError, msg, self.loads, s) def test_invalid_escape(self): s = '["abc\\y"]' msg = 'escape' self.assertRaisesRegexp(ValueError, msg, self.loads, s) def test_negative_index(self): d = self.json.JSONDecoder() self.assertRaises(ValueError, d.raw_decode, 'a'*42, -50000) self.assertRaises(ValueError, d.raw_decode, u'a'*42, -50000) class TestPyDecode(TestDecode, PyTest): pass class TestCDecode(TestDecode, CTest): pass
[-] test_pass2.py
[open]
[-] test_pass3.py
[open]
[-] test_pass2.pyc
[open]
[-] test_default.py
[open]
[-] test_recursion.py
[open]
[-] test_check_circular.pyo
[open]
[+]
..
[-] test_default.pyc
[open]
[-] test_speedups.py
[open]
[-] test_speedups.pyc
[open]
[-] test_pass1.py
[open]
[-] test_check_circular.py
[open]
[-] test_separators.pyo
[open]
[-] test_encode_basestring_ascii.pyc
[open]
[-] test_speedups.pyo
[open]
[-] test_check_circular.pyc
[open]
[-] test_pass3.pyc
[open]
[-] test_float.pyo
[open]
[-] test_decode.py
[open]
[-] test_unicode.pyo
[open]
[-] test_scanstring.py
[open]
[-] __init__.pyc
[open]
[-] test_pass2.pyo
[open]
[-] test_default.pyo
[open]
[-] test_encode_basestring_ascii.pyo
[open]
[-] test_recursion.pyc
[open]
[-] test_pass1.pyc
[open]
[-] test_decode.pyo
[open]
[-] test_fail.pyo
[open]
[-] test_recursion.pyo
[open]
[-] test_dump.pyo
[open]
[-] test_decode.pyc
[open]
[-] test_pass1.pyo
[open]
[-] test_float.pyc
[open]
[-] test_pass3.pyo
[open]
[-] test_encode_basestring_ascii.py
[open]
[-] test_fail.pyc
[open]
[-] test_separators.pyc
[open]
[-] test_separators.py
[open]
[-] test_indent.pyo
[open]
[-] test_unicode.pyc
[open]
[-] test_unicode.py
[open]
[-] test_scanstring.pyo
[open]
[-] test_tool.pyo
[open]
[-] __init__.py
[open]
[-] test_tool.py
[open]
[-] test_indent.py
[open]
[-] test_indent.pyc
[open]
[-] test_dump.pyc
[open]
[-] test_tool.pyc
[open]
[-] test_dump.py
[open]
[-] test_fail.py
[open]
[-] test_scanstring.pyc
[open]
[-] test_float.py
[open]
[-] __init__.pyo
[open]