Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mthrok committed Jun 2, 2023
1 parent dae2b57 commit 8ec5475
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/unittest-linux-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ 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_NO_SOX_DECODER=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_ENCODER=true
echo '::endgroup::'
set -euxo pipefail
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/unittest-macos-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ 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_NO_SOX_DECODER=true
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_ENCODER=true
echo '::endgroup::'
set -euxo pipefail
Expand Down
4 changes: 3 additions & 1 deletion test/torchaudio_unittest/backend/dispatcher/sox/info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
skipIfNoExec,
skipIfNoModule,
skipIfNoSox,
skipIfNoSoxDecoder,
sox_utils,
TempDirMixin,
)
Expand Down Expand Up @@ -178,6 +179,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 +258,7 @@ def test_htk(self):
assert info.encoding == "PCM_S"


@skipIfNoSox
@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 @@ -14,6 +14,7 @@
save_wav,
skipIfNoExec,
skipIfNoSox,
skipIfNoSoxDecoder,
sox_utils,
TempDirMixin,
)
Expand Down Expand Up @@ -238,6 +239,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 @@ -282,6 +284,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 @@ -18,6 +18,7 @@
skipIfNoExec,
skipIfNoModule,
skipIfNoSox,
skipIfNoSoxDecoder,
sox_utils,
TempDirMixin,
)
Expand Down Expand Up @@ -244,6 +245,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 @@ -288,6 +290,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 @@ -12,6 +12,7 @@
save_wav,
skipIfNoExec,
skipIfNoSox,
skipIfNoSoxEncoder,
sox_utils,
TempDirMixin,
TorchaudioTestCase,
Expand Down Expand Up @@ -266,6 +267,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 @@ -282,12 +284,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
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
2 changes: 2 additions & 0 deletions test/torchaudio_unittest/common_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
skipIfNoQengine,
skipIfNoRIR,
skipIfNoSox,
skipIfNoSoxDecoder,
skipIfNoSoxEncoder,
skipIfPy310,
skipIfRocm,
TempDirMixin,
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=f"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 read.',
key=f"NO_SOX_ENCODER",
)


skipIfNoKaldi = _skipIf(
not torchaudio._extension._IS_KALDI_AVAILABLE,
reason="Kaldi features are not available.",
Expand Down

0 comments on commit 8ec5475

Please sign in to comment.