Skip to content

Commit

Permalink
Fix/dummy audio mopidy 3.4.0 (#58)
Browse files Browse the repository at this point in the history
* tests: Update dummy audio layer to match Mopidy 3.4.0

Updated to match DummyAudio from Mopidy

* Also latest linting fixes
  • Loading branch information
kingosticks committed Feb 16, 2023
1 parent 1f5c021 commit 8cbb441
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
1 change: 0 additions & 1 deletion mopidy_mpd/__init__.py
Expand Up @@ -8,7 +8,6 @@


class Extension(ext.Extension):

dist_name = "Mopidy-MPD"
ext_name = "mpd"
version = __version__
Expand Down
6 changes: 3 additions & 3 deletions mopidy_mpd/network.py
Expand Up @@ -46,7 +46,7 @@ def get_socket_address(host, port):
return (host, port)


class ShouldRetrySocketCall(Exception):
class ShouldRetrySocketCallError(Exception):

"""Indicate that attempted socket call should be retried"""

Expand Down Expand Up @@ -170,7 +170,7 @@ def register_server_socket(self, fileno):
def handle_connection(self, fd, flags):
try:
sock, addr = self.accept_connection()
except ShouldRetrySocketCall:
except ShouldRetrySocketCallError:
return True

if self.maximum_connections_exceeded():
Expand All @@ -187,7 +187,7 @@ def accept_connection(self):
return sock, addr
except OSError as e:
if e.errno in (errno.EAGAIN, errno.EINTR):
raise ShouldRetrySocketCall
raise ShouldRetrySocketCallError
raise

def maximum_connections_exceeded(self):
Expand Down
4 changes: 2 additions & 2 deletions mopidy_mpd/protocol/current_playlist.py
Expand Up @@ -93,7 +93,7 @@ def delete(context, songrange):
tl_tracks = context.core.tracklist.slice(start, end).get()
if not tl_tracks:
raise exceptions.MpdArgError("Bad song index", command="delete")
for (tlid, _) in tl_tracks:
for tlid, _ in tl_tracks:
context.core.tracklist.remove({"tlid": [tlid]})


Expand Down Expand Up @@ -325,7 +325,7 @@ def plchangesposid(context, version):
# XXX Naive implementation that returns all tracks as changed
if int(version) != context.core.tracklist.get_version().get():
result = []
for (position, (tlid, _)) in enumerate(
for position, (tlid, _) in enumerate(
context.core.tracklist.get_tl_tracks().get()
):
result.append(("cpos", position))
Expand Down
29 changes: 21 additions & 8 deletions tests/dummy_audio.py
Expand Up @@ -21,7 +21,8 @@ def __init__(self, config=None, mixer=None):
self.state = audio.PlaybackState.STOPPED
self._volume = 0
self._position = 0
self._callback = None
self._source_setup_callback = None
self._about_to_finish_callback = None
self._uri = None
self._stream_changed = False
self._live_stream = False
Expand Down Expand Up @@ -58,6 +59,7 @@ def pause_playback(self):

def prepare_change(self):
self._uri = None
self._source_setup_callback = None
return True

def stop_playback(self):
Expand All @@ -76,8 +78,11 @@ def set_metadata(self, track):
def get_current_tags(self):
return self._tags

def set_source_setup_callback(self, callback):
self._source_setup_callback = callback

def set_about_to_finish_callback(self, callback):
self._callback = callback
self._about_to_finish_callback = callback

def enable_sync_handler(self):
pass
Expand All @@ -93,13 +98,13 @@ def _change_state(self, new_state):
self._stream_changed = True
self._uri = None

if self._uri is not None:
audio.AudioListener.send("position_changed", position=0)

if self._stream_changed:
self._stream_changed = False
audio.AudioListener.send("stream_changed", uri=self._uri)

if self._uri is not None:
audio.AudioListener.send("position_changed", position=0)

old_state, self.state = self.state, new_state
audio.AudioListener.send(
"state_changed",
Expand All @@ -121,14 +126,22 @@ def trigger_fake_tags_changed(self, tags):
self._tags.update(tags)
audio.AudioListener.send("tags_changed", tags=self._tags.keys())

def get_source_setup_callback(self):
# This needs to be called from outside the actor or we lock up.
def wrapper():
if self._source_setup_callback:
self._source_setup_callback()

return wrapper

def get_about_to_finish_callback(self):
# This needs to be called from outside the actor or we lock up.
def wrapper():
if self._callback:
if self._about_to_finish_callback:
self.prepare_change()
self._callback()
self._about_to_finish_callback()

if not self._uri or not self._callback:
if not self._uri or not self._about_to_finish_callback:
self._tags = {}
audio.AudioListener.send("reached_end_of_stream")
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/network/test_server.py
Expand Up @@ -250,7 +250,7 @@ def test_accept_connection_recoverable_error(self):

for error in (errno.EAGAIN, errno.EINTR):
sock.accept.side_effect = socket.error(error, "")
with self.assertRaises(network.ShouldRetrySocketCall):
with self.assertRaises(network.ShouldRetrySocketCallError):
network.Server.accept_connection(self.mock)

# FIXME decide if this should be allowed to propegate
Expand Down
1 change: 0 additions & 1 deletion tests/protocol/test_regression.py
Expand Up @@ -169,7 +169,6 @@ def test(self):


class IssueGH113RegressionTest(protocol.BaseTestCase):

r"""
The issue: https://github.com/mopidy/mopidy/issues/113
Expand Down

0 comments on commit 8cbb441

Please sign in to comment.