Commit d92de5b9 authored by jamarshon's avatar jamarshon Committed by cpuhrsch
Browse files

Setup Travis CI so that unit tests are run automatically (#117)

parent 883f2428
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
torchaudio: an audio library for PyTorch
================================================
[![Build Status](https://travis-ci.org/pytorch/audio.svg?branch=master)](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,
......
#!/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
#!/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
# 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
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
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")
......
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()
......@@ -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
......
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")
......
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()
......@@ -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")
......
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