chiark / gitweb /
disorder.py:
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 2 Dec 2007 15:13:33 +0000 (15:13 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 2 Dec 2007 15:13:33 +0000 (15:13 +0000)
 - dictionary keys in disorder.py are always strings (not unicode strings)
 - the config file is optional
New tests/play.py.

python/disorder.py.in
tests/Makefile.am
tests/play.py [new file with mode: 0755]

index a8afcba9401dfaef6995eeb0755b56edac62808e..95854383f6768912530fa5280f50d3992973994c 100644 (file)
@@ -231,7 +231,7 @@ def _list2dict(l):
     while True:
       k = i.next()
       v = i.next()
-      d[k] = v
+      d[str(k)] = v
   except StopIteration:
     pass
   return d
@@ -294,7 +294,8 @@ class client:
       home = pw.pw_dir
     privconf = _configfile + "." + pw.pw_name
     passfile = home + os.sep + ".disorder" + os.sep + "passwd"
-    self._readfile(_configfile)
+    if os.path.exists(_configfile):
+      self._readfile(_configfile)
     if os.path.exists(privconf):
       self._readfile(privconf)
     if os.path.exists(passfile) and _userconf:
index 56c64be47c922aa795f66b27a8354b44b143905b..c865c582eb36855d3bd225b55b64f216f6d6ad03 100644 (file)
@@ -22,5 +22,4 @@ check:
        ${PYTHON} ${srcdir}/alltests
 
 EXTRA_DIST=alltests dtest.py nothing.py version.py dbversion.py search.py \
-       queue.py dump.py
-
+       queue.py dump.py play.py
diff --git a/tests/play.py b/tests/play.py
new file mode 100755 (executable)
index 0000000..b02ffce
--- /dev/null
@@ -0,0 +1,57 @@
+#! /usr/bin/env python
+#
+# This file is part of DisOrder.
+# Copyright (C) 2007 Richard Kettlewell
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+#
+import dtest,time,disorder,re
+
+def test():
+    """Play some tracks"""
+    dtest.start_daemon()
+    c = disorder.client()
+    track = u"%s/Joe Bloggs/First Album/02:Second track.ogg" % dtest.tracks
+    print "adding track to queue"
+    c.play(track)
+    print "checking track turned up in queue"
+    q = c.queue()
+    ts = filter(lambda t: t['track'] == track and 'submitter' in t, q)
+    assert len(ts) == 1
+    t = ts[0]
+    assert t['submitter'] == u'fred', "check queue submitter"
+    i = t['id']
+    print "waiting for track to play"
+    p = c.playing()
+    while p is None or p['id'] != i:
+        time.sleep(1)
+        p = c.playing()
+    print "waiting for track to finish"
+    p = c.playing()
+    while p is not None and p['id'] == i:
+        time.sleep(1)
+        p = c.playing()
+    print "checking track turned up in recent list"
+    q = c.recent()
+    ts = filter(lambda t: t['track'] == track and 'submitter' in t, q)
+    assert len(ts) == 1
+    t = ts[0]
+    assert t['submitter'] == u'fred', "check recent entry submitter"
+    
+        
+
+if __name__ == '__main__':
+    dtest.run()