示例#1
0
 def test_unknown_dumps(self):
     error_text = "<object object at .*> is not JSON serializable"
     with self.assertRaisesRegexp(TypeError, error_text):
         json.dumps(object())
示例#2
0
 def test_jsonobject_dumps(self):
     expected = '{"__user__": {"first_name": "Isaak", "last_name": "Knewton", "email": null}}\n'
     json_object = json.JSONObject("__user__", {"first_name": "Isaak", "last_name": "Knewton", "email": None})
     actual = json.dumps(json_object)
     assert expected == actual
示例#3
0
 def test_date_dumps(self):
     expected = '{"__date__": "2000-01-01"}\n'
     actual = json.dumps(datetime.date(2000, 1, 1))
     assert expected == actual
示例#4
0
 def test_decimal_dumps_negative(self):
     expected = '{"__decimal__": {"__string_repr__": "-10001e-1", ' '"__float_repr__": -1000.1}}\n'
     actual = json.dumps(decimal.Decimal("-1000.1"))
     assert expected == actual
示例#5
0
 def test_string_dumps(self):
     assert '"foobar"\n' == json.dumps("foobar")