diff options
author | Marius Gedminas <marius@gedmin.as> | 2016-02-04 19:56:51 +0200 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2016-04-24 13:56:42 -0700 |
commit | e1d09fe4b0f4ab8eee5e923dd63ae08155334e80 (patch) | |
tree | 5322746c8c96d9098e76ea4232d36bbefe42c2f9 | |
parent | f15b383e4499e85689bfcc83dc942f0b6c898264 (diff) |
Make NoValidConnectionsError picklable correctly
Fixes #617.
-rw-r--r-- | paramiko/ssh_exception.py | 3 | ||||
-rwxr-xr-x | test.py | 4 | ||||
-rw-r--r-- | tests/test_ssh_exception.py | 15 |
3 files changed, 21 insertions, 1 deletions
diff --git a/paramiko/ssh_exception.py b/paramiko/ssh_exception.py index 016a411e..b61000ae 100644 --- a/paramiko/ssh_exception.py +++ b/paramiko/ssh_exception.py @@ -173,3 +173,6 @@ class NoValidConnectionsError(socket.error): msg.format(addrs[0][1], body, tail) ) self.errors = errors + + def __reduce__(self): + return (NoValidConnectionsError, (self.errors, )) @@ -43,8 +43,9 @@ from tests.test_kex import KexTest from tests.test_packetizer import PacketizerTest from tests.test_auth import AuthTest from tests.test_transport import TransportTest +from tests.test_ssh_exception import NoValidConnectionsErrorTest from tests.test_client import SSHClientTest -from test_client import SSHClientTest +from test_client import SSHClientTest # XXX why shadow the above import? from test_gssapi import GSSAPITest from test_ssh_gss import GSSAuthTest from test_kex_gss import GSSKexTest @@ -156,6 +157,7 @@ def main(): if options.use_transport: suite.addTest(unittest.makeSuite(AuthTest)) suite.addTest(unittest.makeSuite(TransportTest)) + suite.addTest(unittest.makeSuite(NoValidConnectionsErrorTest)) suite.addTest(unittest.makeSuite(SSHClientTest)) if options.use_sftp: suite.addTest(unittest.makeSuite(SFTPTest)) diff --git a/tests/test_ssh_exception.py b/tests/test_ssh_exception.py new file mode 100644 index 00000000..2d1f899f --- /dev/null +++ b/tests/test_ssh_exception.py @@ -0,0 +1,15 @@ +import pickle +import unittest + +from paramiko.ssh_exception import NoValidConnectionsError + + +class NoValidConnectionsErrorTest (unittest.TestCase): + + def test_pickling(self): + # Regression test for https://github.com/paramiko/paramiko/issues/617 + exc = NoValidConnectionsError({'ab': ''}) + new_exc = pickle.loads(pickle.dumps(exc)) + self.assertEqual(type(exc), type(new_exc)) + self.assertEqual(str(exc), str(new_exc)) + self.assertEqual(exc.args, new_exc.args) |