##// END OF EJS Templates
avoid jsonlib returning Decimal...
MinRK -
Show More
@@ -73,9 +73,22 b' def squash_unicode(obj):'
73 # globals and defaults
73 # globals and defaults
74 #-----------------------------------------------------------------------------
74 #-----------------------------------------------------------------------------
75
75
76 key = 'on_unknown' if jsonapi.jsonmod.__name__ == 'jsonlib' else 'default'
76
77 json_packer = lambda obj: jsonapi.dumps(obj, **{key:date_default})
77 # jsonlib behaves a bit differently, so handle that where it affects us
78 json_unpacker = lambda s: extract_dates(jsonapi.loads(s))
78 if jsonapi.jsonmod.__name__ == 'jsonlib':
79 # kwarg for serializing unknown types (datetime) is different
80 dumps_kwargs = dict(on_unknown=date_default)
81 # By default, jsonlib unpacks floats as Decimal instead of float,
82 # which can foul things up
83 loads_kwargs = dict(use_float=True)
84 else:
85 # ISO8601-ify datetime objects
86 dumps_kwargs = dict(default=date_default)
87 # nothing to specify for loads
88 loads_kwargs = dict()
89
90 json_packer = lambda obj: jsonapi.dumps(obj, **dumps_kwargs)
91 json_unpacker = lambda s: extract_dates(jsonapi.loads(s, **loads_kwargs))
79
92
80 pickle_packer = lambda o: pickle.dumps(o,-1)
93 pickle_packer = lambda o: pickle.dumps(o,-1)
81 pickle_unpacker = pickle.loads
94 pickle_unpacker = pickle.loads
@@ -59,7 +59,7 b' class TestSession(SessionTestCase):'
59 self.assertEquals(msg['msg_type'], 'execute')
59 self.assertEquals(msg['msg_type'], 'execute')
60
60
61 def test_serialize(self):
61 def test_serialize(self):
62 msg = self.session.msg('execute',content=dict(a=10))
62 msg = self.session.msg('execute', content=dict(a=10, b=1.1))
63 msg_list = self.session.serialize(msg, ident=b'foo')
63 msg_list = self.session.serialize(msg, ident=b'foo')
64 ident, msg_list = self.session.feed_identities(msg_list)
64 ident, msg_list = self.session.feed_identities(msg_list)
65 new_msg = self.session.unserialize(msg_list)
65 new_msg = self.session.unserialize(msg_list)
@@ -69,6 +69,8 b' class TestSession(SessionTestCase):'
69 self.assertEquals(new_msg['header'],msg['header'])
69 self.assertEquals(new_msg['header'],msg['header'])
70 self.assertEquals(new_msg['content'],msg['content'])
70 self.assertEquals(new_msg['content'],msg['content'])
71 self.assertEquals(new_msg['parent_header'],msg['parent_header'])
71 self.assertEquals(new_msg['parent_header'],msg['parent_header'])
72 # ensure floats don't come out as Decimal:
73 self.assertEquals(type(new_msg['content']['b']),type(new_msg['content']['b']))
72
74
73 def test_send(self):
75 def test_send(self):
74 socket = MockSocket(zmq.Context.instance(),zmq.PAIR)
76 socket = MockSocket(zmq.Context.instance(),zmq.PAIR)
General Comments 0
You need to be logged in to leave comments. Login now