[Pkg-mpd-commits] [python-mpd] 128/262: test: mpd connection info from enviroment variable
Simon McVittie
smcv at debian.org
Sun May 22 18:16:36 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 966bf485340b0e316a9fd22edcb42b9db309f65f
Author: Jonathan Ballet <jon at multani.info>
Date: Fri Mar 30 21:45:18 2012 +0200
test: mpd connection info from enviroment variable
TEST_MPD_HOST - the server to connect to (default: localhost)
TEST_MPD_PORT - the port used (have to be set)
TEST_MPD_PASSWORD - the password to authenticate (default: no)
---
test.py | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/test.py b/test.py
index c417f49..862e398 100755
--- a/test.py
+++ b/test.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+import os
import types
import sys
from socket import error as SocketError
@@ -19,27 +20,40 @@ except ImportError:
print("Please install unittest2 from pypi to run tests!")
sys.exit(1)
-# Alternate this to your setup
-# Make sure you have at least one song on your playlist
-MPD_HOST = "localhost"
-MPD_PORT = 6600
-MPD_PASSW = None
+def setup_environment():
+ # Alternate this to your setup
+ # Make sure you have at least one song on your playlist
+ global TEST_MPD_HOST, TEST_MPD_PORT, TEST_MPD_PASSWORD
+
+ if 'TEST_MPD_PORT' not in os.environ:
+ sys.stderr.write(
+ "You should set the TEST_MPD_PORT environment variable to point "
+ "to your test MPD running instance.\n")
+ sys.exit(255)
+
+ TEST_MPD_HOST = os.environ.get('TEST_MPD_HOST', "localhost")
+ TEST_MPD_PORT = int(os.environ['TEST_MPD_PORT'])
+ TEST_MPD_PASSWORD = os.environ.get('TEST_MPD_PASSWORD')
+
+setup_environment()
+
class TestMPDClient(unittest.TestCase):
@classmethod
def setUpClass(self):
+ global TEST_MPD_HOST, TEST_MPD_PORT, TEST_MPD_PASSWORD
self.client = mpd.MPDClient()
self.idleclient = mpd.MPDClient()
try:
- self.client.connect(MPD_HOST, MPD_PORT)
- self.idleclient.connect(MPD_HOST, MPD_PORT)
+ self.client.connect(TEST_MPD_HOST, TEST_MPD_PORT)
+ self.idleclient.connect(TEST_MPD_HOST, TEST_MPD_PORT)
self.commands = self.client.commands()
except SocketError as e:
raise Exception("Can't connect mpd! Start it or check the configuration: %s" % e)
- if MPD_PASSW != None:
+ if TEST_MPD_PASSWORD != None:
try:
- self.client.password(MPD_PASSW)
- self.idleclient.password(MPD_PASSW)
+ self.client.password(TEST_MPD_PASSWORD)
+ self.idleclient.password(TEST_MPD_PASSWORD)
except mpd.CommandError as e:
raise Exception("Fail to authenticate to mpd.")
@classmethod
--
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