Example #1
0
def main():
    obj = [
        {
            "a": 1,
            "b": [
                [
                    [
                        1,
                        2,
                        3,
                        [
                            [
                                5,
                                6,
                                [False, [True], [{}, {}, {}, None, False, True, 10.12, -10.13123123]],
                                {"a": {"b": {"c": {"d": [-1, -2, -3, 0]}}}},
                            ]
                        ],
                    ]
                ]
            ],
        },
        {},
        {},
        False,
        "sample text",
        {"!": [{}, [{'"': "this \t is \n quote key"}, {}]]},
    ]
    json = to_json(obj)
    parsed = from_json(json)
    print(json)
    print(parsed)
    print("obj == parsed is", parsed == obj)
 def __new__(cls, name, parents, dct):
     with open(fname) as attrs:
         content = ''.join(attrs.readlines())
         obj = from_json(content)
         for tuple in obj.items():
             key = tuple[0]
             value = tuple[1]
             if key is not dct:
                 dct[key] = value
     return super(AttrBuilderMetaClassHidden, cls).__new__(cls, name, parents, dct)
Example #3
0
 def test_equal(self):
     obj = [{'a': 1, 'b': [
         [[1, 2, 3, [[5, 6, [False, [True], [{}, {}, {}, None, False, True, 10.12, -10.13123123]],
                      {'a': {'b': {'c': {'d': [-1, -2, -3, 0]}}}}]]]]]}, {}, {}, False, "sample text",
            {'!': [{}, [{'"': 'this \t is \n quote key'}, {}]]}]
     self.assertSequenceEqual(from_json(to_json(obj)), obj)
Example #4
0
 def test_parse_g(self):
     try:
         self.assertRaises(ParseException, from_json('{"a":{{}'))
     except BaseException as e:
         self.assertIsInstance(e, ParseException)
Example #5
0
 def test_parse_d(self):
     try:
         self.assertRaises(ParseException, from_json('[{{{{{}}]'))
     except BaseException as e:
         self.assertIsInstance(e, ParseException)
Example #6
0
 def test_parse(self):
     self.assertEqual(from_json(""), None)