Пример #1
0
    def test_connect_will_not_instantinate_socket_twice(self):
        self.setUpConnect()

        z = Zmq(context=self.ctx)
        self.assertTrue(isinstance(z.connect(), Zmq))
        self.assertTrue(isinstance(z.connect(), Zmq))
        self.ctx.socket.assert_called_once_with(IsA(int))
        self.socket.connect.assert_called_once_with(IsA(str))
Пример #2
0
    def test_serve_will_not_initialize_already_initialized_socket(self):
        self.setUpConnect()

        z = Zmq(context=self.ctx)
        z.connect()
        self.assertTrue(z.serve() is None)
        self.socket.connect.assert_called_once_with(IsA(str))
        self.assertEqual(self.socket.bind.call_count, 0)
Пример #3
0
    def test_serve_expects_zmq_messages_consisted_on_2_parts(self):
        self.setUpBind()
        c = mock.MagicMock(return_value=self.deferred)

        self.socket.recv = mock.MagicMock(side_effect=results('route', 'msg'))
        self.deferred.done = mock.MagicMock(side_effect=KeyboardInterrupt)
        z = Zmq(context=self.ctx)
        z.attach_listener('route', c)
        self.assertRaises(KeyboardInterrupt, z.serve)

        c.assert_called_once_with(IsA(str))
Пример #4
0
    def test_serve_expects_deferred_instance_returned_from_handler(self):
        self.setUpBind()
        c = mock.MagicMock(return_value=self.deferred)

        self.socket.recv = mock.MagicMock(side_effect=results('route', 'msg',
                KeyboardInterrupt()))

        z = Zmq(context=self.ctx)
        z.attach_listener('route', c)
        self.assertRaises(KeyboardInterrupt, z.serve)

        c.assert_called_once_with(IsA(str))
        self.deferred.done.assert_called_once_with(IsCallable())