Skip to content

Commit b1e3159

Browse files
committed
fixup! Tweak TempDirMixin
1 parent b9f8732 commit b1e3159

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

test/sox_io_backend/sox_utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ def gen_audio_file(
3131
'Use get_wav_data and save_wav to generate wav file for accurate result.')
3232
command = [
3333
'sox',
34-
'-V', # verbose
34+
'-V3', # verbose
35+
'-R',
36+
# -R is supposed to be repeatable, though the implementation looks suspicious
37+
# and not setting the seed to a fixed value.
38+
# https://fossies.org/dox/sox-14.4.2/sox_8c_source.html
39+
# search "sox_globals.repeatable"
3540
]
3641
if bit_depth is not None:
3742
command += ['--bits', str(bit_depth)]
@@ -64,7 +69,7 @@ def convert_audio_file(
6469
src_path, dst_path,
6570
*, bit_depth=None, compression=None):
6671
"""Convert audio file with `sox` command."""
67-
command = ['sox', '-V', str(src_path)]
72+
command = ['sox', '-V3', '-R', str(src_path)]
6873
if bit_depth is not None:
6974
command += ['--bits', str(bit_depth)]
7075
if compression is not None:

test/sox_io_backend/test_info.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_wav(self, dtype, sample_rate, num_channels):
4444
def test_wav_multiple_channels(self, dtype, sample_rate, num_channels):
4545
"""`sox_io_backend.info` can check wav file with channels more than 2 correctly"""
4646
duration = 1
47-
path = self.get_temp_path(f'data.wav')
47+
path = self.get_temp_path('data.wav')
4848
data = get_wav_data(dtype, num_channels, normalize=False, num_frames=duration * sample_rate)
4949
save_wav(path, data, sample_rate)
5050
info = sox_io_backend.info(path)
@@ -60,7 +60,7 @@ def test_wav_multiple_channels(self, dtype, sample_rate, num_channels):
6060
def test_mp3(self, sample_rate, num_channels, bit_rate):
6161
"""`sox_io_backend.info` can check mp3 file correctly"""
6262
duration = 1
63-
path = self.get_temp_path(f'data.mp3')
63+
path = self.get_temp_path('data.mp3')
6464
sox_utils.gen_audio_file(
6565
path, sample_rate, num_channels,
6666
compression=bit_rate, duration=duration,
@@ -79,7 +79,7 @@ def test_mp3(self, sample_rate, num_channels, bit_rate):
7979
def test_flac(self, sample_rate, num_channels, compression_level):
8080
"""`sox_io_backend.info` can check flac file correctly"""
8181
duration = 1
82-
path = self.get_temp_path(f'data.flac')
82+
path = self.get_temp_path('data.flac')
8383
sox_utils.gen_audio_file(
8484
path, sample_rate, num_channels,
8585
compression=compression_level, duration=duration,
@@ -97,7 +97,7 @@ def test_flac(self, sample_rate, num_channels, compression_level):
9797
def test_vorbis(self, sample_rate, num_channels, quality_level):
9898
"""`sox_io_backend.info` can check vorbis file correctly"""
9999
duration = 1
100-
path = self.get_temp_path(f'data.vorbis')
100+
path = self.get_temp_path('data.vorbis')
101101
sox_utils.gen_audio_file(
102102
path, sample_rate, num_channels,
103103
compression=quality_level, duration=duration,

test/sox_io_backend/test_load.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def assert_wav(self, dtype, sample_rate, num_channels, normalize, duration):
2424
2525
Wav data loaded with sox_io backend should match those with scipy
2626
"""
27-
path = self.get_temp_path(f'reference.wav')
27+
path = self.get_temp_path('reference.wav')
2828
data = get_wav_data(dtype, num_channels, normalize=normalize, num_frames=duration * sample_rate)
2929
save_wav(path, data, sample_rate)
3030
expected = load_wav(path, normalize=normalize)[0]

test/sox_io_backend/test_roundtrip.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ class TestRoundTripIO(TempDirMixin, PytorchTestCase):
2323
['float32', 'int32', 'int16', 'uint8'],
2424
[8000, 16000],
2525
[1, 2],
26-
[False, True]
2726
)), name_func=get_test_name)
28-
def test_roundtrip_wav(self, dtype, sample_rate, num_channels, normalize):
27+
def test_wav(self, dtype, sample_rate, num_channels):
2928
"""save/load round trip should not degrade data for wav formats"""
30-
original = get_wav_data(dtype, num_channels, normalize=normalize)
29+
original = get_wav_data(dtype, num_channels, normalize=False)
3130
data = original
3231
for i in range(10):
3332
path = self.get_temp_path(f'{i}.wav')
3433
sox_io_backend.save(path, data, sample_rate)
35-
data, sr = sox_io_backend.load(path, normalize=normalize)
34+
data, sr = sox_io_backend.load(path, normalize=False)
3635
assert sr == sample_rate
3736
self.assertEqual(original, data)
3837

@@ -41,7 +40,7 @@ def test_roundtrip_wav(self, dtype, sample_rate, num_channels, normalize):
4140
[1, 2],
4241
list(range(9)),
4342
)), name_func=get_test_name)
44-
def test_roundtrip_flac(self, sample_rate, num_channels, compression_level):
43+
def test_flac(self, sample_rate, num_channels, compression_level):
4544
"""save/load round trip should not degrade data for flac formats"""
4645
original = get_wav_data('float32', num_channels)
4746
data = original

test/sox_io_backend/test_save.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def assert_wav(self, dtype, sample_rate, num_channels, num_frames):
2424
path = self.get_temp_path('data.wav')
2525
expected = get_wav_data(dtype, num_channels, num_frames=num_frames)
2626
sox_io_backend.save(path, expected, sample_rate)
27-
found = load_wav(path)[0]
27+
found, sr = load_wav(path)[0]
28+
assert sample_rate == sr
2829
self.assertEqual(found, expected)
2930

3031
def assert_mp3(self, sample_rate, num_channels, bit_rate, duration):

0 commit comments

Comments
 (0)