Skip to content

Commit

Permalink
playback: Music of unknown audio formats are rejected
Browse files Browse the repository at this point in the history
  • Loading branch information
jodal committed Sep 17, 2014
1 parent 7f1b7a7 commit bff2a15
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mopidy_spotify/playback.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def music_delivery_callback(
if not push_audio_data_event.is_set():
return 0

known_format = (
audio_format.sample_type == spotify.SampleType.INT16_NATIVE_ENDIAN)
assert known_format, 'Expects 16-bit signed integer samples'

# TODO Implement


Expand Down
19 changes: 19 additions & 0 deletions tests/test_playback.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,25 @@ def test_music_delivery_rejects_data_depending_on_push_audio_data_event(
assert result == 0


def test_music_delivery_rejects_unknown_audio_formats(
session_mock, audio_mock):

audio_format = mock.Mock()
audio_format.sample_type = 17
frames = b''
num_frames = 0
push_audio_data_event = threading.Event()
push_audio_data_event.set()
buffer_timestamp = mock.Mock()

with pytest.raises(AssertionError) as excinfo:
playback.music_delivery_callback(
session_mock, audio_format, frames, num_frames,
audio_mock, push_audio_data_event, buffer_timestamp)

assert 'Expects 16-bit signed integer samples' in str(excinfo.value)


def test_end_of_track_callback(session_mock, audio_mock):
playback.end_of_track_callback(session_mock, audio_mock)

Expand Down

0 comments on commit bff2a15

Please sign in to comment.