utils_test.py 1.15 KB
Newer Older
1
import torchaudio
2
from torchaudio_unittest import common_utils
3

moto's avatar
moto committed
4
5

class BackendSwitchMixin:
6
    """Test set/get_audio_backend works"""
7

8
9
10
11
12
13
14
15
16
17
18
19
20
21
    backend = None
    backend_module = None

    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
22
class TestBackendSwitch_NoBackend(BackendSwitchMixin, common_utils.TorchaudioTestCase):
23
24
25
26
    backend = None
    backend_module = torchaudio.backend.no_backend


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


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