Skip to content

Commit

Permalink
Make sox selective (#1338)
Browse files Browse the repository at this point in the history
  • Loading branch information
Caroline Chen committed Mar 2, 2021
1 parent 98d0d59 commit ecfed4d
Show file tree
Hide file tree
Showing 28 changed files with 140 additions and 86 deletions.
12 changes: 6 additions & 6 deletions test/torchaudio_unittest/backend/sox_io/info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
HttpServerMixin,
PytorchTestCase,
skipIfNoExec,
skipIfNoExtension,
skipIfNoModule,
skipIfNoSox,
get_asset_path,
get_wav_data,
save_wav,
Expand All @@ -33,7 +33,7 @@


@skipIfNoExec('sox')
@skipIfNoExtension
@skipIfNoSox
class TestInfo(TempDirMixin, PytorchTestCase):
@parameterized.expand(list(itertools.product(
['float32', 'int32', 'int16', 'uint8'],
Expand Down Expand Up @@ -253,7 +253,7 @@ def test_htk(self):
assert info.encoding == "PCM_S"


@skipIfNoExtension
@skipIfNoSox
class TestInfoOpus(PytorchTestCase):
@parameterized.expand(list(itertools.product(
['96k'],
Expand All @@ -271,7 +271,7 @@ def test_opus(self, bitrate, num_channels, compression_level):
assert info.encoding == "OPUS"


@skipIfNoExtension
@skipIfNoSox
class TestLoadWithoutExtension(PytorchTestCase):
def test_mp3(self):
"""Providing `format` allows to read mp3 without extension
Expand Down Expand Up @@ -306,7 +306,7 @@ def _gen_file(self, ext, dtype, sample_rate, num_channels, num_frames):
return path


@skipIfNoExtension
@skipIfNoSox
@skipIfNoExec('sox')
class TestFileObject(FileObjTestBase, PytorchTestCase):
def _query_fileobj(self, ext, dtype, sample_rate, num_channels, num_frames):
Expand Down Expand Up @@ -438,7 +438,7 @@ def test_tarfile(self, ext, dtype):
assert sinfo.encoding == get_encoding(ext, dtype)


@skipIfNoExtension
@skipIfNoSox
@skipIfNoExec('sox')
@skipIfNoModule("requests")
class TestFileObjectHttp(HttpServerMixin, FileObjTestBase, PytorchTestCase):
Expand Down
12 changes: 6 additions & 6 deletions test/torchaudio_unittest/backend/sox_io/load_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
HttpServerMixin,
PytorchTestCase,
skipIfNoExec,
skipIfNoExtension,
skipIfNoModule,
skipIfNoSox,
get_asset_path,
get_wav_data,
load_wav,
Expand Down Expand Up @@ -200,7 +200,7 @@ def assert_amr_nb(self, duration):


@skipIfNoExec('sox')
@skipIfNoExtension
@skipIfNoSox
class TestLoad(LoadTestBase):
"""Test the correctness of `sox_io_backend.load` for various formats"""
@parameterized.expand(list(itertools.product(
Expand Down Expand Up @@ -332,7 +332,7 @@ def test_amr_nb(self):


@skipIfNoExec('sox')
@skipIfNoExtension
@skipIfNoSox
class TestLoadParams(TempDirMixin, PytorchTestCase):
"""Test the correctness of frame parameters of `sox_io_backend.load`"""
original = None
Expand Down Expand Up @@ -363,7 +363,7 @@ def test_channels_first(self, channels_first):
self.assertEqual(found, expected)


@skipIfNoExtension
@skipIfNoSox
class TestLoadWithoutExtension(PytorchTestCase):
def test_mp3(self):
"""Providing format allows to read mp3 without extension
Expand Down Expand Up @@ -393,7 +393,7 @@ def read(self, n):
return ret


@skipIfNoExtension
@skipIfNoSox
@skipIfNoExec('sox')
class TestFileObject(TempDirMixin, PytorchTestCase):
"""
Expand Down Expand Up @@ -553,7 +553,7 @@ def test_tarfile(self, ext, compression):
self.assertEqual(expected, found)


@skipIfNoExtension
@skipIfNoSox
@skipIfNoExec('sox')
@skipIfNoModule("requests")
class TestFileObjectHttp(HttpServerMixin, PytorchTestCase):
Expand Down
4 changes: 2 additions & 2 deletions test/torchaudio_unittest/backend/sox_io/roundtrip_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
TempDirMixin,
PytorchTestCase,
skipIfNoExec,
skipIfNoExtension,
skipIfNoSox,
get_wav_data,
)
from .common import (
Expand All @@ -17,7 +17,7 @@


@skipIfNoExec('sox')
@skipIfNoExtension
@skipIfNoSox
class TestRoundTripIO(TempDirMixin, PytorchTestCase):
"""save/load round trip should not degrade data for lossless formats"""
@parameterized.expand(list(itertools.product(
Expand Down
6 changes: 3 additions & 3 deletions test/torchaudio_unittest/backend/sox_io/save_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
TorchaudioTestCase,
PytorchTestCase,
skipIfNoExec,
skipIfNoExtension,
skipIfNoSox,
get_wav_data,
load_wav,
save_wav,
Expand Down Expand Up @@ -157,7 +157,7 @@ def _name_func(func, _, params):


@skipIfNoExec('sox')
@skipIfNoExtension
@skipIfNoSox
class SaveTest(SaveTestBase):
@nested_params(
["path", "fileobj", "bytesio"],
Expand Down Expand Up @@ -354,7 +354,7 @@ def test_save_multi_channels(self, num_channels):


@skipIfNoExec('sox')
@skipIfNoExtension
@skipIfNoSox
class TestSaveParams(TempDirMixin, PytorchTestCase):
"""Test the correctness of optional parameters of `sox_io_backend.save`"""
@parameterized.expand([(True, ), (False, )], name_func=name_func)
Expand Down
10 changes: 5 additions & 5 deletions test/torchaudio_unittest/backend/sox_io/smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@

from torchaudio.utils import sox_utils
from torchaudio.backend import sox_io_backend
from torchaudio._internal.module_utils import is_module_available
from torchaudio._internal.module_utils import is_sox_available
from parameterized import parameterized

from torchaudio_unittest.common_utils import (
TempDirMixin,
TorchaudioTestCase,
skipIfNoExtension,
skipIfNoSox,
get_wav_data,
)
from .common import name_func


skipIfNoMP3 = unittest.skipIf(
not is_module_available('torchaudio._torchaudio') or
not is_sox_available() or
'mp3' not in sox_utils.list_read_formats() or
'mp3' not in sox_utils.list_write_formats(),
'"sox_io" backend does not support MP3')


@skipIfNoExtension
@skipIfNoSox
class SmokeTest(TempDirMixin, TorchaudioTestCase):
"""Run smoke test on various audio format
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_flac(self, sample_rate, num_channels, compression_level):
self.run_smoke_test('flac', sample_rate, num_channels, compression=compression_level)


@skipIfNoExtension
@skipIfNoSox
class SmokeTestFileObj(TorchaudioTestCase):
"""Run smoke test on various audio format
Expand Down
4 changes: 2 additions & 2 deletions test/torchaudio_unittest/backend/sox_io/torchscript_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
TempDirMixin,
TorchaudioTestCase,
skipIfNoExec,
skipIfNoExtension,
skipIfNoSox,
get_wav_data,
save_wav,
load_wav,
Expand Down Expand Up @@ -45,7 +45,7 @@ def py_save_func(


@skipIfNoExec('sox')
@skipIfNoExtension
@skipIfNoSox
class SoxIO(TempDirMixin, TorchaudioTestCase):
"""TorchScript-ability Test suite for `sox_io_backend`"""
backend = 'sox_io'
Expand Down
2 changes: 1 addition & 1 deletion test/torchaudio_unittest/backend/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TestBackendSwitch_NoBackend(BackendSwitchMixin, common_utils.TorchaudioTes
backend_module = torchaudio.backend.no_backend


@common_utils.skipIfNoExtension
@common_utils.skipIfNoSox
class TestBackendSwitch_SoXIO(BackendSwitchMixin, common_utils.TorchaudioTestCase):
backend = 'sox_io'
backend_module = torchaudio.backend.sox_io_backend
Expand Down
5 changes: 3 additions & 2 deletions test/torchaudio_unittest/common_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
skipIfNoExec,
skipIfNoModule,
skipIfNoExtension,
skipIfNoSox,
skipIfNoSoxBackend,
)
from .wav_utils import (
Expand All @@ -30,5 +31,5 @@

__all__ = ['get_asset_path', 'get_whitenoise', 'get_sinusoid', 'set_audio_backend',
'TempDirMixin', 'HttpServerMixin', 'TestBaseMixin', 'PytorchTestCase', 'TorchaudioTestCase',
'skipIfNoCuda', 'skipIfNoExec', 'skipIfNoModule', 'skipIfNoExtension', 'skipIfNoSoxBackend',
'get_wav_data', 'normalize_wav', 'load_wav', 'save_wav', 'load_params']
'skipIfNoCuda', 'skipIfNoExec', 'skipIfNoModule', 'skipIfNoExtension', 'skipIfNoSox',
'skipIfNoSoxBackend', 'get_wav_data', 'normalize_wav', 'load_wav', 'save_wav', 'load_params']
6 changes: 5 additions & 1 deletion test/torchaudio_unittest/common_utils/case_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import torch
from torch.testing._internal.common_utils import TestCase as PytorchTestCase
import torchaudio
from torchaudio._internal.module_utils import is_module_available
from torchaudio._internal.module_utils import (
is_module_available,
is_sox_available
)

from .backend_utils import set_audio_backend

Expand Down Expand Up @@ -95,6 +98,7 @@ def skipIfNoModule(module, display_name=None):
skipIfNoSoxBackend = unittest.skipIf(
'sox' not in torchaudio.list_audio_backends(), 'Sox backend not available')
skipIfNoCuda = unittest.skipIf(not torch.cuda.is_available(), reason='CUDA not available')
skipIfNoSox = unittest.skipIf(not is_sox_available(), reason='Sox not available')


def skipIfNoExtension(test_item):
Expand Down
2 changes: 2 additions & 0 deletions test/torchaudio_unittest/datasets/tedlium_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
TorchaudioTestCase,
get_whitenoise,
save_wav,
skipIfNoSox
)

from torchaudio.datasets import tedlium
Expand Down Expand Up @@ -144,5 +145,6 @@ class TestTedliumSoundfile(Tedlium, TorchaudioTestCase):


if platform.system() != "Windows":
@skipIfNoSox
class TestTedliumSoxIO(Tedlium, TorchaudioTestCase):
backend = "sox_io"
4 changes: 2 additions & 2 deletions test/torchaudio_unittest/functional/functional_cpu_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from torchaudio_unittest import common_utils
from torchaudio_unittest.common_utils import (
TorchaudioTestCase,
skipIfNoExtension,
skipIfNoSox,
)
from torchaudio_unittest.backend.sox_io.common import name_func

Expand Down Expand Up @@ -220,7 +220,7 @@ def test_mask_along_axis_iid(self, mask_param, mask_value, axis):
assert (num_masked_columns < mask_param).sum() == num_masked_columns.numel()


@skipIfNoExtension
@skipIfNoSox
class TestApplyCodec(TorchaudioTestCase):
backend = "sox_io"

Expand Down
6 changes: 3 additions & 3 deletions test/torchaudio_unittest/sox_effect/dataset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from torchaudio_unittest.common_utils import (
TempDirMixin,
PytorchTestCase,
skipIfNoExtension,
skipIfNoSox,
get_whitenoise,
save_wav,
)
Expand Down Expand Up @@ -71,7 +71,7 @@ def init_random_seed(worker_id):
dataset.rng = np.random.RandomState(worker_id)


@skipIfNoExtension
@skipIfNoSox
@skipIf(
platform.system() == 'Darwin' and
sys.version_info.major == 3 and
Expand Down Expand Up @@ -134,7 +134,7 @@ def speed(path):
return torchaudio.sox_effects.apply_effects_tensor(wav, sample_rate, effects)[0]


@skipIfNoExtension
@skipIfNoSox
class TestProcessPoolExecutor(TempDirMixin, PytorchTestCase):
backend = "sox_io"

Expand Down
4 changes: 2 additions & 2 deletions test/torchaudio_unittest/sox_effect/smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from torchaudio_unittest.common_utils import (
TempDirMixin,
TorchaudioTestCase,
skipIfNoExtension,
skipIfNoSox,
get_wav_data,
get_sinusoid,
save_wav,
Expand All @@ -14,7 +14,7 @@
)


@skipIfNoExtension
@skipIfNoSox
class SmokeTest(TempDirMixin, TorchaudioTestCase):
"""Run smoke test on various effects
Expand Down

0 comments on commit ecfed4d

Please sign in to comment.