Showing the changes to python/tests (2 of 2 files). Show all
Unified · Split
| @@ -2,6 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | |
| 3 | 3 | import numpy as np |
| 4 | 4 | from numpy.testing import TestCase, assert_equal, assert_almost_equal |
| 5 | +from _tools import assert_warns | |
| 5 | 6 | |
| 6 | 7 | from aubio import cvec, filterbank, float_type |
| 7 | 8 | |
| @@ -28,7 +29,8 @@ class aubio_filterbank_mel_test_case(TestCase): · 20 unmodified lines | ||
| 28 | 29 | f = filterbank(9, 1024) |
| 29 | 30 | freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000] |
| 30 | 31 | freqs = np.array(freq_list, dtype = float_type) |
| 31 | − f.set_triangle_bands(freqs, 48000) | |
| 32 | + with assert_warns(UserWarning): | |
| 33 | + f.set_triangle_bands(freqs, 48000) | |
| 32 | 34 | assert_equal ( f(cvec(1024)), 0) |
| 33 | 35 | self.assertIsInstance(f.get_coeffs(), np.ndarray) |
| 34 | 36 | |
| @@ -36,7 +38,8 @@ class aubio_filterbank_mel_test_case(TestCase): · 1 unmodified line | ||
| 36 | 38 | f = filterbank(9, 1024) |
| 37 | 39 | freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000] |
| 38 | 40 | freqs = np.array(freq_list, dtype = float_type) |
| 39 | − f.set_triangle_bands(freqs, 48000) | |
| 41 | + with assert_warns(UserWarning): | |
| 42 | + f.set_triangle_bands(freqs, 48000) | |
| 40 | 43 | self.assertIsInstance(f.get_coeffs(), np.ndarray) |
| 41 | 44 | spec = cvec(1024) |
| 42 | 45 | spec.norm[:] = 1 |
| @@ -44,6 +47,37 @@ class aubio_filterbank_mel_test_case(TestCase): · 1 unmodified line | ||
| 44 | 47 | [ 0.02070313, 0.02138672, 0.02127604, 0.02135417, |
| 45 | 48 | 0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345]) |
| 46 | 49 | |
| 50 | + def test_triangle_freqs_normal(self): | |
| 51 | + """ create a filter with set_triangle_bands, normal mode """ | |
| 52 | + f = filterbank(3, 1024) | |
| 53 | + freq_list = [100, 1000, 10000, 15000, 20000] | |
| 54 | + freqs = np.array(freq_list, dtype = float_type) | |
| 55 | + f.set_triangle_bands(freqs, 44100) | |
| 56 | + | |
| 57 | + def test_triangle_freqs_too_long(self): | |
| 58 | + """ create a filter with freq_list too long """ | |
| 59 | + f = filterbank(2, 1024) | |
| 60 | + freq_list = [100, 1000, 10000, 15000, 20000] | |
| 61 | + freqs = np.array(freq_list, dtype = float_type) | |
| 62 | + with assert_warns(UserWarning): | |
| 63 | + f.set_triangle_bands(freqs, 44100) | |
| 64 | + | |
| 65 | + def test_triangle_freqs_too_short(self): | |
| 66 | + """ create a filter with freq_list too short """ | |
| 67 | + f = filterbank(4, 1024) | |
| 68 | + freq_list = [100, 1000, 10000, 15000, 20000] | |
| 69 | + freqs = np.array(freq_list, dtype = float_type) | |
| 70 | + with assert_warns(UserWarning): | |
| 71 | + f.set_triangle_bands(freqs, 44100) | |
| 72 | + | |
| 73 | + def test_above_nyquist(self): | |
| 74 | + """ create a filter with freq_list too short """ | |
| 75 | + f = filterbank(3, 1024) | |
| 76 | + freq_list = [100, 1000, 10000, 15000, 23000] | |
| 77 | + freqs = np.array(freq_list, dtype = float_type) | |
| 78 | + with assert_warns(UserWarning): | |
| 79 | + f.set_triangle_bands(freqs, 44100) | |
| 80 | + | |
| 47 | 81 | if __name__ == '__main__': |
| 48 | 82 | from unittest import main |
| 49 | 83 | main() |
| @@ -69,7 +69,7 @@ class Test_aubio_source_read: · 68 unmodified lines | ||
| 69 | 69 | read_frames = self.read_from_source(f) |
| 70 | 70 | if 'f_' in soundfile and samplerate == 0: |
| 71 | 71 | import re |
| 72 | − f = re.compile('.*_\([0:9]*f\)_.*') | |
| 72 | + f = re.compile(r'.*_\([0:9]*f\)_.*') | |
| 73 | 73 | match_f = re.findall('([0-9]*)f_', soundfile) |
| 74 | 74 | if len(match_f) == 1: |
| 75 | 75 | expected_frames = int(match_f[0]) |