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

import torchaudio
from torchaudio._internal.module_utils import is_module_available

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

moto's avatar
moto committed
8
9

class BackendSwitchMixin:
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    """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
26
class TestBackendSwitch_NoBackend(BackendSwitchMixin, common_utils.TorchaudioTestCase):
27
28
29
30
31
32
33
    backend = None
    backend_module = torchaudio.backend.no_backend


@unittest.skipIf(
    not is_module_available('torchaudio._torchaudio'),
    'torchaudio C++ extension not available')
moto's avatar
moto committed
34
class TestBackendSwitch_SoX(BackendSwitchMixin, common_utils.TorchaudioTestCase):
35
36
37
38
39
    backend = 'sox'
    backend_module = torchaudio.backend.sox_backend


@unittest.skipIf(not is_module_available('soundfile'), '"soundfile" not available')
moto's avatar
moto committed
40
class TestBackendSwitch_soundfile(BackendSwitchMixin, common_utils.TorchaudioTestCase):
41
42
    backend = 'soundfile'
    backend_module = torchaudio.backend.soundfile_backend