| 12 | |
| 13 | |
| 14 | class _DummySocket(object): |
| 15 | def __init__(self): |
| 16 | self._sock_for_reader_thread = None |
| 17 | self._sock_for_fixture_test = None |
| 18 | self._socket_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 19 | self._localhost = host = pydev_localhost.get_localhost() |
| 20 | self._socket_server.bind((host, 0)) |
| 21 | self._socket_server.listen(1) |
| 22 | |
| 23 | def recv(self, *args, **kwargs): |
| 24 | if self._sock_for_reader_thread is None: |
| 25 | sock, _addr = self._socket_server.accept() |
| 26 | self._sock_for_reader_thread = sock |
| 27 | return self._sock_for_reader_thread.recv(*args, **kwargs) |
| 28 | |
| 29 | def put(self, msg): |
| 30 | if not isinstance(msg, bytes): |
| 31 | msg = msg.encode("utf-8") |
| 32 | |
| 33 | if self._sock_for_fixture_test is None: |
| 34 | self._sock_for_fixture_test = start_client(*self._socket_server.getsockname()) |
| 35 | |
| 36 | self._sock_for_fixture_test.sendall(msg) |
| 37 | |
| 38 | def close(self): |
| 39 | self._socket_server.close() |
| 40 | |
| 41 | if self._sock_for_fixture_test is not None: |
| 42 | self._sock_for_fixture_test.close() |
| 43 | |
| 44 | if self._sock_for_reader_thread is not None: |
| 45 | self._sock_for_reader_thread.close() |
| 46 | |
| 47 | |
| 48 | @pytest.yield_fixture |
no outgoing calls