1
from decimal import Decimal
2
from unittest import TestCase
4
import simplejson as json
6
class TestDecimal(TestCase):
7
NUMS = "1.0", "10.00", "1.1", "1234567890.1234567890", "500"
8
def test_decimal_encode(self):
9
for d in map(Decimal, self.NUMS):
10
self.assertEquals(json.dumps(d, use_decimal=True), str(d))
12
def test_decimal_decode(self):
14
self.assertEquals(json.loads(s, parse_float=Decimal), Decimal(s))
16
def test_decimal_roundtrip(self):
17
for d in map(Decimal, self.NUMS):
18
# The type might not be the same (int and Decimal) but they
19
# should still compare equal.
22
json.dumps(d, use_decimal=True), parse_float=Decimal),
26
json.dumps([d], use_decimal=True), parse_float=Decimal),
29
def test_decimal_defaults(self):
31
# use_decimal=False is the default
32
self.assertRaises(TypeError, json.dumps, d, use_decimal=False)
33
self.assertRaises(TypeError, json.dumps, d)
b'\\ No newline at end of file'