jcgregorio@wpgntai-ubiq72.hot.corp.google.com | ed13252 | 2010-04-19 11:12:52 -0700 | [diff] [blame] | 1 | from unittest import TestCase |
| 2 | from cStringIO import StringIO |
| 3 | |
| 4 | import simplejson as json |
| 5 | |
| 6 | class TestDump(TestCase): |
| 7 | def test_dump(self): |
| 8 | sio = StringIO() |
| 9 | json.dump({}, sio) |
| 10 | self.assertEquals(sio.getvalue(), '{}') |
| 11 | |
| 12 | def test_dumps(self): |
| 13 | self.assertEquals(json.dumps({}), '{}') |
| 14 | |
| 15 | def test_encode_truefalse(self): |
| 16 | self.assertEquals(json.dumps( |
| 17 | {True: False, False: True}, sort_keys=True), |
| 18 | '{"false": true, "true": false}') |
| 19 | self.assertEquals(json.dumps( |
| 20 | {2: 3.0, 4.0: 5L, False: 1, 6L: True, "7": 0}, sort_keys=True), |
| 21 | '{"false": 1, "2": 3.0, "4.0": 5, "6": true, "7": 0}') |
| 22 | |
| 23 | def test_ordered_dict(self): |
| 24 | # http://bugs.python.org/issue6105 |
| 25 | items = [('one', 1), ('two', 2), ('three', 3), ('four', 4), ('five', 5)] |
| 26 | s = json.dumps(json.OrderedDict(items)) |
| 27 | self.assertEqual(s, '{"one": 1, "two": 2, "three": 3, "four": 4, "five": 5}') |