|
7 | 7 | from torch.testing._internal.common_utils import TestCase |
8 | 8 | import torchaudio |
9 | 9 | import torchaudio.functional as F |
10 | | -from torchaudio.common_utils import IMPORT_LIBROSA |
| 10 | +from torchaudio.common_utils import _check_module_exists |
11 | 11 |
|
12 | | -if IMPORT_LIBROSA: |
| 12 | +LIBROSA_AVAILABLE = _check_module_exists('librosa') |
| 13 | + |
| 14 | +if LIBROSA_AVAILABLE: |
13 | 15 | import numpy as np |
14 | 16 | import librosa |
15 | 17 | import scipy |
|
19 | 21 | from . import common_utils |
20 | 22 |
|
21 | 23 |
|
22 | | -@unittest.skipIf(not IMPORT_LIBROSA, "Librosa not available") |
| 24 | +@unittest.skipIf(not LIBROSA_AVAILABLE, "Librosa not available") |
23 | 25 | class TestFunctional(TestCase): |
24 | 26 | """Test suite for functions in `functional` module.""" |
25 | 27 | def test_griffinlim(self): |
@@ -115,12 +117,8 @@ def test_amplitude_to_DB(self): |
115 | 117 | ]) |
116 | 118 | @pytest.mark.parametrize('rate', [0.5, 1.01, 1.3]) |
117 | 119 | @pytest.mark.parametrize('hop_length', [256]) |
| 120 | +@unittest.skipIf(not LIBROSA_AVAILABLE, "Librosa not available") |
118 | 121 | def test_phase_vocoder(complex_specgrams, rate, hop_length): |
119 | | - |
120 | | - # Using a decorator here causes parametrize to fail on Python 2 |
121 | | - if not IMPORT_LIBROSA: |
122 | | - raise unittest.SkipTest('Librosa is not available') |
123 | | - |
124 | 122 | # Due to cummulative sum, numerical error in using torch.float32 will |
125 | 123 | # result in bottom right values of the stretched sectrogram to not |
126 | 124 | # match with librosa. |
@@ -158,7 +156,7 @@ def _load_audio_asset(*asset_paths, **kwargs): |
158 | 156 | return sound, sample_rate |
159 | 157 |
|
160 | 158 |
|
161 | | -@unittest.skipIf(not IMPORT_LIBROSA, "Librosa not available") |
| 159 | +@unittest.skipIf(not LIBROSA_AVAILABLE, "Librosa not available") |
162 | 160 | class TestTransforms(TestCase): |
163 | 161 | """Test suite for functions in `transforms` module.""" |
164 | 162 | def assert_compatibilities(self, n_fft, hop_length, power, n_mels, n_mfcc, sample_rate): |
|
0 commit comments