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
d92de5b9
Commit
d92de5b9
authored
May 24, 2019
by
jamarshon
Committed by
cpuhrsch
May 24, 2019
Browse files
Setup Travis CI so that unit tests are run automatically (#117)
parent
883f2428
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
185 additions
and
28 deletions
+185
-28
.travis.yml
.travis.yml
+26
-13
README.md
README.md
+2
-0
build_tools/travis/install.sh
build_tools/travis/install.sh
+60
-0
build_tools/travis/test_script.sh
build_tools/travis/test_script.sh
+36
-0
requirements.txt
requirements.txt
+12
-0
test/common_utils.py
test/common_utils.py
+18
-0
test/test.py
test/test.py
+2
-1
test/test_dataloader.py
test/test_dataloader.py
+13
-8
test/test_kaldi_io.py
test/test_kaldi_io.py
+2
-1
test/test_legacy.py
test/test_legacy.py
+2
-1
test/test_sox_effects.py
test/test_sox_effects.py
+10
-3
test/test_transforms.py
test/test_transforms.py
+2
-1
No files found.
.travis.yml
View file @
d92de5b9
language
:
python
# note dist: 'trusty' does not work here
dist
:
xenial
language
:
python
# cache miniconda installer and similar files
cache
:
directories
:
-
/home/travis/download
# This matrix tests that the code works on Python 3.5, 3.6, and passes lint.
matrix
:
fast_finish
:
true
include
:
-
python
:
"
3.5"
-
env
:
PYTHON_VERSION="3.5"
-
env
:
PYTHON_VERSION="3.6"
-
env
:
PYTHON_VERSION="3.5" RUN_FLAKE8="true" SKIP_TESTS="true"
addons
:
apt
:
packages
:
sox
libsox-dev
libsox-fmt-all
libpython3.5-dev
install
:
-
pip install torch
-
python setup.py install
script
:
-
python -m unittest
notifications
:
email
:
false
install
:
source build_tools/travis/install.sh
script
:
bash build_tools/travis/test_script.sh
README.md
View file @
d92de5b9
torchaudio: an audio library for PyTorch
================================================
[

](https://travis-ci.org/pytorch/audio)
-
[
Support audio I/O (Load files, Save files)
](
http://pytorch.org/audio/
)
-
Load the following formats into a torch Tensor
-
mp3, wav, aac, ogg, flac, avr, cdda, cvs/vms,
...
...
build_tools/travis/install.sh
0 → 100644
View file @
d92de5b9
#!/bin/bash
# This script is meant to be called by the "install" step defined in
# .travis.yml. See http://docs.travis-ci.com/ for more details.
# The behavior of the script is controlled by environment variabled defined
# in the .travis.yml in the top level folder of the project.
set
-e
echo
'List files from cached directories'
if
[
-d
$HOME
/download
]
;
then
echo
'download:'
ls
$HOME
/download
fi
if
[
-d
$HOME
/.cache/pip
]
;
then
echo
'pip:'
ls
$HOME
/.cache/pip
fi
# Deactivate the travis-provided virtual environment and setup a
# conda-based environment instead
deactivate
# Add the miniconda bin directory to $PATH
export
PATH
=
/home/travis/miniconda3/bin:
$PATH
echo
$PATH
# Use the miniconda installer for setup of conda itself
pushd
.
cd
mkdir
-p
download
cd
download
if
[[
!
-f
/home/travis/miniconda3/bin/activate
]]
then
if
[[
!
-f
miniconda.sh
]]
then
wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
\
-O
miniconda.sh
fi
chmod
+x miniconda.sh
&&
./miniconda.sh
-b
-f
conda update
--yes
conda
echo
"Creating environment to run tests in."
conda create
-n
testenv
--yes
python
=
"
$PYTHON_VERSION
"
fi
cd
..
popd
# Activate the python environment we created.
source
activate testenv
# Install requirements via pip in our conda environment
pip
install
-r
requirements.txt
# Install the following only if running tests
if
[[
"
$SKIP_TESTS
"
!=
"true"
]]
;
then
# PyTorch
conda
install
--yes
pytorch
-c
pytorch
# TorchAudio CPP Extensions
pip
install
.
fi
build_tools/travis/test_script.sh
0 → 100644
View file @
d92de5b9
#!/bin/bash
# This script is meant to be called by the "script" step defined in
# .travis.yml. See http://docs.travis-ci.com/ for more details.
# The behavior of the script is controlled by environment variabled defined
# in the .travis.yml in the top level folder of the project.
set
-e
python
--version
run_tests
()
{
# find all the test files that match "test*.py"
TEST_FILES
=
"
$(
find
test
/
-type
f
-name
"test*.py"
|
sort
)
"
echo
"Test files are:"
echo
$TEST_FILES
echo
"Executing tests:"
EXIT_STATUS
=
0
for
FILE
in
$TEST_FILES
;
do
# run each file on a separate process. if one fails, just keep going and
# return the final exit status.
python
-m
unittest
-v
$FILE
STATUS
=
$?
EXIT_STATUS
=
"
$((
$EXIT_STATUS
+
STATUS
))
"
done
echo
"Done, exit status:
$EXIT_STATUS
"
exit
$EXIT_STATUS
}
if
[[
"
$RUN_FLAKE8
"
==
"true"
]]
;
then
flake8
fi
if
[[
"
$SKIP_TESTS
"
!=
"true"
]]
;
then
run_tests
fi
requirements.txt
0 → 100644
View file @
d92de5b9
# Optional for torchaudio.kaldi_io
numpy
kaldi_io
# Required for tests only:
# Style-checking for PEP8
flake8
# Used for comparison of outputs in tests
librosa
scipy
test/common_utils.py
0 → 100644
View file @
d92de5b9
import
os
from
shutil
import
copytree
import
tempfile
TEST_DIR_PATH
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
def
create_temp_assets_dir
():
"""
Creates a temporary directory and moves all files from test/assets there.
Returns a Tuple[string, TemporaryDirectory] which is the folder path
and object.
"""
tmp_dir
=
tempfile
.
TemporaryDirectory
()
copytree
(
os
.
path
.
join
(
TEST_DIR_PATH
,
"assets"
),
os
.
path
.
join
(
tmp_dir
.
name
,
"assets"
))
return
tmp_dir
.
name
,
tmp_dir
test/test.py
View file @
d92de5b9
import
unittest
import
test.common_utils
import
torch
import
torchaudio
import
math
...
...
@@ -6,7 +7,7 @@ import os
class
Test_LoadSave
(
unittest
.
TestCase
):
test_dirpath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)
)
test_dirpath
,
test_dir
=
test
.
common_utils
.
create_temp_assets_dir
(
)
test_filepath
=
os
.
path
.
join
(
test_dirpath
,
"assets"
,
"steam-train-whistle-daniel_simon.mp3"
)
...
...
test/test_dataloader.py
View file @
d92de5b9
import
unittest
import
test.common_utils
import
torch
import
torch.nn
as
nn
from
torch.utils.data
import
Dataset
,
DataLoader
...
...
@@ -9,11 +10,12 @@ import os
class
TORCHAUDIODS
(
Dataset
):
test_dirpath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)
)
test_dirpath
,
test_dir
=
test
.
common_utils
.
create_temp_assets_dir
(
)
def
__init__
(
self
):
self
.
asset_dirpath
=
os
.
path
.
join
(
self
.
test_dirpath
,
"assets"
)
self
.
data
=
[
os
.
path
.
join
(
self
.
asset_dirpath
,
fn
)
for
fn
in
os
.
listdir
(
self
.
asset_dirpath
)]
sound_files
=
list
(
filter
(
lambda
x
:
'.wav'
in
x
or
'.mp3'
in
x
,
os
.
listdir
(
self
.
asset_dirpath
)))
self
.
data
=
[
os
.
path
.
join
(
self
.
asset_dirpath
,
fn
)
for
fn
in
sound_files
]
self
.
si
,
self
.
ei
=
torchaudio
.
info
(
os
.
path
.
join
(
self
.
asset_dirpath
,
"sinewave.wav"
))
self
.
si
.
precision
=
16
self
.
E
=
torchaudio
.
sox_effects
.
SoxEffectsChain
()
...
...
@@ -32,17 +34,20 @@ class TORCHAUDIODS(Dataset):
class
Test_DataLoader
(
unittest
.
TestCase
):
@
classmethod
def
setUpClass
(
cls
):
torchaudio
.
initialize_sox
()
@
classmethod
def
tearDownClass
(
cls
):
torchaudio
.
shutdown_sox
()
def
test_1
(
self
):
expected_size
=
(
2
,
1
,
16000
)
ds
=
TORCHAUDIODS
()
dl
=
DataLoader
(
ds
,
batch_size
=
2
)
for
x
in
dl
:
# print(x.size())
continue
self
.
assertTrue
(
x
.
size
()
==
expected_size
)
if
__name__
==
'__main__'
:
torchaudio
.
initialize_sox
()
unittest
.
main
()
torchaudio
.
shutdown_sox
()
test/test_kaldi_io.py
View file @
d92de5b9
...
...
@@ -2,12 +2,13 @@ import os
import
torch
import
torchaudio.kaldi_io
as
kio
import
unittest
import
test.common_utils
class
KaldiIOTest
(
unittest
.
TestCase
):
data1
=
[[
1
,
2
,
3
],
[
11
,
12
,
13
],
[
21
,
22
,
23
]]
data2
=
[[
31
,
32
,
33
],
[
41
,
42
,
43
],
[
51
,
52
,
53
]]
test_dirpath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)
)
test_dirpath
,
test_dir
=
test
.
common_utils
.
create_temp_assets_dir
(
)
def
_test_helper
(
self
,
file_name
,
expected_data
,
fn
,
expected_dtype
):
""" Takes a file_name to the input data and a function fn to extract the
...
...
test/test_legacy.py
View file @
d92de5b9
import
unittest
import
test.common_utils
import
torch
import
torchaudio
from
torchaudio.legacy
import
save
,
load
...
...
@@ -7,7 +8,7 @@ import os
class
Test_LoadSave
(
unittest
.
TestCase
):
test_dirpath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)
)
test_dirpath
,
test_dir
=
test
.
common_utils
.
create_temp_assets_dir
(
)
test_filepath
=
os
.
path
.
join
(
test_dirpath
,
"assets"
,
"steam-train-whistle-daniel_simon.mp3"
)
...
...
test/test_sox_effects.py
View file @
d92de5b9
import
unittest
import
test.common_utils
import
torch
import
torchaudio
import
math
...
...
@@ -6,10 +7,18 @@ import os
class
Test_SoxEffectsChain
(
unittest
.
TestCase
):
test_dirpath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)
)
test_dirpath
,
test_dir
=
test
.
common_utils
.
create_temp_assets_dir
(
)
test_filepath
=
os
.
path
.
join
(
test_dirpath
,
"assets"
,
"steam-train-whistle-daniel_simon.mp3"
)
@
classmethod
def
setUpClass
(
cls
):
torchaudio
.
initialize_sox
()
@
classmethod
def
tearDownClass
(
cls
):
torchaudio
.
shutdown_sox
()
def
test_single_channel
(
self
):
fn_sine
=
os
.
path
.
join
(
self
.
test_dirpath
,
"assets"
,
"sinewave.wav"
)
E
=
torchaudio
.
sox_effects
.
SoxEffectsChain
()
...
...
@@ -220,6 +229,4 @@ class Test_SoxEffectsChain(unittest.TestCase):
if
__name__
==
'__main__'
:
torchaudio
.
initialize_sox
()
unittest
.
main
()
torchaudio
.
shutdown_sox
()
test/test_transforms.py
View file @
d92de5b9
...
...
@@ -7,6 +7,7 @@ import torchaudio
from
torchaudio.common_utils
import
IMPORT_LIBROSA
,
IMPORT_SCIPY
import
torchaudio.transforms
as
transforms
import
unittest
import
test.common_utils
if
IMPORT_LIBROSA
:
import
librosa
...
...
@@ -25,7 +26,7 @@ class Tester(unittest.TestCase):
sig
.
unsqueeze_
(
1
)
# (64000, 1)
sig
=
(
sig
*
volume
*
2
**
31
).
long
()
# file for stereo stft test
test_dirpath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)
)
test_dirpath
,
test_dir
=
test
.
common_utils
.
create_temp_assets_dir
(
)
test_filepath
=
os
.
path
.
join
(
test_dirpath
,
"assets"
,
"steam-train-whistle-daniel_simon.mp3"
)
...
...
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