diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2022-06-03 19:55:51 -0400 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2022-06-03 19:55:51 -0400 |
commit | 0f3beefa5618ca46ea880eca696dca488fcc2bb6 (patch) | |
tree | aae2a285cc2821c7e2b042bf28e2d2a08f0b74d5 /tests | |
parent | 00fce050cb33fb5ec1f13811c1ad8188cf11645d (diff) | |
parent | 92920c113740d768ccb311b103fdd744389304b1 (diff) |
Merge branch '2.10' into 2.11
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_client.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/test_client.py b/tests/test_client.py index 3db4cd22..fd54140b 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -33,6 +33,7 @@ import warnings import weakref from tempfile import mkstemp +import pytest from pytest_relaxed import raises from mock import patch, Mock @@ -473,6 +474,23 @@ class SSHClientTest(ClientTest): assert p() is None + @patch("paramiko.client.socket.socket") + @patch("paramiko.client.socket.getaddrinfo") + def test_closes_socket_on_socket_errors(self, getaddrinfo, mocket): + getaddrinfo.return_value = ( + ("irrelevant", None, None, None, "whatever"), + ) + + class SocksToBeYou(socket.error): + pass + + my_socket = mocket.return_value + my_socket.connect.side_effect = SocksToBeYou + client = SSHClient() + with pytest.raises(SocksToBeYou): + client.connect(hostname="nope") + my_socket.close.assert_called_once_with() + def test_client_can_be_used_as_context_manager(self): """ verify that an SSHClient can be used a context manager |