utils_test.py 1.26 KB
Newer Older
1
2
from unittest.mock import patch

3
import torchaudio
4
from torchaudio_unittest import common_utils
5

moto's avatar
moto committed
6
7

class BackendSwitchMixin:
8
    """Test set/get_audio_backend works"""
9

10
11
12
    backend = None
    backend_module = None

13
    @patch("torchaudio.backend.utils._is_backend_dispatcher_enabled", lambda: False)
14
15
16
17
18
19
20
21
22
23
24
    def test_switch(self):
        torchaudio.set_audio_backend(self.backend)
        if self.backend is None:
            assert torchaudio.get_audio_backend() is None
        else:
            assert torchaudio.get_audio_backend() == self.backend
        assert torchaudio.load == self.backend_module.load
        assert torchaudio.save == self.backend_module.save
        assert torchaudio.info == self.backend_module.info


moto's avatar
moto committed
25
class TestBackendSwitch_NoBackend(BackendSwitchMixin, common_utils.TorchaudioTestCase):
26
27
28
29
    backend = None
    backend_module = torchaudio.backend.no_backend


Caroline Chen's avatar
Caroline Chen committed
30
@common_utils.skipIfNoSox
moto's avatar
moto committed
31
class TestBackendSwitch_SoXIO(BackendSwitchMixin, common_utils.TorchaudioTestCase):
32
    backend = "sox_io"
moto's avatar
moto committed
33
34
35
    backend_module = torchaudio.backend.sox_io_backend


36
@common_utils.skipIfNoModule("soundfile")
37
class TestBackendSwitch_soundfile(BackendSwitchMixin, common_utils.TorchaudioTestCase):
38
    backend = "soundfile"
Prabhat Roy's avatar
Prabhat Roy committed
39
    backend_module = torchaudio.backend.soundfile_backend