test_backend.py 1.21 KB
Newer Older
1
2
3
4
import unittest

import torchaudio

moto's avatar
moto committed
5
from . import common_utils
6

moto's avatar
moto committed
7
8

class BackendSwitchMixin:
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    """Test set/get_audio_backend works"""
    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.load_wav == self.backend_module.load_wav
        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


30
@common_utils.skipIfNoExtension
moto's avatar
moto committed
31
class TestBackendSwitch_SoX(BackendSwitchMixin, common_utils.TorchaudioTestCase):
32
33
34
35
    backend = 'sox'
    backend_module = torchaudio.backend.sox_backend


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