Skip to content

Commit

Permalink
Disable some tests that need libsox (#3494)
Browse files Browse the repository at this point in the history
Summary:
In preparation for #3082

Disable those FFmpeg tests that depend on sox CLI. These tests need to be updated or removed so as not to use sox CLI.

Auto-skip some sox tests if decoder/encoder are not available

Pull Request resolved: #3494

Differential Revision: D47761948

Pulled By: mthrok

fbshipit-source-id: 3a48d7f280f8376a48d223947dd41a7cdc8cbc30
  • Loading branch information
mthrok authored and facebook-github-bot committed Jul 25, 2023
1 parent e483a67 commit 49e9ed9
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/unittest-linux-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_ON_PYTHON_310=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_AUDIO_OUT_DEVICE=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MACOS=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_TEMPORARY_DISABLED=true
echo '::endgroup::'
set -euxo pipefail
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/unittest-macos-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_ON_PYTHON_310=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_sentencepiece=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_AUDIO_OUT_DEVICE=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_TEMPORARY_DISABLED=true
echo '::endgroup::'
set -euxo pipefail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from torchaudio_unittest.backend.dispatcher.sox.common import name_func
from torchaudio_unittest.common_utils import (
disabledInCI,
get_asset_path,
get_wav_data,
HttpServerMixin,
Expand Down Expand Up @@ -535,6 +536,7 @@ def read(self, n):
return self.fileobj.read(n)


@disabledInCI
@skipIfNoFFmpeg
@skipIfNoExec("sox")
@skipIfNoModule("requests")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from torchaudio_unittest.backend.dispatcher.sox.common import get_enc_params, name_func
from torchaudio_unittest.common_utils import (
disabledInCI,
get_wav_data,
load_wav,
nested_params,
Expand Down Expand Up @@ -147,6 +148,7 @@ def assert_save_consistency(
self.assertEqual(found, expected)


@disabledInCI
@skipIfNoExec("sox")
@skipIfNoExec("ffmpeg")
@skipIfNoFFmpeg
Expand Down Expand Up @@ -396,6 +398,7 @@ def test_save_tensor_preserve(self, dtype):
self.assertEqual(data, expected)


@disabledInCI
@skipIfNoExec("sox")
@skipIfNoFFmpeg
class TestSaveNonExistingDirectory(PytorchTestCase):
Expand Down
6 changes: 5 additions & 1 deletion test/torchaudio_unittest/backend/dispatcher/sox/info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from torchaudio._internal import module_utils as _mod_utils
from torchaudio_unittest.backend.common import get_encoding
from torchaudio_unittest.common_utils import (
disabledInCI,
get_asset_path,
get_wav_data,
HttpServerMixin,
Expand All @@ -15,6 +16,7 @@
skipIfNoExec,
skipIfNoModule,
skipIfNoSox,
skipIfNoSoxDecoder,
sox_utils,
TempDirMixin,
)
Expand Down Expand Up @@ -178,6 +180,7 @@ def test_amb(self, dtype, sample_rate, num_channels):
assert info.bits_per_sample == bits_per_sample
assert info.encoding == get_encoding("amb", dtype)

@skipIfNoSoxDecoder("amr-nb")
def test_amr_nb(self):
"""`self._info` can check amr-nb file correctly"""
duration = 1
Expand Down Expand Up @@ -256,7 +259,8 @@ def test_htk(self):
assert info.encoding == "PCM_S"


@skipIfNoSox
@disabledInCI
@skipIfNoSoxDecoder("opus")
class TestInfoOpus(PytorchTestCase):
_info = partial(get_info_func(), backend="sox")

Expand Down
3 changes: 3 additions & 0 deletions test/torchaudio_unittest/backend/dispatcher/sox/load_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
save_wav,
skipIfNoExec,
skipIfNoSox,
skipIfNoSoxDecoder,
sox_utils,
TempDirMixin,
)
Expand Down Expand Up @@ -237,6 +238,7 @@ def test_vorbis_large(self, sample_rate, num_channels, quality_level):
),
name_func=name_func,
)
@skipIfNoSoxDecoder("opus")
def test_opus(self, bitrate, num_channels, compression_level):
"""`sox_io_backend.load` can load opus file correctly."""
ops_path = get_asset_path("io", f"{bitrate}_{compression_level}_{num_channels}ch.opus")
Expand Down Expand Up @@ -281,6 +283,7 @@ def test_amb(self, dtype, sample_rate, num_channels, normalize):
"amb", sample_rate, num_channels, bit_depth=bit_depth, duration=1, encoding=encoding, normalize=normalize
)

@skipIfNoSoxDecoder("amr-nb")
def test_amr_nb(self):
"""`sox_io_backend.load` can load amr_nb format correctly."""
self.assert_format("amr-nb", sample_rate=8000, num_channels=1, bit_depth=32, duration=1)
Expand Down
10 changes: 9 additions & 1 deletion test/torchaudio_unittest/backend/dispatcher/sox/save_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
save_wav,
skipIfNoExec,
skipIfNoSox,
skipIfNoSoxEncoder,
sox_utils,
TempDirMixin,
TorchaudioTestCase,
Expand Down Expand Up @@ -253,6 +254,7 @@ def test_save_amb(self, enc_params):
encoding, bits_per_sample = enc_params
self.assert_save_consistency("amb", encoding=encoding, bits_per_sample=bits_per_sample, test_mode="path")

@skipIfNoSoxEncoder("amr-nb")
def test_save_amr_nb(self):
self.assert_save_consistency("amr-nb", num_channels=1, test_mode="path")

Expand All @@ -269,12 +271,18 @@ def test_save_gsm(self):
("flac",),
("vorbis",),
("sph", "PCM_S", 16),
("amr-nb",),
("amb", "PCM_S", 16),
],
name_func=name_func,
)
def test_save_large(self, format, encoding=None, bits_per_sample=None):
self._test_save_large(format, encoding, bits_per_sample)

@skipIfNoSoxEncoder("amr-nb")
def test_save_large_amr_nb(self):
self._test_save_large("amr-nb")

def _test_save_large(self, format, encoding=None, bits_per_sample=None):
"""`self._save` can save large files."""
sample_rate = 8000
one_hour = 60 * 60 * sample_rate
Expand Down
2 changes: 2 additions & 0 deletions test/torchaudio_unittest/backend/sox_io/info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
save_wav,
skipIfNoExec,
skipIfNoSox,
skipIfNoSoxDecoder,
sox_utils,
TempDirMixin,
)
Expand Down Expand Up @@ -196,6 +197,7 @@ def test_amb(self, dtype, sample_rate, num_channels):
assert info.bits_per_sample == bits_per_sample
assert info.encoding == get_encoding("amb", dtype)

@skipIfNoSoxDecoder("amr-nb")
def test_amr_nb(self):
"""`sox_io_backend.info` can check amr-nb file correctly"""
duration = 1
Expand Down
3 changes: 3 additions & 0 deletions test/torchaudio_unittest/backend/sox_io/load_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
save_wav,
skipIfNoExec,
skipIfNoSox,
skipIfNoSoxDecoder,
sox_utils,
TempDirMixin,
)
Expand Down Expand Up @@ -234,6 +235,7 @@ def test_vorbis_large(self, sample_rate, num_channels, quality_level):
),
name_func=name_func,
)
@skipIfNoSoxDecoder("opus")
def test_opus(self, bitrate, num_channels, compression_level):
"""`sox_io_backend.load` can load opus file correctly."""
ops_path = get_asset_path("io", f"{bitrate}_{compression_level}_{num_channels}ch.opus")
Expand Down Expand Up @@ -278,6 +280,7 @@ def test_amb(self, dtype, sample_rate, num_channels, normalize):
"amb", sample_rate, num_channels, bit_depth=bit_depth, duration=1, encoding=encoding, normalize=normalize
)

@skipIfNoSoxDecoder("amr-nb")
def test_amr_nb(self):
"""`sox_io_backend.load` can load amr_nb format correctly."""
self.assert_format("amr-nb", sample_rate=8000, num_channels=1, bit_depth=32, duration=1)
Expand Down
10 changes: 9 additions & 1 deletion test/torchaudio_unittest/backend/sox_io/save_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
save_wav,
skipIfNoExec,
skipIfNoSox,
skipIfNoSoxEncoder,
sox_utils,
TempDirMixin,
TorchaudioTestCase,
Expand Down Expand Up @@ -265,6 +266,7 @@ def test_save_amb(self, enc_params):
7,
],
)
@skipIfNoSoxEncoder("amr-nb")
def test_save_amr_nb(self, bit_rate):
self.assert_save_consistency("amr-nb", compression=bit_rate, num_channels=1)

Expand All @@ -281,12 +283,18 @@ def test_save_gsm(self):
("flac",),
("vorbis",),
("sph", "PCM_S", 16),
("amr-nb",),
("amb", "PCM_S", 16),
],
name_func=name_func,
)
def test_save_large(self, format, encoding=None, bits_per_sample=None):
self._test_save_large(format, encoding, bits_per_sample)

@skipIfNoSoxEncoder("amr-nb")
def test_save_large_amr_nb(self):
self._test_save_large("amr-nb")

def _test_save_large(self, format, encoding=None, bits_per_sample=None):
"""`sox_io_backend.save` can save large files."""
sample_rate = 8000
one_hour = 60 * 60 * sample_rate
Expand Down
5 changes: 4 additions & 1 deletion test/torchaudio_unittest/common_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
skipIfNoQengine,
skipIfNoRIR,
skipIfNoSox,
skipIfNoSoxDecoder,
skipIfNoSoxEncoder,
skipIfPy310,
skipIfRocm,
TempDirMixin,
Expand Down Expand Up @@ -53,7 +55,8 @@
"skipIfNoModule",
"skipIfNoRIR",
"skipIfNoSox",
"skipIfNoSoxBackend",
"skipIfNoSoxDecoder",
"skipIfNoSoxEncoder",
"skipIfRocm",
"skipIfNoQengine",
"skipIfNoFFmpeg",
Expand Down
18 changes: 18 additions & 0 deletions test/torchaudio_unittest/common_utils/case_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,24 @@ def skipIfNoModule(module, display_name=None):
reason="Sox features are not available.",
key="NO_SOX",
)


def skipIfNoSoxDecoder(ext):
return _skipIf(
not torchaudio._extension._SOX_INITIALIZED or ext not in torchaudio.utils.sox_utils.list_read_formats(),
f'sox does not handle "{ext}" for read.',
key="NO_SOX_DECODER",
)


def skipIfNoSoxEncoder(ext):
return _skipIf(
not torchaudio._extension._SOX_INITIALIZED or ext not in torchaudio.utils.sox_utils.list_write_formats(),
f'sox does not handle "{ext}" for write.',
key="NO_SOX_ENCODER",
)


skipIfNoRIR = _skipIf(
not torchaudio._extension._IS_RIR_AVAILABLE,
reason="RIR features are not available.",
Expand Down
6 changes: 4 additions & 2 deletions test/torchaudio_unittest/sox_effect/dataset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ def test_apply_effects_file(self):
loader = torch.utils.data.DataLoader(
dataset,
batch_size=32,
num_workers=16,
num_workers=4,
worker_init_fn=init_random_seed,
multiprocessing_context=torch.multiprocessing.get_context("spawn"),
)
for batch in loader:
assert batch.shape == (32, 2, 2 * sample_rate)
Expand All @@ -115,8 +116,9 @@ def test_apply_effects_tensor(self):
loader = torch.utils.data.DataLoader(
dataset,
batch_size=32,
num_workers=16,
num_workers=4,
worker_init_fn=init_random_seed,
multiprocessing_context=torch.multiprocessing.get_context("spawn"),
)
for batch in loader:
assert batch.shape == (32, 2, 2 * sample_rate)
Expand Down

0 comments on commit 49e9ed9

Please sign in to comment.