diff --git a/mopidy/audio/utils.py b/mopidy/audio/utils.py index 0f7f1957..a8627001 100644 --- a/mopidy/audio/utils.py +++ b/mopidy/audio/utils.py @@ -28,6 +28,9 @@ def create_buffer(data, capabilites=None, timestamp=None, duration=None): .. versionchanged:: 1.2 ``capabilites`` argument is no longer in use """ + if not data: + raise ValueError( + 'Cannot create buffer without data: length=%d' % len(data)) buffer_ = Gst.Buffer.new_wrapped(data) if timestamp is not None: buffer_.pts = timestamp diff --git a/tests/audio/test_utils.py b/tests/audio/test_utils.py index d3e81ef2..e10613d2 100644 --- a/tests/audio/test_utils.py +++ b/tests/audio/test_utils.py @@ -23,6 +23,12 @@ class TestCreateBuffer(object): assert buf.duration == 1000000 assert buf.get_size() == len(b'123') + def test_fails_if_data_has_zero_length(self): + with pytest.raises(ValueError) as excinfo: + utils.create_buffer(b'', timestamp=0, duration=1000000) + + assert 'Cannot create buffer without data' in str(excinfo.value) + # TODO: keep ids without name? # TODO: current test is trying to test everything at once with a complete tags