Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Torchaudio
Commits
5085aeb9
Unverified
Commit
5085aeb9
authored
Jan 29, 2021
by
moto
Committed by
GitHub
Jan 29, 2021
Browse files
Add smoke test for sox_io fileobj (#1165)
parent
b152ee61
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
0 deletions
+68
-0
test/torchaudio_unittest/sox_io_backend/smoke_test.py
test/torchaudio_unittest/sox_io_backend/smoke_test.py
+68
-0
No files found.
test/torchaudio_unittest/sox_io_backend/smoke_test.py
View file @
5085aeb9
import
io
import
itertools
import
unittest
...
...
@@ -85,3 +86,70 @@ class SmokeTest(TempDirMixin, TorchaudioTestCase):
def
test_flac
(
self
,
sample_rate
,
num_channels
,
compression_level
):
"""Run smoke test on flac format"""
self
.
run_smoke_test
(
'flac'
,
sample_rate
,
num_channels
,
compression
=
compression_level
)
@
skipIfNoExtension
class
SmokeTestFileObj
(
TorchaudioTestCase
):
"""Run smoke test on various audio format
The purpose of this test suite is to verify that sox_io_backend functionalities do not exhibit
abnormal behaviors.
This test suite should be able to run without any additional tools (such as sox command),
however without such tools, the correctness of each function cannot be verified.
"""
def
run_smoke_test
(
self
,
ext
,
sample_rate
,
num_channels
,
*
,
compression
=
None
,
dtype
=
'float32'
):
duration
=
1
num_frames
=
sample_rate
*
duration
original
=
get_wav_data
(
dtype
,
num_channels
,
normalize
=
False
,
num_frames
=
num_frames
)
fileobj
=
io
.
BytesIO
()
# 1. run save
sox_io_backend
.
save
(
fileobj
,
original
,
sample_rate
,
compression
=
compression
,
format
=
ext
)
# 2. run info
fileobj
.
seek
(
0
)
info
=
sox_io_backend
.
info
(
fileobj
,
format
=
ext
)
assert
info
.
sample_rate
==
sample_rate
assert
info
.
num_channels
==
num_channels
# 3. run load
fileobj
.
seek
(
0
)
loaded
,
sr
=
sox_io_backend
.
load
(
fileobj
,
normalize
=
False
,
format
=
ext
)
assert
sr
==
sample_rate
assert
loaded
.
shape
[
0
]
==
num_channels
@
parameterized
.
expand
(
list
(
itertools
.
product
(
[
'float32'
,
'int32'
,
'int16'
,
'uint8'
],
[
8000
,
16000
],
[
1
,
2
],
)),
name_func
=
name_func
)
def
test_wav
(
self
,
dtype
,
sample_rate
,
num_channels
):
"""Run smoke test on wav format"""
self
.
run_smoke_test
(
'wav'
,
sample_rate
,
num_channels
,
dtype
=
dtype
)
@
parameterized
.
expand
(
list
(
itertools
.
product
(
[
8000
,
16000
],
[
1
,
2
],
[
-
4.2
,
-
0.2
,
0
,
0.2
,
96
,
128
,
160
,
192
,
224
,
256
,
320
],
)))
@
skipIfNoMP3
def
test_mp3
(
self
,
sample_rate
,
num_channels
,
bit_rate
):
"""Run smoke test on mp3 format"""
self
.
run_smoke_test
(
'mp3'
,
sample_rate
,
num_channels
,
compression
=
bit_rate
)
@
parameterized
.
expand
(
list
(
itertools
.
product
(
[
8000
,
16000
],
[
1
,
2
],
[
-
1
,
0
,
1
,
2
,
3
,
3.6
,
5
,
10
],
)))
def
test_vorbis
(
self
,
sample_rate
,
num_channels
,
quality_level
):
"""Run smoke test on vorbis format"""
self
.
run_smoke_test
(
'vorbis'
,
sample_rate
,
num_channels
,
compression
=
quality_level
)
@
parameterized
.
expand
(
list
(
itertools
.
product
(
[
8000
,
16000
],
[
1
,
2
],
list
(
range
(
9
)),
)),
name_func
=
name_func
)
def
test_flac
(
self
,
sample_rate
,
num_channels
,
compression_level
):
"""Run smoke test on flac format"""
self
.
run_smoke_test
(
'flac'
,
sample_rate
,
num_channels
,
compression
=
compression_level
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment