Unverified Commit 4a24ed72 authored by peterjc123's avatar peterjc123 Committed by GitHub
Browse files

Enable unittest jobs for windows (#604)



* Turn on tests when building through conda-build

* skip one failling test on windows.

* Switch to unittest

* Fix conda env activation

* add linux only condition

* Fix librosa installation

* conda-forge channel as a fallback

* Revert "conda-forge channel as a fallback"

This reverts commit 8c15f6638e34792640a3de3e057d9c2995425180.

* Try the pytorch way

* Use conda-forge

* Disable conda-forge

* Install future at setup env

* Move linux unittest CI job tools to dedicated directory

* Restore Linux scripts and move the updated souces to a new subdir

* Add back future

* Remove comments
Co-authored-by: default avatarVincent Quenneville-Belair <vincentqb@gmail.com>
Co-authored-by: default avatarmoto <855818+mthrok@users.noreply.github.com>
parent be18755b
#!/usr/bin/env bash
# This script is for setting up environment in which unit test is ran.
# To speed up the CI time, the resulting environment is cached.
#
# Do not install PyTorch and torchaudio here, otherwise they also get cached.
set -e
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
root_dir="$(git rev-parse --show-toplevel)"
conda_dir="${root_dir}/conda"
env_dir="${root_dir}/env"
cd "${root_dir}"
# 1. Install conda at ./conda
if [ ! -d "${conda_dir}" ]; then
printf "* Installing conda\n"
export tmp_conda="$(echo $conda_dir | tr '/' '\\')"
export miniconda_exe="$(echo $root_dir | tr '/' '\\')\\miniconda.exe"
curl --output miniconda.exe https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe -O
"$this_dir/install_conda.bat"
unset tmp_conda
unset miniconda_exe
fi
eval "$(${conda_dir}/Scripts/conda.exe 'shell.bash' 'hook')"
# 2. Create test environment at ./env
if [ ! -d "${env_dir}" ]; then
printf "* Creating a test environment\n"
conda create --prefix "${env_dir}" -y python="$PYTHON_VERSION"
fi
conda activate "${env_dir}"
# 3. Install Conda dependencies
printf "* Installing dependencies (except PyTorch)\n"
conda env update --file "${this_dir}/environment.yml" --prune
"""Test numerical consistency among single input and batched input."""
import unittest
import platform
import torch
import torchaudio
import torchaudio.functional as F
......@@ -206,6 +207,7 @@ class TestTransforms(unittest.TestCase):
computed = torchaudio.transforms.MelSpectrogram()(waveform.repeat(3, 1, 1))
torch.testing.assert_allclose(computed, expected)
@unittest.skipIf(platform.system() == "Windows", "Test is known to fail on Windows.")
def test_batch_mfcc(self):
test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(test_filepath)
......
......@@ -28,8 +28,9 @@ class TORCHAUDIODS(Dataset):
return len(self.data)
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
class Test_DataLoader(unittest.TestCase):
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_1(self):
expected_size = (2, 1, 16000)
ds = TORCHAUDIODS()
......@@ -39,5 +40,4 @@ class Test_DataLoader(unittest.TestCase):
if __name__ == '__main__':
with AudioBackendScope("sox"):
unittest.main()
unittest.main()
......@@ -26,10 +26,12 @@ class TestDatasets(unittest.TestCase):
data = LIBRISPEECH(self.path, "dev-clean")
data[0]
@unittest.skipIf("sox" not in common_utils.BACKENDS, "sox not available")
def test_commonvoice(self):
data = COMMONVOICE(self.path, url="tatar")
data[0]
@unittest.skipIf("sox" not in common_utils.BACKENDS, "sox not available")
def test_commonvoice_diskcache(self):
data = COMMONVOICE(self.path, url="tatar")
data = diskcache_iterator(data)
......@@ -38,6 +40,7 @@ class TestDatasets(unittest.TestCase):
# Load
data[0]
@unittest.skipIf("sox" not in common_utils.BACKENDS, "sox not available")
def test_commonvoice_bg(self):
data = COMMONVOICE(self.path, url="tatar")
data = bg_iterator(data, 5)
......
......@@ -7,10 +7,11 @@ import common_utils
from common_utils import AudioBackendScope, BACKENDS
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
class Test_SoxEffectsChain(unittest.TestCase):
test_filepath = common_utils.get_asset_path("steam-train-whistle-daniel_simon.mp3")
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_single_channel(self):
fn_sine = common_utils.get_asset_path("sinewave.wav")
E = torchaudio.sox_effects.SoxEffectsChain()
......@@ -20,6 +21,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
# check if effects worked
# print(x.size())
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_rate_channels(self):
target_rate = 16000
target_channels = 1
......@@ -32,6 +35,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
self.assertEqual(sr, target_rate)
self.assertEqual(x.size(0), target_channels)
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_lowpass_speed(self):
speed = .8
si, _ = torchaudio.info(self.test_filepath)
......@@ -44,6 +49,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
# check if effects worked
self.assertEqual(x.size(1), int((si.length / si.channels) / speed))
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_ulaw_and_siginfo(self):
si_out = torchaudio.sox_signalinfo_t()
ei_out = torchaudio.sox_encodinginfo_t()
......@@ -61,6 +68,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
self.assertLess(x.unique().size(0), 2**8 + 1)
self.assertEqual(x.numel(), si_in.length)
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_band_chorus(self):
si_in, ei_in = torchaudio.info(self.test_filepath)
ei_in.encoding = torchaudio.get_sox_encoding_t(1)
......@@ -75,6 +84,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
self.assertEqual(x.size(0), si_in.channels)
self.assertGreaterEqual(x.size(1) * x.size(0), si_in.length)
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_synth(self):
si_in, ei_in = torchaudio.info(self.test_filepath)
len_in_seconds = si_in.length / si_in.channels / si_in.rate
......@@ -88,6 +99,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
self.assertEqual(x.size(0), si_in.channels)
self.assertEqual(si_in.length, x.size(0) * x.size(1))
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_gain(self):
E = torchaudio.sox_effects.SoxEffectsChain()
E.set_input_file(self.test_filepath)
......@@ -111,6 +124,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
E.clear_chain()
self.assertLess(x.abs().max().item(), 1.)
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_tempo_or_speed(self):
tempo = .8
si, _ = torchaudio.info(self.test_filepath)
......@@ -144,6 +159,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
# check if effect worked
self.assertAlmostEqual(x.size(1), math.ceil((si.length / si.channels) / speed), delta=1)
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_trim(self):
x_orig, _ = torchaudio.load(self.test_filepath)
offset = "10000s"
......@@ -157,6 +174,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
# check if effect worked
self.assertTrue(x.allclose(x_orig[:, offset_int:(offset_int + num_frames_int)], rtol=1e-4, atol=1e-4))
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_silence_contrast(self):
si, _ = torchaudio.info(self.test_filepath)
E = torchaudio.sox_effects.SoxEffectsChain()
......@@ -167,6 +186,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
# check if effect worked
self.assertLess(x.numel(), si.length)
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_reverse(self):
x_orig, _ = torchaudio.load(self.test_filepath)
E = torchaudio.sox_effects.SoxEffectsChain()
......@@ -177,6 +198,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
rev_idx = torch.LongTensor(range(x_orig.size(1))[::-1])
self.assertTrue(x_orig.allclose(x_rev[:, rev_idx], rtol=1e-5, atol=2e-5))
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_compand_fade(self):
E = torchaudio.sox_effects.SoxEffectsChain()
E.set_input_file(self.test_filepath)
......@@ -186,6 +209,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
# check if effect worked
# print(x.size())
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_biquad_delay(self):
si, _ = torchaudio.info(self.test_filepath)
E = torchaudio.sox_effects.SoxEffectsChain()
......@@ -197,6 +222,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
# check if effect worked
self.assertTrue(x.size(1) == (si.length / si.channels) + 15000)
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_invalid_effect_name(self):
E = torchaudio.sox_effects.SoxEffectsChain()
E.set_input_file(self.test_filepath)
......@@ -204,6 +231,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
with self.assertRaises(LookupError):
E.append_effect_to_chain("special", [""])
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_unimplemented_effect(self):
E = torchaudio.sox_effects.SoxEffectsChain()
E.set_input_file(self.test_filepath)
......@@ -211,6 +240,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
with self.assertRaises(NotImplementedError):
E.append_effect_to_chain("spectrogram", [""])
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_invalid_effect_options(self):
E = torchaudio.sox_effects.SoxEffectsChain()
E.set_input_file(self.test_filepath)
......@@ -219,6 +250,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
with self.assertRaises(RuntimeError):
E.sox_build_flow_effects()
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_fade(self):
x_orig, _ = torchaudio.load(self.test_filepath)
fade_in_len = 44100
......@@ -235,6 +268,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
# check if effect worked
self.assertTrue(x.allclose(fade(x_orig), rtol=1e-4, atol=1e-4))
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_vol(self):
x_orig, _ = torchaudio.load(self.test_filepath)
......@@ -249,6 +284,8 @@ class Test_SoxEffectsChain(unittest.TestCase):
# check if effect worked
self.assertTrue(x.allclose(z, rtol=1e-4, atol=1e-4))
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
@AudioBackendScope("sox")
def test_vad(self):
sample_files = [
common_utils.get_asset_path("vad-go-stereo-44100.wav"),
......@@ -269,5 +306,4 @@ class Test_SoxEffectsChain(unittest.TestCase):
if __name__ == '__main__':
with AudioBackendScope("sox"):
unittest.main()
unittest.main()
......@@ -80,7 +80,7 @@ class _FunctionalTestMixin:
self._assert_consistency(func, tensor)
def test_detect_pitch_frequency(self):
filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.mp3')
filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(filepath)
def func(tensor):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment