##// END OF EJS Templates
test date time treatment in Session...
MinRK -
Show More
@@ -13,6 +13,8 b''
13
13
14 import os
14 import os
15 import uuid
15 import uuid
16 from datetime import datetime
17
16 import zmq
18 import zmq
17
19
18 from zmq.tests import BaseZMQTestCase
20 from zmq.tests import BaseZMQTestCase
@@ -20,6 +22,10 b' from zmq.eventloop.zmqstream import ZMQStream'
20
22
21 from IPython.kernel.zmq import session as ss
23 from IPython.kernel.zmq import session as ss
22
24
25 from IPython.testing.decorators import skipif, module_not_available
26 from IPython.utils.py3compat import string_types
27 from IPython.utils import jsonutil
28
23 def _bad_packer(obj):
29 def _bad_packer(obj):
24 raise TypeError("I don't work")
30 raise TypeError("I don't work")
25
31
@@ -155,24 +161,6 b' class TestSession(SessionTestCase):'
155 t.wait(1) # this will raise
161 t.wait(1) # this will raise
156
162
157
163
158 # def test_rekey(self):
159 # """rekeying dict around json str keys"""
160 # d = {'0': uuid.uuid4(), 0:uuid.uuid4()}
161 # self.assertRaises(KeyError, ss.rekey, d)
162 #
163 # d = {'0': uuid.uuid4(), 1:uuid.uuid4(), 'asdf':uuid.uuid4()}
164 # d2 = {0:d['0'],1:d[1],'asdf':d['asdf']}
165 # rd = ss.rekey(d)
166 # self.assertEqual(d2,rd)
167 #
168 # d = {'1.5':uuid.uuid4(),'1':uuid.uuid4()}
169 # d2 = {1.5:d['1.5'],1:d['1']}
170 # rd = ss.rekey(d)
171 # self.assertEqual(d2,rd)
172 #
173 # d = {'1.0':uuid.uuid4(),'1':uuid.uuid4()}
174 # self.assertRaises(KeyError, ss.rekey, d)
175 #
176 def test_unique_msg_ids(self):
164 def test_unique_msg_ids(self):
177 """test that messages receive unique ids"""
165 """test that messages receive unique ids"""
178 ids = set()
166 ids = set()
@@ -267,5 +255,35 b' class TestSession(SessionTestCase):'
267
255
268 def test_bad_roundtrip(self):
256 def test_bad_roundtrip(self):
269 with self.assertRaises(ValueError):
257 with self.assertRaises(ValueError):
270 session= ss.Session(unpack=lambda b: 5)
258 session = ss.Session(unpack=lambda b: 5)
259
260 def _datetime_test(self, session):
261 content = dict(t=datetime.now())
262 metadata = dict(t=datetime.now())
263 p = session.msg('msg')
264 msg = session.msg('msg', content=content, metadata=metadata, parent=p['header'])
265 smsg = session.serialize(msg)
266 msg2 = session.unserialize(session.feed_identities(smsg)[1])
267 assert isinstance(msg2['header']['date'], datetime)
268 self.assertEqual(msg['header'], msg2['header'])
269 self.assertEqual(msg['parent_header'], msg2['parent_header'])
270 self.assertEqual(msg['parent_header'], msg2['parent_header'])
271 assert isinstance(msg['content']['t'], datetime)
272 assert isinstance(msg['metadata']['t'], datetime)
273 assert isinstance(msg2['content']['t'], string_types)
274 assert isinstance(msg2['metadata']['t'], string_types)
275 self.assertEqual(msg['content'], jsonutil.extract_dates(msg2['content']))
276 self.assertEqual(msg['content'], jsonutil.extract_dates(msg2['content']))
277
278 def test_datetimes(self):
279 self._datetime_test(self.session)
280
281 def test_datetimes_pickle(self):
282 session = ss.Session(packer='pickle')
283 self._datetime_test(session)
284
285 @skipif(module_not_available('msgpack'))
286 def test_datetimes_msgpack(self):
287 session = ss.Session(packer='msgpack.packb', unpacker='msgpack.unpackb')
288 self._datetime_test(session)
271
289
General Comments 0
You need to be logged in to leave comments. Login now