# HG changeset patch # User Amine Sehili # Date 1549309048 -3600 # Node ID aa0e5535f7243f64dd73964a8a010e0d17bcdafd # Parent efd8f4606cf49957ebd66ae8d939c2691614f5ee Add tests for from_file with compressed audio data and channel mixing diff -r efd8f4606cf4 -r aa0e5535f724 tests/test_io.py --- a/tests/test_io.py Sun Feb 03 16:04:24 2019 +0100 +++ b/tests/test_io.py Mon Feb 04 20:37:28 2019 +0100 @@ -331,6 +331,34 @@ self.assertTrue(open_func.called) self.assertFalse(ext_mock.called) + @patch("auditok.io._WITH_PYDUB", True) + @patch("auditok.io.BufferAudioSource") + @genty_dataset( + ogg=("ogg", "from_ogg"), + mp3=("mp3", "from_mp3"), + flac=("flac", "from_file"), + ) + def test_from_file_multichannel_audio_mix_compressed( + self, audio_format, function, *mocks + ): + filename = "audio.{}".format(audio_format) + segment_mock = Mock() + segment_mock.sample_width = 2 + segment_mock.channels = 2 + segment_mock._data = b"abcd" + with patch("auditok.io._mix_audio_channels") as mix_mock: + with patch( + "auditok.io.AudioSegment.{}".format(function) + ) as open_func: + open_func.return_value = segment_mock + from_file(filename, use_channel="mix") + self.assertTrue(open_func.called) + mix_mock.assert_called_with( + segment_mock._data, + segment_mock.channels, + segment_mock.sample_width, + ) + @genty_dataset( mono=("mono_400Hz.wav", (400,)), three_channel=("3channel_400-800-1600Hz.wav", (400, 800, 1600)),