"docs/source/api/vscode:/vscode.git/clone" did not exist on "b3d3a2c4b0e04320bd9c0cedeb7ed70813d2d824"
Unverified Commit 38287a75 authored by moto's avatar moto Committed by GitHub
Browse files

Only initialize sox once and never shutdown in test (#562)

parent 9d40302d
...@@ -78,3 +78,14 @@ def filter_backends_with_mp3(backends): ...@@ -78,3 +78,14 @@ def filter_backends_with_mp3(backends):
BACKENDS_MP3 = filter_backends_with_mp3(BACKENDS) BACKENDS_MP3 = filter_backends_with_mp3(BACKENDS)
_IS_SOX_INITIALIZED = False
def initialize_sox():
"""Initialize sox backend only if it has not yet."""
global _IS_SOX_INITIALIZED
if not _IS_SOX_INITIALIZED:
torchaudio.initialize_sox()
_IS_SOX_INITIALIZED = True
...@@ -7,9 +7,7 @@ import common_utils ...@@ -7,9 +7,7 @@ import common_utils
from common_utils import AudioBackendScope, BACKENDS from common_utils import AudioBackendScope, BACKENDS
@unittest.skipIf("sox" not in BACKENDS, "sox not available")
class TORCHAUDIODS(Dataset): class TORCHAUDIODS(Dataset):
def __init__(self): def __init__(self):
sound_files = ["sinewave.wav", "steam-train-whistle-daniel_simon.mp3"] sound_files = ["sinewave.wav", "steam-train-whistle-daniel_simon.mp3"]
self.data = [common_utils.get_asset_path(fn) for fn in sound_files] self.data = [common_utils.get_asset_path(fn) for fn in sound_files]
...@@ -34,11 +32,7 @@ class TORCHAUDIODS(Dataset): ...@@ -34,11 +32,7 @@ class TORCHAUDIODS(Dataset):
class Test_DataLoader(unittest.TestCase): class Test_DataLoader(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
torchaudio.initialize_sox() common_utils.initialize_sox()
@classmethod
def tearDownClass(cls):
torchaudio.shutdown_sox()
def test_1(self): def test_1(self):
expected_size = (2, 1, 16000) expected_size = (2, 1, 16000)
...@@ -47,6 +41,7 @@ class Test_DataLoader(unittest.TestCase): ...@@ -47,6 +41,7 @@ class Test_DataLoader(unittest.TestCase):
for x in dl: for x in dl:
self.assertTrue(x.size() == expected_size) self.assertTrue(x.size() == expected_size)
if __name__ == '__main__': if __name__ == '__main__':
with AudioBackendScope("sox"): with AudioBackendScope("sox"):
unittest.main() unittest.main()
...@@ -13,11 +13,7 @@ class Test_SoxEffectsChain(unittest.TestCase): ...@@ -13,11 +13,7 @@ class Test_SoxEffectsChain(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
torchaudio.initialize_sox() common_utils.initialize_sox()
@classmethod
def tearDownClass(cls):
torchaudio.shutdown_sox()
def test_single_channel(self): def test_single_channel(self):
fn_sine = common_utils.get_asset_path("sinewave.wav") fn_sine = common_utils.get_asset_path("sinewave.wav")
......
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