def test_open_and_close(self, mock_socket): mock_socket_ins = Mock() mock_socket.create_connection.return_value = mock_socket_ins client = RPCClient(HOST, PORT) ok_(client.is_connected()) mock_socket.create_connection.assert_called_once_with((HOST, PORT)) client.close() ok_(mock_socket_ins.close.called) ok_(not client.is_connected())
def test_open_and_close_unix_socket(self, mock_socket): mock_socket_ins = Mock() mock_socket.socket.return_value = mock_socket_ins client = RPCClient(unix_socket_path=UNIX_SOCK_PATH) mock_socket.socket.assert_called_once_with(mock_socket.AF_UNIX, mock_socket.SOCK_STREAM) ok_(client.is_connected()) mock_socket_ins.connect.assert_called_once_with(UNIX_SOCK_PATH) client.close() ok_(mock_socket_ins.close.called) ok_(not client.is_connected())
def test_open_with_timeout(self, mock_socket): mock_socket_ins = Mock() mock_socket.create_connection.return_value = mock_socket_ins client = RPCClient(HOST, PORT, timeout=5.0) mock_socket_ins.settimeout.assert_called_once_with(5.0) ok_(client.is_connected())
def test_open_unix_socket_with_timeout(self, mock_socket): mock_socket_ins = Mock() mock_socket.socket.return_value = mock_socket_ins client = RPCClient(unix_socket_path=UNIX_SOCK_PATH, timeout=5.0) mock_socket_ins.settimeout.assert_called_once_with(5.0) ok_(client.is_connected())