Mercurial > hg > auditok
comparison tests/test_io.py @ 142:d42c0c2858c5
Use TemporaryDirectory to export test audio files
author | Amine Sehili <amine.sehili@gmail.com> |
---|---|
date | Sun, 17 Feb 2019 14:18:47 +0100 |
parents | 995a568e6eff |
children | 5ff29f286374 |
comparison
equal
deleted
inserted
replaced
141:995a568e6eff | 142:d42c0c2858c5 |
---|---|
579 srate, swidth, channels, _ = _get_audio_parameters(params) | 579 srate, swidth, channels, _ = _get_audio_parameters(params) |
580 _save_wave(b"\0\0", "audio", srate, swidth, channels) | 580 _save_wave(b"\0\0", "audio", srate, swidth, channels) |
581 | 581 |
582 def test_save_with_pydub(self): | 582 def test_save_with_pydub(self): |
583 with patch("auditok.io.AudioSegment.export") as export: | 583 with patch("auditok.io.AudioSegment.export") as export: |
584 _save_with_pydub(b"\0\0", "audio.org", "ogg", 16000, 2, 1) | 584 tmpdir = TemporaryDirectory() |
585 filename = os.path.join(tmpdir.name, "audio.ogg") | |
586 _save_with_pydub(b"\0\0", filename, "ogg", 16000, 2, 1) | |
585 self.assertTrue(export.called) | 587 self.assertTrue(export.called) |
588 tmpdir.cleanup() | |
586 | 589 |
587 @genty_dataset( | 590 @genty_dataset( |
588 raw_with_audio_format=("audio", "raw"), | 591 raw_with_audio_format=("audio", "raw"), |
589 raw_with_extension=("audio.raw", None), | 592 raw_with_extension=("audio.raw", None), |
590 raw_with_audio_format_and_extension=("audio.mp3", "raw"), | 593 raw_with_audio_format_and_extension=("audio.mp3", "raw"), |
647 ogg_with_audio_format=("audio", "ogg"), | 650 ogg_with_audio_format=("audio", "ogg"), |
648 ogg_format_with_wrong_extension=("audio.wav", "ogg"), | 651 ogg_format_with_wrong_extension=("audio.wav", "ogg"), |
649 ) | 652 ) |
650 def test_to_file_compressed(self, filename, audio_format, *mocks): | 653 def test_to_file_compressed(self, filename, audio_format, *mocks): |
651 with patch("auditok.io.AudioSegment.export") as export: | 654 with patch("auditok.io.AudioSegment.export") as export: |
655 tmpdir = TemporaryDirectory() | |
656 filename = os.path.join(tmpdir.name, filename) | |
652 to_file(b"\0\0", filename, audio_format, **AUDIO_PARAMS_SHORT) | 657 to_file(b"\0\0", filename, audio_format, **AUDIO_PARAMS_SHORT) |
653 self.assertTrue(export.called) | 658 self.assertTrue(export.called) |
659 tmpdir.cleanup() |