Esempio n. 1
0
 def test_nested_dict_encode(self):
     self.assertEqual(
         json_encode({
             u"name":
             u"Paul",
             u"decimal_number":
             14.46,
             u"float_number":
             14.456,
             u"int_number":
             122,
             u"my_dict": {
                 u"value_1": 1,
                 u"value_2": u"2"
             },
             u"list": [{
                 u"value_1": 1,
                 u"value_2": u"2"
             }, {
                 u"value_1": 1,
                 u"value_2": u"2"
             }, {
                 u"value_1": 1,
                 u"value_2": u"2"
             }]
         }),
         '{"name": "Paul", "decimal_number": 14.46, "float_number": 14.456, "int_number": 122, "my_dict": {"value_1": 1, "value_2": "2"}, "list": [{"value_1": 1, "value_2": "2"}, {"value_1": 1, "value_2": "2"}, {"value_1": 1, "value_2": "2"}]}'
     )
Esempio n. 2
0
 def dump(obj, fp):
     try:
         f = open(fp, 'w')
         f.write(json_encode(obj))
         f.close()
     except Exception as e:
         print('error')            
Esempio n. 3
0
 def test_dict_encode(self):
     self.assertEqual(
         json_encode({
             "name": "Gena Bukin",
             "float_number": 14.5644,
             "int_number": 4
         }),
         "{\"name\": \"Gena Bukin\", \"float_number\": 14.5644, \"int_number\": 4}"
     )
Esempio n. 4
0
 def test_class_encode(self):
     obj = CustomClass("Valerii", "Jmyshenko", 54)
     self.assertEqual(
         json_encode(obj),
         '"{\\"fname\\": \\"Valerii\\", \\"lname\\": \\"Jmyshenko\\", \\"age\\": 54}"'
     )
Esempio n. 5
0
 def dumps(obj):
     return json_encode(obj)