[Pkg-mpd-commits] [python-mpd] 202/262: Handle specific noidle command.

Simon McVittie smcv at debian.org
Sun May 22 18:16:47 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 aef2aa1941dda2d4643721b895de456ea162eba5
Author: François de Metz <francois at 2metz.fr>
Date:   Tue Apr 9 23:04:46 2013 +0200

    Handle specific noidle command.
    
    Signed-off-by: François de Metz <francois at stormz.me>
---
 mpd.py  | 13 ++++++++++++-
 test.py | 22 +++++++++++++++++++++-
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/mpd.py b/mpd.py
index a7fd522..4ebb18e 100644
--- a/mpd.py
+++ b/mpd.py
@@ -79,7 +79,6 @@ _commands = {
     "clearerror":         "_fetch_nothing",
     "currentsong":        "_fetch_object",
     "idle":               "_fetch_idle",
-    "noidle":             None,
     "status":             "_fetch_object",
     "stats":              "_fetch_object",
     # Playback Option Commands
@@ -411,6 +410,18 @@ class MPDClient(object):
     def _fetch_command_list(self):
         return self._wrap_iterator(self._read_command_list())
 
+    def noidle(self):
+        if not self._pending or self._pending[0] != 'idle':
+          raise CommandError('cannot send noidle if send_idle was not called')
+        del self._pending[0]
+        self._write_command("noidle")
+        status = self._read_line()
+        # In some case mpd has already write the changed line
+        if status is not None:
+            # So we need to fetch the result of the noidle
+            self._fetch_nothing()
+        return None
+
     def _hello(self):
         line = self._rfile.readline()
         if not line.endswith("\n"):
diff --git a/test.py b/test.py
index 5b091f0..3d6d894 100755
--- a/test.py
+++ b/test.py
@@ -170,7 +170,27 @@ class TestMPDClient(unittest.TestCase):
     def test_noidle(self):
         self.MPDWillReturn('OK\n') # nothing changed after idle-ing
         self.client.send_idle()
-        self.client.noidle()
+        self.MPDWillReturn('OK\n') # nothing changed after noidle
+        self.assertIsNone(self.client.noidle())
+        self.assertMPDReceived('noidle\n')
+        self.MPDWillReturn("volume: 50\n", "OK\n")
+        self.client.status()
+        self.assertMPDReceived('status\n')
+
+    def test_noidle_while_idle_started_sending(self):
+        self.MPDWillReturn('OK\n') # nothing changed after idle-ing
+        self.client.send_idle()
+        self.MPDWillReturn('CHANGED: player\n') # started to change
+        self.MPDWillReturn('OK\n') # noidle response
+        self.assertIsNone(self.client.noidle())
+        self.MPDWillReturn("volume: 50\n", "OK\n")
+        status = self.client.status()
+        self.assertEqual({'volume': '50'}, status)
+
+    def test_throw_when_calling_noidle_withoutidling(self):
+        self.assertRaises(mpd.CommandError, self.client.noidle)
+        self.client.send_status()
+        self.assertRaises(mpd.CommandError, self.client.noidle)
 
     def test_add_and_remove_command(self):
         self.MPDWillReturn("ACK awesome command\n")

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