Fix Transport, DatagramTransport mockup issues.

This commit is contained in:
Jonathan Moody 2022-06-16 12:37:00 -04:00 committed by Lex Berezhny
parent 7a86406746
commit ea4fba39a6

View file

@ -61,16 +61,14 @@ def mock_network_loop(loop: asyncio.AbstractEventLoop,
dht_network[from_addr] = protocol dht_network[from_addr] = protocol
return transport, protocol return transport, protocol
with mock.patch('socket.socket') as mock_socket: mock_sock = mock.Mock(spec=socket.socket)
mock_sock = mock.Mock(spec=socket.socket) mock_sock.setsockopt = lambda *_: None
mock_sock.setsockopt = lambda *_: None mock_sock.bind = lambda *_: None
mock_sock.bind = lambda *_: None mock_sock.setblocking = lambda *_: None
mock_sock.setblocking = lambda *_: None mock_sock.getsockname = lambda: "0.0.0.0"
mock_sock.getsockname = lambda: "0.0.0.0" mock_sock.getpeername = lambda: ""
mock_sock.getpeername = lambda: "" mock_sock.close = lambda: None
mock_sock.close = lambda: None mock_sock.type = socket.SOCK_DGRAM
mock_sock.type = socket.SOCK_DGRAM mock_sock.fileno = lambda: 7
mock_sock.fileno = lambda: 7 loop.create_datagram_endpoint = create_datagram_endpoint
mock_socket.return_value = mock_sock yield
loop.create_datagram_endpoint = create_datagram_endpoint
yield