History

[tests] capture warnings from filterbank_mel, improve coverage

Paul Brossier committed 8 years ago

Commit 67024ff1 parent 5af36fa2 files · +37 −3Browse files

Showing the changes to python/tests (2 of 2 files). Show all

Unified · Split

2 files
  1. python/tests/test_filterbank_mel.py +36 −2
  2. python/tests/test_source.py +1 −1
python/tests/test_filterbank_mel.py+36−2
@@ -2,6 +2,7 @@ · 1 unmodified line
2 2
3import numpy as np3import numpy as np
4from numpy.testing import TestCase, assert_equal, assert_almost_equal4from numpy.testing import TestCase, assert_equal, assert_almost_equal
5from _tools import assert_warns
5 6
6from aubio import cvec, filterbank, float_type7from aubio import cvec, filterbank, float_type
7 8
@@ -28,7 +29,8 @@ class aubio_filterbank_mel_test_case(TestCase): · 20 unmodified lines
28 f = filterbank(9, 1024)29 f = filterbank(9, 1024)
29 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]30 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
30 freqs = np.array(freq_list, dtype = float_type)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 assert_equal ( f(cvec(1024)), 0)34 assert_equal ( f(cvec(1024)), 0)
33 self.assertIsInstance(f.get_coeffs(), np.ndarray)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 f = filterbank(9, 1024)38 f = filterbank(9, 1024)
37 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]39 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
38 freqs = np.array(freq_list, dtype = float_type)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 self.assertIsInstance(f.get_coeffs(), np.ndarray)43 self.assertIsInstance(f.get_coeffs(), np.ndarray)
41 spec = cvec(1024)44 spec = cvec(1024)
42 spec.norm[:] = 145 spec.norm[:] = 1
@@ -44,6 +47,37 @@ class aubio_filterbank_mel_test_case(TestCase): · 1 unmodified line
44 [ 0.02070313, 0.02138672, 0.02127604, 0.02135417,47 [ 0.02070313, 0.02138672, 0.02127604, 0.02135417,
45 0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345])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
47if __name__ == '__main__':81if __name__ == '__main__':
48 from unittest import main82 from unittest import main
49 main()83 main()
python/tests/test_source.py+1−1
@@ -69,7 +69,7 @@ class Test_aubio_source_read: · 68 unmodified lines
69 read_frames = self.read_from_source(f)69 read_frames = self.read_from_source(f)
70 if 'f_' in soundfile and samplerate == 0:70 if 'f_' in soundfile and samplerate == 0:
71 import re71 import re
72 f = re.compile('.*_\([0:9]*f\)_.*')72 f = re.compile(r'.*_\([0:9]*f\)_.*')
73 match_f = re.findall('([0-9]*)f_', soundfile)73 match_f = re.findall('([0-9]*)f_', soundfile)
74 if len(match_f) == 1:74 if len(match_f) == 1:
75 expected_frames = int(match_f[0])75 expected_frames = int(match_f[0])

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t