# HG changeset patch # User Amine Sehili # Date 1550337926 -3600 # Node ID b5a2da2e61f9ef8fbfe14a7a597f5120369587ad # Parent 01ef241d17e644dce4fa8e2903f949be85577de3 Add test for to_file with compressed audio data diff -r 01ef241d17e6 -r b5a2da2e61f9 auditok/io.py --- a/auditok/io.py Fri Feb 15 21:47:42 2019 +0100 +++ b/auditok/io.py Sat Feb 16 18:25:26 2019 +0100 @@ -961,7 +961,7 @@ _save_wave(data, file, sampling_rate, sample_width, channels) elif _WITH_PYDUB: _save_with_pydub( - file, data, audio_format, sampling_rate, sample_width, channels + data, file, audio_format, sampling_rate, sample_width, channels ) else: err_message = "cannot write file format {} (file name: {})" diff -r 01ef241d17e6 -r b5a2da2e61f9 tests/test_io.py --- a/tests/test_io.py Fri Feb 15 21:47:42 2019 +0100 +++ b/tests/test_io.py Sat Feb 16 18:25:26 2019 +0100 @@ -634,3 +634,14 @@ with patch("auditok.io._WITH_PYDUB", False): with self.assertRaises(AudioIOError): to_file("audio", b"", "mp3") + + @patch("auditok.io._WITH_PYDUB", True) + @genty_dataset( + ogg_with_extension=("audio.ogg", None), + ogg_with_audio_format=("audio", "ogg"), + ogg_format_with_wrong_extension=("audio.wav", "ogg"), + ) + def test_to_file_compressed(self, filename, audio_format, *mocks): + with patch("auditok.io.AudioSegment.export") as export: + to_file(b"\0\0", filename, audio_format, **AUDIO_PARAMS_SHORT) + self.assertTrue(export.called)