Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PoC] use pytest configuration file #3401

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/unittest/linux/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fi
# Note: installing librosa via pip fail because it will try to compile numba.
(
set -x
conda install -y -c conda-forge ${NUMBA_DEV_CHANNEL} 'librosa==0.10.0' parameterized 'requests>=2.20'
conda install -y -c conda-forge ${NUMBA_DEV_CHANNEL} sox libvorbis 'librosa==0.10.0' parameterized 'requests>=2.20'
pip install kaldi-io SoundFile coverage pytest pytest-cov 'scipy==1.7.3' transformers expecttest unidecode inflect Pillow sentencepiece pytorch-lightning 'protobuf<4.21.0' demucs tinytag pyroomacoustics flashlight-text git+https://github.com/kpu/kenlm
)
# Install fairseq
Expand Down
2 changes: 1 addition & 1 deletion .circleci/unittest/windows/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ case "$(python --version)" in
esac
# Note: installing librosa via pip fail because it will try to compile numba.
(
conda install -y -c conda-forge ${NUMBA_DEV_CHANNEL} 'librosa==0.10.0' parameterized 'requests>=2.20'
conda install -y -c conda-forge ${NUMBA_DEV_CHANNEL} sox libvorbis 'librosa==0.10.0' parameterized 'requests>=2.20'
# Need to disable shell check since this'll fail out if SENTENCEPIECE_DEPENDENCY is empty
# shellcheck disable=SC2086
pip install \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
pip --quiet install git+https://github.com/kpu/kenlm/ flashlight-text

# Install build tools
conda install --quiet -y -c conda-forge pandoc doxygen pysoundfile
conda install --quiet -y -c conda-forge sox pandoc doxygen pysoundfile
pip install --quiet -r docs/requirements.txt -r docs/requirements-tutorials.txt

# Build docs
Expand Down
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: 1 addition & 1 deletion .github/workflows/unittest-linux-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
USE_FFMPEG=1 python3 -m pip install -v -e . --no-use-pep517

# Install test tools
conda install -y --quiet -c conda-forge -c numba/label/dev 'librosa==0.10.0' parameterized 'requests>=2.20'
conda install -y --quiet -c conda-forge -c numba/label/dev sox libvorbis 'librosa==0.10.0' parameterized 'requests>=2.20'
python3 -m pip install --quiet kaldi-io SoundFile coverage pytest pytest-cov 'scipy==1.7.3' transformers expecttest unidecode inflect Pillow sentencepiece pytorch-lightning 'protobuf<4.21.0' demucs tinytag flashlight-text git+https://github.com/kpu/kenlm/
python3 -m pip install --quiet git+https://github.com/pytorch/fairseq.git@e47a4c8

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
13 changes: 13 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[pytest]
addopts =
# show tests that (f)ailed, (E)rror, or (X)passed in the summary
-rfEX
# Make tracebacks shorter
--tb=native
# enable all warnings
-Wd
--ignore=test/test_datasets_download.py
--ignore-glob=test/test_prototype_*.py
testpaths =
test
xfail_strict = True
20 changes: 1 addition & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,13 @@ def _parse_url(path):
yield url


def _parse_sources():
third_party_dir = ROOT_DIR / "third_party"
libs = ["sox"]
archive_dir = third_party_dir / "archives"
archive_dir.mkdir(exist_ok=True)
for lib in libs:
cmake_file = third_party_dir / lib / "CMakeLists.txt"
for url in _parse_url(cmake_file):
path = archive_dir / os.path.basename(url)
yield path, url


def _fetch_archives(src):
for dest, url in src:
if not dest.exists():
print(f" --- Fetching {os.path.basename(dest)}")
torch.hub.download_url_to_file(url, dest, progress=False)


def _fetch_third_party_libraries():
_init_submodule()
if os.name != "nt":
_fetch_archives(_parse_sources())


def _main():
sha = _run_cmd(["git", "rev-parse", "HEAD"])
branch = _run_cmd(["git", "rev-parse", "--abbrev-ref", "HEAD"])
Expand All @@ -142,7 +124,7 @@ def _main():
print("-- Building version", version)

_make_version_file(version, sha)
_fetch_third_party_libraries()
_init_submodule()

with open("README.md") as f:
long_description = f.read()
Expand Down
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
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
4 changes: 2 additions & 2 deletions test/torchaudio_unittest/sox_effect/dataset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ 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,
)
for batch in loader:
Expand All @@ -115,7 +115,7 @@ 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,
)
for batch in loader:
Expand Down
Loading