def test_args(self): """initialization arguments for Session""" s = self.session self.assertTrue(s.pack is ss.default_packer) self.assertTrue(s.unpack is ss.default_unpacker) self.assertEqual(s.username, os.environ.get('USER', u'username')) s = ss.Session() self.assertEqual(s.username, os.environ.get('USER', u'username')) self.assertRaises(TypeError, ss.Session, pack='hi') self.assertRaises(TypeError, ss.Session, unpack='hi') u = str(uuid.uuid4()) s = ss.Session(username=u'carrot', session=u) self.assertEqual(s.session, u) self.assertEqual(s.username, u'carrot')
def test_datetimes_msgpack(self): import msgpack session = ss.Session( pack=msgpack.packb, unpack=lambda buf: msgpack.unpackb(buf, encoding='utf8'), ) self._datetime_test(session)
def test_bad_unpacker(self): try: session = ss.Session(unpacker=__name__ + '._bad_unpacker') except ValueError as e: self.assertIn("could not handle output", str(e)) self.assertIn("don't work either", str(e)) else: self.fail("Should have raised ValueError")
def test_bad_packer(self): try: session = ss.Session(packer=__name__ + '._bad_packer') except ValueError as e: self.assertIn("could not serialize", str(e)) self.assertIn("don't work", str(e)) else: self.fail("Should have raised ValueError")
def test_session_id(self): session = ss.Session() # get bs before us bs = session.bsession us = session.session self.assertEqual(us.encode('ascii'), bs) session = ss.Session() # get us before bs us = session.session bs = session.bsession self.assertEqual(us.encode('ascii'), bs) # change propagates: session.session = 'something else' bs = session.bsession us = session.session self.assertEqual(us.encode('ascii'), bs) session = ss.Session(session='stuff') # get us before bs self.assertEqual(session.bsession, session.session.encode('ascii')) self.assertEqual(b'stuff', session.bsession)
def test_cull_digest_history(self): session = ss.Session(digest_history_size=100) for i in range(100): session._add_digest(uuid.uuid4().bytes) self.assertTrue(len(session.digest_history) == 100) session._add_digest(uuid.uuid4().bytes) self.assertTrue(len(session.digest_history) == 91) for i in range(9): session._add_digest(uuid.uuid4().bytes) self.assertTrue(len(session.digest_history) == 100) session._add_digest(uuid.uuid4().bytes) self.assertTrue(len(session.digest_history) == 91)
def get_kernel(kernel_class=MetaKernel): log = logging.getLogger('test') log.setLevel(logging.DEBUG) for hdlr in log.handlers: log.removeHandler(hdlr) hdlr = logging.StreamHandler(StringIO()) hdlr.setLevel(logging.DEBUG) log.addHandler(hdlr) context = zmq.Context.instance() iopub_socket = context.socket(zmq.PUB) kernel = kernel_class(session=ss.Session(), iopub_socket=iopub_socket, log=log) return kernel
def setUp(self): BaseZMQTestCase.setUp(self) self.session = ss.Session()
def test_datetimes_pickle(self): session = ss.Session(packer='pickle') self._datetime_test(session)
def test_bad_roundtrip(self): with self.assertRaises(ValueError): session = ss.Session(unpack=lambda b: 5)
def test_zero_digest_history(self): session = ss.Session(digest_history_size=0) for i in range(11): session._add_digest(uuid.uuid4().bytes) self.assertEqual(len(session.digest_history), 0)
def test_datetimes_msgpack(self): session = ss.Session(packer='msgpack.packb', unpacker='msgpack.unpackb') self._datetime_test(session)