2022-12-17 08:32:48 -04:00
|
|
|
import collections
|
2013-08-08 09:03:45 -03:00
|
|
|
from test.test_json import PyTest, CTest
|
2008-05-08 11:29:10 -03:00
|
|
|
|
|
|
|
|
2011-05-14 00:47:51 -03:00
|
|
|
class TestDefault:
|
2008-05-08 11:29:10 -03:00
|
|
|
def test_default(self):
|
2010-11-20 15:04:17 -04:00
|
|
|
self.assertEqual(
|
2011-05-14 00:47:51 -03:00
|
|
|
self.dumps(type, default=repr),
|
|
|
|
self.dumps(repr(type)))
|
|
|
|
|
2022-12-17 08:32:48 -04:00
|
|
|
def test_ordereddict(self):
|
|
|
|
od = collections.OrderedDict(a=1, b=2, c=3, d=4)
|
|
|
|
od.move_to_end('b')
|
|
|
|
self.assertEqual(
|
|
|
|
self.dumps(od),
|
|
|
|
'{"a": 1, "c": 3, "d": 4, "b": 2}')
|
|
|
|
self.assertEqual(
|
|
|
|
self.dumps(od, sort_keys=True),
|
|
|
|
'{"a": 1, "b": 2, "c": 3, "d": 4}')
|
|
|
|
|
2011-05-14 00:47:51 -03:00
|
|
|
|
|
|
|
class TestPyDefault(TestDefault, PyTest): pass
|
|
|
|
class TestCDefault(TestDefault, CTest): pass
|