PageRenderTime 243ms CodeModel.GetById 121ms app.highlight 3ms RepoModel.GetById 117ms app.codeStats 0ms

/Lib/json/tests/test_pass1.py

http://unladen-swallow.googlecode.com/
Python | 76 lines | 73 code | 2 blank | 1 comment | 0 complexity | 19ac46570766fdaa9df8371f12f6310b MD5 | raw file
 1from unittest import TestCase
 2
 3import json
 4
 5# from http://json.org/JSON_checker/test/pass1.json
 6JSON = r'''
 7[
 8    "JSON Test Pattern pass1",
 9    {"object with 1 member":["array with 1 element"]},
10    {},
11    [],
12    -42,
13    true,
14    false,
15    null,
16    {
17        "integer": 1234567890,
18        "real": -9876.543210,
19        "e": 0.123456789e-12,
20        "E": 1.234567890E+34,
21        "":  23456789012E666,
22        "zero": 0,
23        "one": 1,
24        "space": " ",
25        "quote": "\"",
26        "backslash": "\\",
27        "controls": "\b\f\n\r\t",
28        "slash": "/ & \/",
29        "alpha": "abcdefghijklmnopqrstuvwyz",
30        "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
31        "digit": "0123456789",
32        "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
33        "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
34        "true": true,
35        "false": false,
36        "null": null,
37        "array":[  ],
38        "object":{  },
39        "address": "50 St. James Street",
40        "url": "http://www.JSON.org/",
41        "comment": "// /* <!-- --",
42        "# -- --> */": " ",
43        " s p a c e d " :[1,2 , 3
44
45,
46
474 , 5        ,          6           ,7        ],
48        "compact": [1,2,3,4,5,6,7],
49        "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
50        "quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
51        "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
52: "A key can be any string"
53    },
54    0.5 ,98.6
55,
5699.44
57,
58
591066
60
61
62,"rosebud"]
63'''
64
65class TestPass1(TestCase):
66    def test_parse(self):
67        # test in/out equivalence and parsing
68        res = json.loads(JSON)
69        out = json.dumps(res)
70        self.assertEquals(res, json.loads(out))
71        try:
72            json.dumps(res, allow_nan=False)
73        except ValueError:
74            pass
75        else:
76            self.fail("23456789012E666 should be out of range")