[Pkg-mpd-commits] [python-mpd] 93/262: test.py readable errors, if no server and password

Simon McVittie smcv at debian.org
Sun May 22 18:16:29 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 cb8938ea3d7712a6ee1f4a06628c69cb74698a38
Author: Jörg Thalheim <jthalheim at gmail.com>
Date:   Wed Feb 15 00:20:47 2012 +0100

    test.py readable errors, if no server and password
---
 test.py | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/test.py b/test.py
index 1486ff7..8bb91ae 100755
--- a/test.py
+++ b/test.py
@@ -1,20 +1,32 @@
 #!/usr/bin/env python
 import unittest
 import types
-from mpd import MPDClient, CommandError
+from socket import error as SocketError
+import sys
+from mpd import MPDClient, CommandError, ConnectionError
 
 # Alternate this to your setup
 # Make sure you have at least one song on your playlist
-MPD_HOST = "localhost"
-MPD_PORT = 6600
+MPD_HOST  = "localhost"
+MPD_PORT  = 6600
+MPD_PASSW = None
 
 class TestMPDClient(unittest.TestCase):
     @classmethod
     def setUpClass(self):
         self.client = MPDClient()
         self.idleclient = MPDClient()
-        self.client.connect(MPD_HOST, MPD_PORT)
-        self.idleclient.connect(MPD_HOST, MPD_PORT)
+        try:
+            self.client.connect(MPD_HOST, MPD_PORT)
+            self.idleclient.connect(MPD_HOST, MPD_PORT)
+        except SocketError as e:
+            raise Exception("Can't connect mpd! Start it or check the configuration: %s" % e)
+        if MPD_PASSW != None:
+            try:
+                self.client.password(MPD_PASSW)
+                self.idleclient.password(MPD_PASSW)
+            except CommandError as e:
+                raise Exception("Fail to authenticate to mpd.")
     @classmethod
     def tearDownClass(self):
         self.client.disconnect()

-- 
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