[Pkg-mpd-commits] [python-mpd] 106/262: more readable exception handling _connect_tcp()

Simon McVittie smcv at debian.org
Sun May 22 18:16:31 UTC 2016


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch upstream
in repository python-mpd.

commit da8cb1ae4610c848047dc91856aa25c29d8c6b16
Author: Jörg Thalheim <jthalheim at gmail.com>
Date:   Sun Mar 18 18:09:51 2012 +0100

    more readable exception handling _connect_tcp()
---
 mpd.py  | 4 ++--
 test.py | 8 +++++++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/mpd.py b/mpd.py
index 6995bb2..0205f88 100644
--- a/mpd.py
+++ b/mpd.py
@@ -394,11 +394,11 @@ class MPDClient():
                 err = e
                 if sock is not None:
                     sock.close()
-        if err is not None:
-            raise err
         else:
             raise ConnectionError("getaddrinfo returns an empty list")
 
+        raise err
+
     def connect(self, host, port):
         if self._sock is not None:
             raise ConnectionError("Already connected")
diff --git a/test.py b/test.py
index 1434e09..5ff9ee5 100755
--- a/test.py
+++ b/test.py
@@ -32,7 +32,7 @@ class TestMPDClient(unittest.TestCase):
         try:
             self.client.connect(MPD_HOST, MPD_PORT)
             self.idleclient.connect(MPD_HOST, MPD_PORT)
-        except SocketError as e:
+        except (ConnectionError, SocketError) as e:
             raise Exception("Can't connect mpd! Start it or check the configuration: %s" % e)
         if MPD_PASSW != None:
             try:
@@ -128,5 +128,11 @@ class TestMPDClient(unittest.TestCase):
         channels = self.client.channels()
         self.assertNotIn("monty", channels)
 
+    def test_connection_error(self):
+        client2 = MPDClient()
+        with self.assertRaises(ConnectionError) as cm:
+            # should never return getaddrinfo
+            client2.connect("255.255.255.255", 6600)
+
 if __name__ == '__main__':
     unittest.main()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mpd/python-mpd.git



More information about the Pkg-mpd-commits mailing list