2008-05-08 11:29:10 -03:00
|
|
|
from unittest import TestCase
|
|
|
|
from io import StringIO
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
class TestDump(TestCase):
|
|
|
|
def test_dump(self):
|
|
|
|
sio = StringIO()
|
|
|
|
json.dump({}, sio)
|
2010-11-20 15:04:17 -04:00
|
|
|
self.assertEqual(sio.getvalue(), '{}')
|
2008-05-08 11:29:10 -03:00
|
|
|
|
|
|
|
def test_dumps(self):
|
2010-11-20 15:04:17 -04:00
|
|
|
self.assertEqual(json.dumps({}), '{}')
|
2009-05-02 09:36:44 -03:00
|
|
|
|
|
|
|
def test_encode_truefalse(self):
|
2010-11-20 15:04:17 -04:00
|
|
|
self.assertEqual(json.dumps(
|
2009-05-02 09:36:44 -03:00
|
|
|
{True: False, False: True}, sort_keys=True),
|
|
|
|
'{"false": true, "true": false}')
|
2010-11-20 15:04:17 -04:00
|
|
|
self.assertEqual(json.dumps(
|
2009-05-02 09:36:44 -03:00
|
|
|
{2: 3.0, 4.0: 5, False: 1, 6: True}, sort_keys=True),
|
|
|
|
'{"false": 1, "2": 3.0, "4.0": 5, "6": true}')
|