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 (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
22
33 import numpy as np
44 from numpy.testing import TestCase, assert_equal, assert_almost_equal
5+from _tools import assert_warns
56
67 from aubio import cvec, filterbank, float_type
78
@@ -28,7 +29,8 @@ class aubio_filterbank_mel_test_case(TestCase): · 20 unmodified lines
2829 f = filterbank(9, 1024)
2930 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
3031 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)
3234 assert_equal ( f(cvec(1024)), 0)
3335 self.assertIsInstance(f.get_coeffs(), np.ndarray)
3436
@@ -36,7 +38,8 @@ class aubio_filterbank_mel_test_case(TestCase): · 1 unmodified line
3638 f = filterbank(9, 1024)
3739 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
3840 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)
4043 self.assertIsInstance(f.get_coeffs(), np.ndarray)
4144 spec = cvec(1024)
4245 spec.norm[:] = 1
@@ -44,6 +47,37 @@ class aubio_filterbank_mel_test_case(TestCase): · 1 unmodified line
4447 [ 0.02070313, 0.02138672, 0.02127604, 0.02135417,
4548 0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345])
4649
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+
4781 if __name__ == '__main__':
4882 from unittest import main
4983 main()
python/tests/test_source.py+1−1
@@ -69,7 +69,7 @@ class Test_aubio_source_read: · 68 unmodified lines
6969 read_frames = self.read_from_source(f)
7070 if 'f_' in soundfile and samplerate == 0:
7171 import re
72− f = re.compile('.*_\([0:9]*f\)_.*')
72+ f = re.compile(r'.*_\([0:9]*f\)_.*')
7373 match_f = re.findall('([0-9]*)f_', soundfile)
7474 if len(match_f) == 1:
7575 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