DATAROOTDIR?=$(PREFIX)/share
MANDIR?=$(DATAROOTDIR)/man
-# default nose2 command
-NOSE2?=nose2 -N 4 --verbose
+# default python test command
+PYTEST?=pytest --verbose
SOX=sox
test_python: export PYTHONPATH=$(PYDESTDIR)/$(LIBDIR)
test_python: local_dylib
# run test with installed package
- # ./python/tests/run_all_tests --verbose
- # run with nose2, multiple processes
- $(NOSE2)
+ $(PYTEST)
clean_python:
./setup.py clean
uninstall_python \
check_clean_python
+ coverage_cycle: coverage_zero_counters coverage_report
+
+ coverage_zero_counters:
+ lcov --zerocounters --directory .
+
coverage: export CFLAGS=--coverage
coverage: export LDFLAGS=--coverage
coverage: export PYTHONPATH=$(PWD)/python/lib
clean_python clean distclean build local_dylib
lcov --capture --no-external --directory . --output-file build/coverage_lib.info
pip install -v -e .
- coverage run `which nose2`
+ coverage run `which pytest`
lcov --capture --no-external --directory . --output-file build/coverage_python.info
lcov -a build/coverage_python.info -a build/coverage_lib.info -o build/coverage.info
+ # make sure we don't build the doc, which builds a temporary python module
+ coverage_report: export WAFOPTS += --disable-docs
coverage_report: coverage
genhtml build/coverage.info --output-directory lcov_html
mkdir -p gcovr_html/
#! /usr/bin/env python
-from unittest import main
from numpy.testing import TestCase
from numpy.testing import assert_equal, assert_almost_equal
import numpy as np
assert_almost_equal ( r[0], impulse, decimal = 6)
assert_almost_equal ( r[1:], 0)
+ class aubio_fft_odd_sizes(TestCase):
+
+ def test_reconstruct_with_odd_size(self):
+ win_s = 29
+ self.recontruct(win_s, 'odd sizes not supported')
+
+ def test_reconstruct_with_radix15(self):
+ win_s = 2 ** 4 * 15
+ self.recontruct(win_s, 'radix 15 supported')
+
+ def test_reconstruct_with_radix5(self):
+ win_s = 2 ** 4 * 5
+ self.recontruct(win_s, 'radix 5 supported')
+
+ def test_reconstruct_with_radix3(self):
+ win_s = 2 ** 4 * 3
+ self.recontruct(win_s, 'radix 3 supported')
+
+ def recontruct(self, win_s, skipMessage):
+ try:
+ f = fft(win_s)
+ except RuntimeError:
+ self.skipTest(skipMessage)
+ input_signal = fvec(win_s)
+ input_signal[win_s//2] = 1
+ c = f(input_signal)
+ output_signal = f.rdo(c)
+ assert_almost_equal(input_signal, output_signal)
+
+ class aubio_fft_wrong_params(TestCase):
+
def test_large_input_timegrain(self):
win_s = 1024
f = fft(win_s)
with self.assertRaises(ValueError):
f.rdo(s)
- class aubio_fft_wrong_params(TestCase):
-
def test_wrong_buf_size(self):
win_s = -1
with self.assertRaises(ValueError):
fft(win_s)
- def test_buf_size_not_power_of_two(self):
- # when compiled with fftw3, aubio supports non power of two fft sizes
- win_s = 320
- try:
- with self.assertRaises(RuntimeError):
- fft(win_s)
- except AssertionError:
- self.skipTest('creating aubio.fft with size %d did not fail' % win_s)
-
def test_buf_size_too_small(self):
win_s = 1
with self.assertRaises(RuntimeError):
fft(win_s)
if __name__ == '__main__':
+ from unittest import main
main()
import numpy as np
from numpy.testing import TestCase, assert_equal, assert_almost_equal
+from _tools import assert_warns
from aubio import fvec, cvec, filterbank, float_type
-import warnings
-warnings.filterwarnings('ignore', category=UserWarning, append=True)
-
class aubio_filterbank_mel_test_case(TestCase):
def test_slaney(self):
samplerate = 22050
freq_list = [0, samplerate//4, samplerate // 2 + 1]
f = filterbank(len(freq_list)-2, 1024)
- # TODO add assert_warns
- f.set_triangle_bands(fvec(freq_list), samplerate)
+ with assert_warns(UserWarning):
+ f.set_triangle_bands(fvec(freq_list), samplerate)
def test_triangle_freqs_with_not_enough_filters(self):
"""make sure set_triangle_bands warns when not enough filters"""
samplerate = 22050
freq_list = [0, 100, 1000, 4000, 8000, 10000]
f = filterbank(len(freq_list)-3, 1024)
- # TODO add assert_warns
- f.set_triangle_bands(fvec(freq_list), samplerate)
+ with assert_warns(UserWarning):
+ f.set_triangle_bands(fvec(freq_list), samplerate)
def test_triangle_freqs_with_too_many_filters(self):
"""make sure set_triangle_bands warns when too many filters"""
samplerate = 22050
freq_list = [0, 100, 1000, 4000, 8000, 10000]
f = filterbank(len(freq_list)-1, 1024)
- # TODO add assert_warns
- f.set_triangle_bands(fvec(freq_list), samplerate)
+ with assert_warns(UserWarning):
+ f.set_triangle_bands(fvec(freq_list), samplerate)
def test_triangle_freqs_with_double_value(self):
"""make sure set_triangle_bands works with 2 duplicate freqs"""
samplerate = 22050
freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
f = filterbank(len(freq_list)-2, 1024)
- # TODO add assert_warns
- f.set_triangle_bands(fvec(freq_list), samplerate)
+ with assert_warns(UserWarning):
+ f.set_triangle_bands(fvec(freq_list), samplerate)
def test_triangle_freqs_with_triple(self):
"""make sure set_triangle_bands works with 3 duplicate freqs"""
samplerate = 22050
freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
f = filterbank(len(freq_list)-2, 1024)
- # TODO add assert_warns
- f.set_triangle_bands(fvec(freq_list), samplerate)
+ with assert_warns(UserWarning):
+ f.set_triangle_bands(fvec(freq_list), samplerate)
+
+ def test_triangle_freqs_without_norm(self):
+ """make sure set_triangle_bands works without """
+ samplerate = 22050
+ freq_list = fvec([0, 100, 1000, 10000])
+ f = filterbank(len(freq_list) - 2, 1024)
+ f.set_norm(0)
+ f.set_triangle_bands(freq_list, samplerate)
+ expected = f.get_coeffs()
+ f.set_norm(1)
+ f.set_triangle_bands(fvec(freq_list), samplerate)
+ assert_almost_equal(f.get_coeffs().T,
+ expected.T * 2. / (freq_list[2:] - freq_list[:-2]))
+
+ def test_triangle_freqs_wrong_norm(self):
+ f = filterbank(10, 1024)
+ with self.assertRaises(ValueError):
+ f.set_norm(-1)
+
+ def test_triangle_freqs_with_power(self):
+ f = filterbank(9, 1024)
+ freqs = fvec([40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000,
+ 24000])
+ f.set_power(2)
+ f.set_triangle_bands(freqs, 48000)
+ spec = cvec(1024)
+ spec.norm[:] = .1
+ expected = fvec([0.02070313, 0.02138672, 0.02127604, 0.02135417,
+ 0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345])
+ expected /= 100.
+ assert_almost_equal(f(spec), expected)
+
+ def test_mel_coeffs(self):
+ f = filterbank(40, 1024)
+ f.set_mel_coeffs(44100, 0, 44100 / 2)
+
+ def test_zero_fmax(self):
+ f = filterbank(40, 1024)
+ f.set_mel_coeffs(44100, 0, 0)
+
+ def test_wrong_mel_coeffs(self):
+ f = filterbank(40, 1024)
+ with self.assertRaises(ValueError):
+ f.set_mel_coeffs_slaney(0)
+ with self.assertRaises(ValueError):
+ f.set_mel_coeffs(44100, 0, -44100 / 2)
+ with self.assertRaises(ValueError):
+ f.set_mel_coeffs(44100, -0.1, 44100 / 2)
+ with self.assertRaises(ValueError):
+ f.set_mel_coeffs(-44100, 0.1, 44100 / 2)
+ with self.assertRaises(ValueError):
+ f.set_mel_coeffs_htk(-1, 0, 0)
+
+ def test_mel_coeffs_htk(self):
+ f = filterbank(40, 1024)
+ f.set_mel_coeffs_htk(44100, 0, 44100 / 2)
+
+
if __name__ == '__main__':
- import nose2
- nose2.main()
+ from unittest import main
+ main()