Exemplo n.º 1
0
    def test_proto_type_switch(self):
        self.protocol = test_utils.make_test_protocol(asyncio.Protocol)
        tr = self.socket_transport()

        res = asyncio.Future(loop=self.loop)
        res.set_result(b'data')

        tr = self.socket_transport()
        tr._read_fut = res
        tr._loop_reading(res)
        self.loop._proactor.recv.assert_called_with(self.sock, 32768)
        self.protocol.data_received.assert_called_with(b'data')

        # switch protocol to a BufferedProtocol

        buf_proto = test_utils.make_test_protocol(asyncio.BufferedProtocol)
        buf = bytearray(4)
        buf_proto.get_buffer.side_effect = lambda hint: buf

        tr.set_protocol(buf_proto)
        test_utils.run_briefly(self.loop)
        res = asyncio.Future(loop=self.loop)
        res.set_result(4)

        tr._read_fut = res
        tr._loop_reading(res)
        self.loop._proactor.recv_into.assert_called_with(self.sock, buf)
        buf_proto.buffer_updated.assert_called_with(4)
Exemplo n.º 2
0
    def test_proto_type_switch(self):
        self.protocol = test_utils.make_test_protocol(asyncio.Protocol)
        tr = self.socket_transport()

        res = asyncio.Future(loop=self.loop)
        res.set_result(b'data')

        tr = self.socket_transport()
        tr._read_fut = res
        tr._loop_reading(res)
        self.loop._proactor.recv.assert_called_with(self.sock, 32768)
        self.protocol.data_received.assert_called_with(b'data')

        # switch protocol to a BufferedProtocol

        buf_proto = test_utils.make_test_protocol(asyncio.BufferedProtocol)
        buf = bytearray(4)
        buf_proto.get_buffer.side_effect = lambda hint: buf

        tr.set_protocol(buf_proto)
        test_utils.run_briefly(self.loop)
        res = asyncio.Future(loop=self.loop)
        res.set_result(4)

        tr._read_fut = res
        tr._loop_reading(res)
        self.loop._proactor.recv_into.assert_called_with(self.sock, buf)
        buf_proto.buffer_updated.assert_called_with(4)
Exemplo n.º 3
0
 def setUp(self):
     super().setUp()
     self.loop = self.new_test_loop()
     self.addCleanup(self.loop.close)
     self.proactor = mock.Mock()
     self.loop._proactor = self.proactor
     self.protocol = test_utils.make_test_protocol(asyncio.Protocol)
     self.sock = mock.Mock(socket.socket)
Exemplo n.º 4
0
 def setUp(self):
     super().setUp()
     self.loop = self.new_test_loop()
     self.proactor = mock.Mock()
     self.loop._proactor = self.proactor
     self.protocol = test_utils.make_test_protocol(asyncio.DatagramProtocol)
     self.sock = mock.Mock(spec_set=socket.socket)
     self.sock.fileno.return_value = 7
Exemplo n.º 5
0
 def setUp(self):
     super().setUp()
     self.loop = self.new_test_loop()
     self.addCleanup(self.loop.close)
     self.proactor = mock.Mock()
     self.loop._proactor = self.proactor
     self.protocol = test_utils.make_test_protocol(asyncio.Protocol)
     self.sock = mock.Mock(socket.socket)
Exemplo n.º 6
0
    def setUp(self):
        super().setUp()
        self.loop = self.new_test_loop()

        self.protocol = test_utils.make_test_protocol(asyncio.BufferedProtocol)
        self.buf = bytearray(1)
        self.protocol.get_buffer.side_effect = lambda hint: self.buf

        self.sock = mock.Mock(socket.socket)
        self.sock_fd = self.sock.fileno.return_value = 7
Exemplo n.º 7
0
    def setUp(self):
        super().setUp()
        self.loop = self.new_test_loop()

        self.protocol = test_utils.make_test_protocol(asyncio.BufferedProtocol)
        self.buf = bytearray(1)
        self.protocol.get_buffer.side_effect = lambda hint: self.buf

        self.sock = mock.Mock(socket.socket)
        self.sock_fd = self.sock.fileno.return_value = 7
Exemplo n.º 8
0
    def setUp(self):
        super().setUp()
        self.loop = self.new_test_loop()
        self.addCleanup(self.loop.close)
        self.proactor = mock.Mock()
        self.loop._proactor = self.proactor

        self.protocol = test_utils.make_test_protocol(asyncio.BufferedProtocol)
        self.buf = mock.Mock()
        self.protocol.get_buffer.side_effect = lambda: self.buf

        self.sock = mock.Mock(socket.socket)
Exemplo n.º 9
0
    def setUp(self):
        super().setUp()
        self.loop = self.new_test_loop()
        self.addCleanup(self.loop.close)
        self.proactor = mock.Mock()
        self.loop._proactor = self.proactor

        self.protocol = test_utils.make_test_protocol(asyncio.BufferedProtocol)
        self.buf = bytearray(1)
        self.protocol.get_buffer.side_effect = lambda hint: self.buf

        self.sock = mock.Mock(socket.socket)
Exemplo n.º 10
0
    def test_proto_type_switch(self):
        self.protocol = test_utils.make_test_protocol(asyncio.Protocol)
        transport = self.socket_transport()

        self.sock.recv.return_value = b'data'
        transport._read_ready()

        self.protocol.data_received.assert_called_with(b'data')

        # switch protocol to a BufferedProtocol

        buf_proto = test_utils.make_test_protocol(asyncio.BufferedProtocol)
        buf = bytearray(4)
        buf_proto.get_buffer.side_effect = lambda hint: buf

        transport.set_protocol(buf_proto)

        self.sock.recv_into.return_value = 10
        transport._read_ready()

        buf_proto.get_buffer.assert_called_with(-1)
        buf_proto.buffer_updated.assert_called_with(10)
Exemplo n.º 11
0
    def test_proto_type_switch(self):
        self.protocol = test_utils.make_test_protocol(asyncio.Protocol)
        transport = self.socket_transport()

        self.sock.recv.return_value = b'data'
        transport._read_ready()

        self.protocol.data_received.assert_called_with(b'data')

        # switch protocol to a BufferedProtocol

        buf_proto = test_utils.make_test_protocol(asyncio.BufferedProtocol)
        buf = bytearray(4)
        buf_proto.get_buffer.side_effect = lambda hint: buf

        transport.set_protocol(buf_proto)

        self.sock.recv_into.return_value = 10
        transport._read_ready()

        buf_proto.get_buffer.assert_called_with(-1)
        buf_proto.buffer_updated.assert_called_with(10)
Exemplo n.º 12
0
    def test_proto_buf_switch(self):
        tr = self.socket_transport()
        test_utils.run_briefly(self.loop)
        self.protocol.get_buffer.assert_called_with(-1)

        # switch protocol to *another* BufferedProtocol

        buf_proto = test_utils.make_test_protocol(asyncio.BufferedProtocol)
        buf = bytearray(4)
        buf_proto.get_buffer.side_effect = lambda hint: buf
        tr._read_fut.done.side_effect = lambda: False
        tr.set_protocol(buf_proto)
        self.assertFalse(buf_proto.get_buffer.called)
        test_utils.run_briefly(self.loop)
        buf_proto.get_buffer.assert_called_with(-1)
Exemplo n.º 13
0
    def test_proto_buf_switch(self):
        tr = self.socket_transport()
        test_utils.run_briefly(self.loop)
        self.protocol.get_buffer.assert_called_with(-1)

        # switch protocol to *another* BufferedProtocol

        buf_proto = test_utils.make_test_protocol(asyncio.BufferedProtocol)
        buf = bytearray(4)
        buf_proto.get_buffer.side_effect = lambda hint: buf
        tr._read_fut.done.side_effect = lambda: False
        tr.set_protocol(buf_proto)
        self.assertFalse(buf_proto.get_buffer.called)
        test_utils.run_briefly(self.loop)
        buf_proto.get_buffer.assert_called_with(-1)
Exemplo n.º 14
0
 def datagram_transport(self):
     self.protocol = test_utils.make_test_protocol(asyncio.DatagramProtocol)
     return self.loop._make_datagram_transport(self.sock, self.protocol)
Exemplo n.º 15
0
 def setUp(self):
     super().setUp()
     self.loop = self.new_test_loop()
     self.protocol = test_utils.make_test_protocol(asyncio.Protocol)
     self.sock = mock.Mock(socket.socket)
     self.sock_fd = self.sock.fileno.return_value = 7
Exemplo n.º 16
0
 def setUp(self):
     super().setUp()
     self.loop = self.new_test_loop()
     self.protocol = test_utils.make_test_protocol(asyncio.Protocol)
     self.sock = mock.Mock(socket.socket)
     self.sock_fd = self.sock.fileno.return_value = 7