2008-05-05 17:21:38 -03:00
|
|
|
from unittest import TestCase
|
|
|
|
from cStringIO import StringIO
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
class TestDump(TestCase):
|
|
|
|
def test_dump(self):
|
|
|
|
sio = StringIO()
|
|
|
|
json.dump({}, sio)
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(sio.getvalue(), '{}')
|
2008-05-05 17:21:38 -03:00
|
|
|
|
|
|
|
def test_dumps(self):
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(json.dumps({}), '{}')
|
2009-03-17 20:19:00 -03:00
|
|
|
|
|
|
|
def test_encode_truefalse(self):
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(json.dumps(
|
2009-03-17 20:19:00 -03:00
|
|
|
{True: False, False: True}, sort_keys=True),
|
|
|
|
'{"false": true, "true": false}')
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(json.dumps(
|
2010-01-26 11:57:21 -04:00
|
|
|
{2: 3.0, 4.0: 5L, False: 1, 6L: True}, sort_keys=True),
|
|
|
|
'{"false": 1, "2": 3.0, "4.0": 5, "6": true}')
|