History

Merge branch 'feature/pitchshift' into feature/timestretch

Paul Brossier committed 7 years ago

Commit cb0d7d02 parents 6e157df d0f19a7101 files · +1797 −1448Browse files

Showing the changes to python (41 of 101 files). Show all

Unified · Split

41 files
  1. python/README.md +1 −1
  2. python/ext/aubio-docstrings.h +143 −0
  3. python/ext/aubio-types.h +1 −0
  4. python/ext/aubiomodule.c +2 −2
  5. python/ext/py-cvec.c +1 −1
  6. python/ext/py-fft.c +19 −1
  7. python/ext/py-filter.c +55 −4
  8. python/ext/py-filterbank.c +209 −9
  9. python/ext/py-musicutils.c +10 −10
  10. python/lib/gen_code.py +13 −3
  11. python/tests/__init__.py +0 −1
  12. python/tests/_tools.py +41 −0
  13. python/tests/run_all_tests +0 −5
  14. python/tests/test_aubio.py +1 −2
  15. python/tests/test_aubio_cmd.py +2 −2
  16. python/tests/test_aubio_cut.py +1 −1
  17. python/tests/test_cvec.py +1 −1
  18. python/tests/test_dct.py +4 −0
  19. python/tests/test_fft.py +1 −1
  20. python/tests/test_filter.py +2 −2
  21. python/tests/test_filterbank.py +3 −3
  22. python/tests/test_filterbank_mel.py +14 −15
  23. python/tests/test_fvec.py +1 −1
  24. python/tests/test_fvec_shift.py +1 −1
  25. python/tests/test_hztomel.py +11 −8
  26. python/tests/test_mathutils.py +1 −1
  27. python/tests/test_mfcc.py +17 −21
  28. python/tests/test_midi2note.py +11 −12
  29. python/tests/test_musicutils.py +2 −2
  30. python/tests/test_note2midi.py +24 −19
  31. python/tests/test_notes.py +6 −7
  32. python/tests/test_onset.py +1 −1
  33. python/tests/test_phasevoc.py +13 −8
  34. python/tests/test_pitch.py +5 −5
  35. python/tests/test_sink.py +16 −22
  36. python/tests/test_slicing.py +3 −3
  37. python/tests/test_source.py +56 −53
  38. python/tests/test_source_channels.py +1 −1
  39. python/tests/test_specdesc.py +1 −1
  40. python/tests/test_zero_crossing_rate.py +1 −1
  41. python/tests/utils.py +6 −12
python/README.md+1−1
@@ -27,7 +27,7 @@ Links · 26 unmodified lines
2727 Demos
2828 -----
2929
30−Some examples are available in the [`python/demos`][demos_dir] folder. Each
30+Some examples are available in the [`python/demos` folder][demos_dir]. Each
3131 script is a command line program which accepts one ore more argument.
3232
3333 **Notes**: installing additional modules is required to run some of the demos.
python/ext/aubio-docstrings.h+143−0
@@ -0,0 +1,143 @@
1+#define PYAUBIO_dct_doc \
2+ "dct(size=1024)\n"\
3+ "\n"\
4+ "Compute Discrete Fourier Transorms of Type-II.\n"\
5+ "\n"\
6+ "Parameters\n"\
7+ "----------\n"\
8+ "size : int\n"\
9+ " size of the DCT to compute\n"\
10+ "\n"\
11+ "Example\n"\
12+ "-------\n"\
13+ ">>> d = aubio.dct(16)\n"\
14+ ">>> d.size\n"\
15+ "16\n"\
16+ ">>> x = aubio.fvec(np.ones(d.size))\n"\
17+ ">>> d(x)\n"\
18+ "array([4., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n"\
19+ " dtype=float32)\n"\
20+ ">>> d.rdo(d(x))\n"\
21+ "array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n"\
22+ " dtype=float32)\n"\
23+ "\n"\
24+ "References\n"\
25+ "----------\n"\
26+ "`DCT-II in Discrete Cosine Transform\n"\
27+ "<https://en.wikipedia.org/wiki/Discrete_cosine_transform#DCT-II>`_\n"\
28+ "on Wikipedia.\n"
29+
30+#define PYAUBIO_mfcc_doc \
31+ "mfcc(buf_size=1024, n_filters=40, n_coeffs=13, samplerate=44100)\n"\
32+ "\n"\
33+ "Compute Mel Frequency Cepstrum Coefficients (MFCC).\n"\
34+ "\n"\
35+ "`mfcc` creates a callable which takes a `cvec` as input.\n"\
36+ "\n"\
37+ "If `n_filters = 40`, the filterbank will be initialized with\n"\
38+ ":meth:`filterbank.set_mel_coeffs_slaney`. Otherwise, if `n_filters`\n"\
39+ "is greater than `0`, it will be initialized with\n"\
40+ ":meth:`filterbank.set_mel_coeffs` using `fmin = 0`,\n"\
41+ "`fmax = samplerate/`.\n"\
42+ "\n"\
43+ "Example\n"\
44+ "-------\n"\
45+ ">>> buf_size = 2048; n_filters = 128; n_coeffs = 13; samplerate = 44100\n"\
46+ ">>> mf = aubio.mfcc(buf_size, n_filters, n_coeffs, samplerate)\n"\
47+ ">>> fftgrain = aubio.cvec(buf_size)\n"\
48+ ">>> mf(fftgrain).shape\n"\
49+ "(13,)\n"\
50+ ""
51+
52+#define PYAUBIO_notes_doc \
53+ "notes(method=\"default\", buf_size=1024, hop_size=512, samplerate=44100)\n"\
54+ "\n"\
55+ "Note detection\n"
56+
57+#define PYAUBIO_onset_doc \
58+ "onset(method=\"default\", buf_size=1024, hop_size=512, samplerate=44100)\n"\
59+ "\n"\
60+ "Onset detection object. `method` should be one of method supported by\n"\
61+ ":class:`specdesc`.\n"
62+
63+#define PYAUBIO_pitch_doc \
64+ "pitch(method=\"default\", buf_size=1024, hop_size=512, samplerate=44100)\n"\
65+ "\n"\
66+ "Pitch detection.\n"\
67+ "\n"\
68+ "Supported methods: `yinfft`, `yin`, `yinfast`, `fcomb`, `mcomb`,\n"\
69+ "`schmitt`, `specacf`, `default` (`yinfft`).\n"
70+
71+#define PYAUBIO_sampler_doc \
72+ "sampler(hop_size=512, samplerate=44100)\n"\
73+ "\n"\
74+ "Sampler.\n"
75+
76+#define PYAUBIO_specdesc_doc \
77+ "specdesc(method=\"default\", buf_size=1024)\n"\
78+ "\n"\
79+ "Spectral description functions. Creates a callable that takes a\n"\
80+ ":class:`cvec` as input, typically created by :class:`pvoc` for\n"\
81+ "overlap and windowing, and returns a single float.\n"\
82+ "\n"\
83+ "`method` can be any of the values listed below. If `default` is used\n"\
84+ "the `hfc` function will be selected.\n"\
85+ "\n"\
86+ "Onset novelty functions:\n"\
87+ "\n"\
88+ "- `energy`: local energy,\n"\
89+ "- `hfc`: high frequency content,\n"\
90+ "- `complex`: complex domain,\n"\
91+ "- `phase`: phase-based method,\n"\
92+ "- `wphase`: weighted phase deviation,\n"\
93+ "- `specdiff`: spectral difference,\n"\
94+ "- `kl`: Kullback-Liebler,\n"\
95+ "- `mkl`: modified Kullback-Liebler,\n"\
96+ "- `specflux`: spectral flux.\n"\
97+ "\n"\
98+ "Spectral shape functions:\n"\
99+ "\n"\
100+ "- `centroid`: spectral centroid (barycenter of the norm vector),\n"\
101+ "- `spread`: variance around centroid,\n"\
102+ "- `skewness`: third order moment,\n"\
103+ "- `kurtosis`: a measure of the flatness of the spectrum,\n"\
104+ "- `slope`: decreasing rate of the amplitude,\n"\
105+ "- `decrease`: perceptual based measurement of the decreasing rate,\n"\
106+ "- `rolloff`: 95th energy percentile.\n"\
107+ "\n"\
108+ "Parameters\n"\
109+ "----------\n"\
110+ "method : str\n"\
111+ " Onset novelty or spectral shape function.\n"\
112+ "buf_size : int\n"\
113+ " Length of the input frame.\n"\
114+ "\n"\
115+ "Example\n"\
116+ "-------\n"\
117+ ">>> win_s = 1024; hop_s = win_s // 2\n"\
118+ ">>> pv = aubio.pvoc(win_s, hop_s)\n"\
119+ ">>> sd = aubio.specdesc(\"mkl\", win_s)\n"\
120+ ">>> sd(pv(aubio.fvec(hop_s))).shape\n"\
121+ "(1,)\n"\
122+ "\n"\
123+ "References\n"\
124+ "----------\n"\
125+ "`Detailed description "\
126+ "<https://aubio.org/doc/latest/specdesc_8h.html#details>`_ in\n"\
127+ "`aubio API documentation <https://aubio.org/doc/latest/index.html>`_.\n"\
128+ ""
129+
130+#define PYAUBIO_tempo_doc \
131+ "tempo(method=\"default\", buf_size=1024, hop_size=512, samplerate=44100)\n"\
132+ "\n"\
133+ "Tempo detection and beat tracking.\n"
134+
135+#define PYAUBIO_tss_doc \
136+ "tss(buf_size=1024, hop_size=512)\n"\
137+ "\n"\
138+ "Transient/Steady-state separation.\n"
139+
140+#define PYAUBIO_wavetable_doc \
141+ "wavetable(samplerate=44100, hop_size=512)\n"\
142+ "\n"\
143+ "Wavetable synthesis.\n"
python/ext/aubio-types.h+1−0
@@ -1,6 +1,7 @@
11 #include <Python.h>
22 #include <structmember.h>
33
4+#include "aubio-docstrings.h"
45 #include "aubio-generated.h"
56
67 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
python/ext/aubiomodule.c+2−2
@@ -223,7 +223,7 @@ Py_alpha_norm (PyObject * self, PyObject * args) · 222 unmodified lines
223223 }
224224
225225 // compute the function
226− result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, fvec_alpha_norm (&vec, alpha));
226+ result = PyFloat_FromDouble(fvec_alpha_norm (&vec, alpha));
227227 if (result == NULL) {
228228 return NULL;
229229 }
@@ -319,7 +319,7 @@ Py_zero_crossing_rate (PyObject * self, PyObject * args) · 89 unmodified lines
319319 }
320320
321321 // compute the function
322− result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, aubio_zero_crossing_rate (&vec));
322+ result = PyFloat_FromDouble(aubio_zero_crossing_rate (&vec));
323323 if (result == NULL) {
324324 return NULL;
325325 }
python/ext/py-cvec.c+1−1
@@ -136,7 +136,7 @@ Py_cvec_repr (Py_cvec * self, PyObject * unused) · 135 unmodified lines
136136 goto fail;
137137 }
138138
139− args = Py_BuildValue ("I", self->length);
139+ args = PyLong_FromLong(self->length);
140140 if (args == NULL) {
141141 goto fail;
142142 }
python/ext/py-fft.c+19−1
@@ -1,6 +1,24 @@
11 #include "aubio-types.h"
22
3−static char Py_fft_doc[] = "fft object";
3+static char Py_fft_doc[] = ""
4+"fft(size=1024)\n"
5+"\n"
6+"Compute Fast Fourier Transorms.\n"
7+"\n"
8+"Parameters\n"
9+"----------\n"
10+"size : int\n"
11+" size of the FFT to compute\n"
12+"\n"
13+"Example\n"
14+"-------\n"
15+">>> x = aubio.fvec(512)\n"
16+">>> f = aubio.fft(512)\n"
17+">>> c = f(x); c\n"
18+"aubio cvec of 257 elements\n"
19+">>> x2 = f.rdo(c); x2.shape\n"
20+"(512,)\n"
21+"";
422
523 typedef struct
624 {
python/ext/py-filter.c+55−4
@@ -10,7 +10,58 @@ typedef struct · 9 unmodified lines
1010 fvec_t c_out;
1111 } Py_filter;
1212
13−static char Py_filter_doc[] = "filter object";
13+static char Py_filter_doc[] = ""
14+"digital_filter(order=7)\n"
15+"\n"
16+"Create a digital filter.\n"
17+"";
18+
19+static char Py_filter_set_c_weighting_doc[] = ""
20+"set_c_weighting(samplerate)\n"
21+"\n"
22+"Set filter coefficients to C-weighting.\n"
23+"\n"
24+"`samplerate` should be one of 8000, 11025, 16000, 22050, 24000, 32000,\n"
25+"44100, 48000, 88200, 96000, or 192000. `order` of the filter should be 5.\n"
26+"\n"
27+"Parameters\n"
28+"----------\n"
29+"samplerate : int\n"
30+" Sampling-rate of the input signal, in Hz.\n"
31+"";
32+
33+static char Py_filter_set_a_weighting_doc[] = ""
34+"set_a_weighting(samplerate)\n"
35+"\n"
36+"Set filter coefficients to A-weighting.\n"
37+"\n"
38+"`samplerate` should be one of 8000, 11025, 16000, 22050, 24000, 32000,\n"
39+"44100, 48000, 88200, 96000, or 192000. `order` of the filter should be 7.\n"
40+"\n"
41+"Parameters\n"
42+"----------\n"
43+"samplerate : int\n"
44+" Sampling-rate of the input signal.\n"
45+"";
46+
47+static char Py_filter_set_biquad_doc[] = ""
48+"set_biquad(b0, b1, b2, a1, a2)\n"
49+"\n"
50+"Set biquad coefficients. `order` of the filter should be 3.\n"
51+"\n"
52+"Parameters\n"
53+"----------\n"
54+"b0 : float\n"
55+" Forward filter coefficient.\n"
56+"b1 : float\n"
57+" Forward filter coefficient.\n"
58+"b2 : float\n"
59+" Forward filter coefficient.\n"
60+"a1 : float\n"
61+" Feedback filter coefficient.\n"
62+"a2 : float\n"
63+" Feedback filter coefficient.\n"
64+"";
1465
1566 static PyObject *
1667 Py_filter_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
@@ -156,11 +207,11 @@ static PyMemberDef Py_filter_members[] = { · 139 unmodified lines
156207
157208 static PyMethodDef Py_filter_methods[] = {
158209 {"set_c_weighting", (PyCFunction) Py_filter_set_c_weighting, METH_VARARGS,
159− "set filter coefficients to C-weighting"},
210+ Py_filter_set_c_weighting_doc},
160211 {"set_a_weighting", (PyCFunction) Py_filter_set_a_weighting, METH_VARARGS,
161− "set filter coefficients to A-weighting"},
212+ Py_filter_set_a_weighting_doc},
162213 {"set_biquad", (PyCFunction) Py_filter_set_biquad, METH_VARARGS,
163− "set b0, b1, b2, a1, a2 biquad coefficients"},
214+ Py_filter_set_biquad_doc},
164215 {NULL}
165216 };
166217
python/ext/py-filterbank.c+209−9
@@ -1,6 +1,188 @@
11 #include "aubio-types.h"
22
3−static char Py_filterbank_doc[] = "filterbank object";
3+static char Py_filterbank_doc[] = ""
4+"filterbank(n_filters=40, win_s=1024)\n"
5+"\n"
6+"Create a bank of spectral filters. Each instance is a callable\n"
7+"that holds a matrix of coefficients.\n"
8+"\n"
9+"See also :meth:`set_mel_coeffs`, :meth:`set_mel_coeffs_htk`,\n"
10+":meth:`set_mel_coeffs_slaney`, :meth:`set_triangle_bands`, and\n"
11+":meth:`set_coeffs`.\n"
12+"\n"
13+"Parameters\n"
14+"----------\n"
15+"n_filters : int\n"
16+" Number of filters to create.\n"
17+"win_s : int\n"
18+" Size of the input spectrum to process.\n"
19+"\n"
20+"Examples\n"
21+"--------\n"
22+">>> f = aubio.filterbank(128, 1024)\n"
23+">>> f.set_mel_coeffs(44100, 0, 10000)\n"
24+">>> c = aubio.cvec(1024)\n"
25+">>> f(c).shape\n"
26+"(128, )\n"
27+"";
28+
29+static char Py_filterbank_set_triangle_bands_doc[] =""
30+"set_triangle_bands(freqs, samplerate)\n"
31+"\n"
32+"Set triangular bands. The coefficients will be set to triangular\n"
33+"overlapping windows using the boundaries specified by `freqs`.\n"
34+"\n"
35+"`freqs` should contain `n_filters + 2` frequencies in Hz, ordered\n"
36+"by value, from smallest to largest. The first element should be greater\n"
37+"or equal to zero; the last element should be smaller or equal to\n"
38+"`samplerate / 2`.\n"
39+"\n"
40+"Parameters\n"
41+"----------\n"
42+"freqs: fvec\n"
43+" List of frequencies, in Hz.\n"
44+"samplerate : float\n"
45+" Sampling-rate of the expected input.\n"
46+"\n"
47+"Example\n"
48+"-------\n"
49+">>> fb = aubio.filterbank(n_filters=100, win_s=2048)\n"
50+">>> samplerate = 44100; freqs = np.linspace(0, 20200, 102)\n"
51+">>> fb.set_triangle_bands(aubio.fvec(freqs), samplerate)\n"
52+"";
53+
54+static char Py_filterbank_set_mel_coeffs_slaney_doc[] = ""
55+"set_mel_coeffs_slaney(samplerate)\n"
56+"\n"
57+"Set coefficients of filterbank to match Slaney's Auditory Toolbox.\n"
58+"\n"
59+"The filter coefficients will be set as in Malcolm Slaney's\n"
60+"implementation. The filterbank should have been created with\n"
61+"`n_filters = 40`.\n"
62+"\n"
63+"This is approximately equivalent to using :meth:`set_mel_coeffs` with\n"
64+"`fmin = 400./3., fmax = 6853.84`.\n"
65+"\n"
66+"Parameters\n"
67+"----------\n"
68+"samplerate : float\n"
69+" Sampling-rate of the expected input.\n"
70+"\n"
71+"References\n"
72+"----------\n"
73+"\n"
74+"Malcolm Slaney, `Auditory Toolbox Version 2, Technical Report #1998-010\n"
75+"<https://engineering.purdue.edu/~malcolm/interval/1998-010/>`_\n"
76+"";
77+
78+static char Py_filterbank_set_mel_coeffs_doc[] = ""
79+"set_mel_coeffs(samplerate, fmin, fmax)\n"
80+"\n"
81+"Set coefficients of filterbank to linearly spaced mel scale.\n"
82+"\n"
83+"Parameters\n"
84+"----------\n"
85+"samplerate : float\n"
86+" Sampling-rate of the expected input.\n"
87+"fmin : float\n"
88+" Lower frequency boundary of the first filter.\n"
89+"fmax : float\n"
90+" Upper frequency boundary of the last filter.\n"
91+"\n"
92+"See also\n"
93+"--------\n"
94+"hztomel\n"
95+"";
96+
97+static char Py_filterbank_set_mel_coeffs_htk_doc[] = ""
98+"set_mel_coeffs_htk(samplerate, fmin, fmax)\n"
99+"\n"
100+"Set coefficients of the filters to be linearly spaced in the HTK mel scale.\n"
101+"\n"
102+"Parameters\n"
103+"----------\n"
104+"samplerate : float\n"
105+" Sampling-rate of the expected input.\n"
106+"fmin : float\n"
107+" Lower frequency boundary of the first filter.\n"
108+"fmax : float\n"
109+" Upper frequency boundary of the last filter.\n"
110+"\n"
111+"See also\n"
112+"--------\n"
113+"hztomel with `htk=True`\n"
114+"";
115+
116+static char Py_filterbank_get_coeffs_doc[] = ""
117+"get_coeffs()\n"
118+"\n"
119+"Get coefficients matrix of filterbank.\n"
120+"\n"
121+"Returns\n"
122+"-------\n"
123+"array_like\n"
124+" Array of shape (n_filters, win_s/2+1) containing the coefficients.\n"
125+"";
126+
127+static char Py_filterbank_set_coeffs_doc[] = ""
128+"set_coeffs(coeffs)\n"
129+"\n"
130+"Set coefficients of filterbank.\n"
131+"\n"
132+"Parameters\n"
133+"----------\n"
134+"coeffs : fmat\n"
135+" Array of shape (n_filters, win_s/2+1) containing the coefficients.\n"
136+"";
137+
138+static char Py_filterbank_set_power_doc[] = ""
139+"set_power(power)\n"
140+"\n"
141+"Set power applied to input spectrum of filterbank.\n"
142+"\n"
143+"Parameters\n"
144+"----------\n"
145+"power : float\n"
146+" Power to raise input spectrum to before computing the filters.\n"
147+"";
148+
149+static char Py_filterbank_get_power_doc[] = ""
150+"get_power()\n"
151+"\n"
152+"Get power applied to filterbank.\n"
153+"\n"
154+"Returns\n"
155+"-------\n"
156+"float\n"
157+" Power parameter.\n"
158+"";
159+
160+static char Py_filterbank_set_norm_doc[] = ""
161+"set_norm(norm)\n"
162+"\n"
163+"Set norm parameter. If set to `0`, the filters will not be normalized.\n"
164+"If set to `1`, the filters will be normalized to one. Default to `1`.\n"
165+"\n"
166+"This function should be called *before* :meth:`set_triangle_bands`,\n"
167+":meth:`set_mel_coeffs`, :meth:`set_mel_coeffs_htk`, or\n"
168+":meth:`set_mel_coeffs_slaney`.\n"
169+"\n"
170+"Parameters\n"
171+"----------\n"
172+"norm : int\n"
173+" `0` to disable, `1` to enable\n"
174+"";
175+
176+static char Py_filterbank_get_norm_doc[] = ""
177+"get_norm()\n"
178+"\n"
179+"Get norm parameter of filterbank.\n"
180+"\n"
181+"Returns\n"
182+"-------\n"
183+"float\n"
184+" Norm parameter.\n"
185+"";
4186
5187 typedef struct
6188 {
@@ -288,6 +470,13 @@ Py_filterbank_set_power(Py_filterbank *self, PyObject *args) · 281 unmodified lines
288470 Py_RETURN_NONE;
289471 }
290472
473+static PyObject *
474+Py_filterbank_get_power (Py_filterbank * self, PyObject *unused)
475+{
476+ smpl_t power = aubio_filterbank_get_power(self->o);
477+ return (PyObject *)PyFloat_FromDouble (power);
478+}
479+
291480 static PyObject *
292481 Py_filterbank_set_norm(Py_filterbank *self, PyObject *args)
293482 {
@@ -311,23 +500,34 @@ Py_filterbank_set_norm(Py_filterbank *self, PyObject *args) · 17 unmodified lines
311500 Py_RETURN_NONE;
312501 }
313502
503+static PyObject *
504+Py_filterbank_get_norm (Py_filterbank * self, PyObject *unused)
505+{
506+ smpl_t norm = aubio_filterbank_get_norm(self->o);
507+ return (PyObject *)PyFloat_FromDouble (norm);
508+}
509+
314510 static PyMethodDef Py_filterbank_methods[] = {
315511 {"set_triangle_bands", (PyCFunction) Py_filterbank_set_triangle_bands,
316− METH_VARARGS, "set coefficients of filterbanks"},
512+ METH_VARARGS, Py_filterbank_set_triangle_bands_doc},
317513 {"set_mel_coeffs_slaney", (PyCFunction) Py_filterbank_set_mel_coeffs_slaney,
318− METH_VARARGS, "set coefficients of filterbank as in Auditory Toolbox"},
514+ METH_VARARGS, Py_filterbank_set_mel_coeffs_slaney_doc},
319515 {"set_mel_coeffs", (PyCFunction) Py_filterbank_set_mel_coeffs,
320− METH_VARARGS, "set coefficients of filterbank to linearly spaced mel scale"},
516+ METH_VARARGS, Py_filterbank_set_mel_coeffs_doc},
321517 {"set_mel_coeffs_htk", (PyCFunction) Py_filterbank_set_mel_coeffs_htk,
322− METH_VARARGS, "set coefficients of filterbank to linearly spaced mel scale"},
518+ METH_VARARGS, Py_filterbank_set_mel_coeffs_htk_doc},
323519 {"get_coeffs", (PyCFunction) Py_filterbank_get_coeffs,
324− METH_NOARGS, "get coefficients of filterbank"},
520+ METH_NOARGS, Py_filterbank_get_coeffs_doc},
325521 {"set_coeffs", (PyCFunction) Py_filterbank_set_coeffs,
326− METH_VARARGS, "set coefficients of filterbank"},
522+ METH_VARARGS, Py_filterbank_set_coeffs_doc},
327523 {"set_power", (PyCFunction) Py_filterbank_set_power,
328− METH_VARARGS, "set power applied to filterbank input spectrum"},
524+ METH_VARARGS, Py_filterbank_set_power_doc},
525+ {"get_power", (PyCFunction) Py_filterbank_get_power,
526+ METH_NOARGS, Py_filterbank_get_power_doc},
329527 {"set_norm", (PyCFunction) Py_filterbank_set_norm,
330− METH_VARARGS, "set norm applied to filterbank input spectrum"},
528+ METH_VARARGS, Py_filterbank_set_norm_doc},
529+ {"get_norm", (PyCFunction) Py_filterbank_get_norm,
530+ METH_NOARGS, Py_filterbank_get_norm_doc},
331531 {NULL}
332532 };
333533
python/ext/py-musicutils.c+10−10
@@ -39,7 +39,7 @@ Py_aubio_level_lin(PyObject *self, PyObject *args) · 38 unmodified lines
3939 return NULL;
4040 }
4141
42− level_lin = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_lin(&vec));
42+ level_lin = PyFloat_FromDouble(aubio_level_lin(&vec));
4343 if (level_lin == NULL) {
4444 PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
4545 return NULL;
@@ -67,7 +67,7 @@ Py_aubio_db_spl(PyObject *self, PyObject *args) · 21 unmodified lines
6767 return NULL;
6868 }
6969
70− db_spl = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_db_spl(&vec));
70+ db_spl = PyFloat_FromDouble(aubio_db_spl(&vec));
7171 if (db_spl == NULL) {
7272 PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
7373 return NULL;
@@ -96,7 +96,7 @@ Py_aubio_silence_detection(PyObject *self, PyObject *args) · 22 unmodified lines
9696 return NULL;
9797 }
9898
99− silence_detection = Py_BuildValue("I", aubio_silence_detection(&vec, threshold));
99+ silence_detection = PyLong_FromLong(aubio_silence_detection(&vec, threshold));
100100 if (silence_detection == NULL) {
101101 PyErr_SetString (PyExc_ValueError, "failed computing silence_detection");
102102 return NULL;
@@ -125,7 +125,7 @@ Py_aubio_level_detection(PyObject *self, PyObject *args) · 22 unmodified lines
125125 return NULL;
126126 }
127127
128− level_detection = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_detection(&vec, threshold));
128+ level_detection = PyFloat_FromDouble(aubio_level_detection(&vec, threshold));
129129 if (level_detection == NULL) {
130130 PyErr_SetString (PyExc_ValueError, "failed computing level_detection");
131131 return NULL;
@@ -194,9 +194,9 @@ Py_aubio_hztomel(PyObject *self, PyObject *args, PyObject *kwds) · 62 unmodified lines
194194 return NULL;
195195 }
196196 if (htk != NULL && PyObject_IsTrue(htk) == 1)
197− return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v));
197+ return PyFloat_FromDouble(aubio_hztomel_htk(v));
198198 else
199− return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel(v));
199+ return PyFloat_FromDouble(aubio_hztomel(v));
200200 }
201201
202202 PyObject*
@@ -211,9 +211,9 @@ Py_aubio_meltohz(PyObject *self, PyObject *args, PyObject *kwds) · 8 unmodified lines
211211 return NULL;
212212 }
213213 if (htk != NULL && PyObject_IsTrue(htk) == 1)
214− return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v));
214+ return PyFloat_FromDouble(aubio_meltohz_htk(v));
215215 else
216− return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz(v));
216+ return PyFloat_FromDouble(aubio_meltohz(v));
217217 }
218218
219219 PyObject*
@@ -223,7 +223,7 @@ Py_aubio_hztomel_htk(PyObject *self, PyObject *args) · 3 unmodified lines
223223 if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) {
224224 return NULL;
225225 }
226− return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v));
226+ return PyFloat_FromDouble(aubio_hztomel_htk(v));
227227 }
228228
229229 PyObject*
@@ -233,5 +233,5 @@ Py_aubio_meltohz_htk(PyObject *self, PyObject *args) · 3 unmodified lines
233233 if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) {
234234 return NULL;
235235 }
236− return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v));
236+ return PyFloat_FromDouble(aubio_meltohz_htk(v));
237237 }
python/lib/gen_code.py+13−3
@@ -234,11 +234,21 @@ typedef struct{{ · 233 unmodified lines
234234 return out.format(do_inputs_list = do_inputs_list, **self.__dict__)
235235
236236 def gen_doc(self):
237+ sig = []
238+ for p in self.input_params:
239+ name = p['name']
240+ defval = aubiodefvalue[name].replace('"','\\\"')
241+ sig.append("{name}={defval}".format(defval=defval, name=name))
237242 out = """
238−// TODO: add documentation
239−static char Py_{shortname}_doc[] = \"undefined\";
243+#ifndef PYAUBIO_{shortname}_doc
244+#define PYAUBIO_{shortname}_doc "{shortname}({sig})"
245+#endif /* PYAUBIO_{shortname}_doc */
246+
247+static char Py_{shortname}_doc[] = ""
248+PYAUBIO_{shortname}_doc
249+"";
240250 """
241− return out.format(**self.__dict__)
251+ return out.format(sig=', '.join(sig), **self.__dict__)
242252
243253 def gen_new(self):
244254 out = """
python/tests/__init__.py+0−1
@@ -1 +0,0 @@
1−
python/tests/_tools.py+41−0
@@ -0,0 +1,41 @@
1+"""
2+This file imports test methods from different testing modules, in this
3+order:
4+
5+ - try importing 'pytest'
6+ - if it fails, fallback to 'numpy.testing'
7+
8+Nose2 support was removed because of lacking assertWarns on py2.7.
9+
10+"""
11+
12+import sys
13+
14+_has_pytest = False
15+
16+# check if we have pytest
17+try:
18+ import pytest
19+ parametrize = pytest.mark.parametrize
20+ assert_raises = pytest.raises
21+ assert_warns = pytest.warns
22+ skipTest = pytest.skip
23+ _has_pytest = True
24+ def run_module_suite():
25+ import sys, pytest
26+ pytest.main(sys.argv)
27+except:
28+ pass
29+
30+# otherwise fallback on numpy.testing
31+if not _has_pytest:
32+ from numpy.testing import dec, assert_raises, assert_warns
33+ from numpy.testing import SkipTest
34+ parametrize = dec.parametrize
35+ def skipTest(msg):
36+ raise SkipTest(msg)
37+ from numpy.testing import run_module_suite
38+
39+# always use numpy's assert_equal
40+import numpy
41+assert_equal = numpy.testing.assert_equal
python/tests/run_all_tests+0−5
@@ -1,5 +0,0 @@
1−#! /usr/bin/env python
2−
3−if __name__ == '__main__':
4− import nose2.main
5− nose2.discover()
python/tests/test_aubio.py+1−2
@@ -1,6 +1,5 @@
11 #! /usr/bin/env python
22
3−from unittest import main
43 from numpy.testing import TestCase
54
65 class aubiomodule_test_case(TestCase):
@@ -15,5 +14,5 @@ class aubiomodule_test_case(TestCase): · 8 unmodified lines
1514 self.assertEqual('0', aubio.version[0])
1615
1716 if __name__ == '__main__':
17+ from unittest import main
1818 main()
19−
python/tests/test_aubio_cmd.py+2−2
@@ -1,8 +1,7 @@
11 #! /usr/bin/env python
22
3−import aubio.cmd
4−from nose2 import main
53 from numpy.testing import TestCase
4+import aubio.cmd
65
76 class aubio_cmd(TestCase):
87
@@ -31,4 +30,5 @@ class aubio_cmd_utils(TestCase): · 22 unmodified lines
3130 "3200\t")
3231
3332 if __name__ == '__main__':
33+ from unittest import main
3434 main()
python/tests/test_aubio_cut.py+1−1
@@ -1,7 +1,6 @@
11 #! /usr/bin/env python
22
33 import aubio.cut
4−from nose2 import main
54 from numpy.testing import TestCase
65
76 class aubio_cut(TestCase):
@@ -13,4 +12,5 @@ class aubio_cut(TestCase): · 5 unmodified lines
1312 assert self.a_parser.parse_args(['-v']).verbose
1413
1514 if __name__ == '__main__':
15+ from unittest import main
1616 main()
python/tests/test_cvec.py+1−1
@@ -1,6 +1,5 @@
11 #! /usr/bin/env python
22
3−from unittest import main
43 import numpy as np
54 from numpy.testing import TestCase, assert_equal
65 from aubio import cvec, fvec, float_type
@@ -141,4 +140,5 @@ class aubio_cvec_wrong_norm_input(TestCase): · 134 unmodified lines
141140 a.norm = np.zeros((512//2+1, 2), dtype = float_type)
142141
143142 if __name__ == '__main__':
143+ from unittest import main
144144 main()
python/tests/test_dct.py+4−0
@@ -66,3 +66,7 @@ class aubio_dct(TestCase): · 65 unmodified lines
6666 aubio.dct(size)
6767 except AssertionError:
6868 self.skipTest('creating aubio.dct with size %d did not fail' % size)
69+
70+if __name__ == '__main__':
71+ from unittest import main
72+ main()
python/tests/test_fft.py+1−1
@@ -1,6 +1,5 @@
11 #! /usr/bin/env python
22
3−from unittest import main
43 from numpy.testing import TestCase
54 from numpy.testing import assert_equal, assert_almost_equal
65 import numpy as np
@@ -212,4 +211,5 @@ class aubio_fft_wrong_params(TestCase): · 205 unmodified lines
212211 fft(win_s)
213212
214213 if __name__ == '__main__':
214+ from unittest import main
215215 main()
python/tests/test_filter.py+2−2
@@ -1,9 +1,8 @@
11 #! /usr/bin/env python
22
3−from unittest import main
43 from numpy.testing import TestCase, assert_equal, assert_almost_equal
54 from aubio import fvec, digital_filter
6−from .utils import array_from_text_file
5+from utils import array_from_text_file
76
87 class aubio_filter_test_case(TestCase):
98
@@ -94,4 +93,5 @@ class aubio_filter_wrong_params(TestCase): · 84 unmodified lines
9493 digital_filter(-1)
9594
9695 if __name__ == '__main__':
96+ from unittest import main
9797 main()
python/tests/test_filterbank.py+3−3
@@ -4,7 +4,7 @@ import numpy as np · 3 unmodified lines
44 from numpy.testing import TestCase, assert_equal, assert_almost_equal
55
66 from aubio import cvec, filterbank, float_type
7−from .utils import array_from_text_file
7+from utils import array_from_text_file
88
99 class aubio_filterbank_test_case(TestCase):
1010
@@ -87,5 +87,5 @@ class aubio_filterbank_wrong_values(TestCase): · 76 unmodified lines
8787 f(cvec(256))
8888
8989 if __name__ == '__main__':
90− import nose2
91− nose2.main()
90+ from unittest import main
91+ main()
python/tests/test_filterbank_mel.py+14−15
@@ -2,12 +2,10 @@ · 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 fvec, cvec, filterbank, float_type
78
8−import warnings
9−warnings.filterwarnings('ignore', category=UserWarning, append=True)
10−
119 class aubio_filterbank_mel_test_case(TestCase):
1210
1311 def test_slaney(self):
@@ -75,40 +73,41 @@ class aubio_filterbank_mel_test_case(TestCase): · 61 unmodified lines
7573 samplerate = 22050
7674 freq_list = [0, samplerate//4, samplerate // 2 + 1]
7775 f = filterbank(len(freq_list)-2, 1024)
78− # TODO add assert_warns
79− f.set_triangle_bands(fvec(freq_list), samplerate)
76+ with assert_warns(UserWarning):
77+ f.set_triangle_bands(fvec(freq_list), samplerate)
8078
8179 def test_triangle_freqs_with_not_enough_filters(self):
8280 """make sure set_triangle_bands warns when not enough filters"""
8381 samplerate = 22050
8482 freq_list = [0, 100, 1000, 4000, 8000, 10000]
8583 f = filterbank(len(freq_list)-3, 1024)
86− # TODO add assert_warns
87− f.set_triangle_bands(fvec(freq_list), samplerate)
84+ with assert_warns(UserWarning):
85+ f.set_triangle_bands(fvec(freq_list), samplerate)
8886
8987 def test_triangle_freqs_with_too_many_filters(self):
9088 """make sure set_triangle_bands warns when too many filters"""
9189 samplerate = 22050
9290 freq_list = [0, 100, 1000, 4000, 8000, 10000]
9391 f = filterbank(len(freq_list)-1, 1024)
94− # TODO add assert_warns
95− f.set_triangle_bands(fvec(freq_list), samplerate)
92+ with assert_warns(UserWarning):
93+ f.set_triangle_bands(fvec(freq_list), samplerate)
9694
9795 def test_triangle_freqs_with_double_value(self):
9896 """make sure set_triangle_bands works with 2 duplicate freqs"""
9997 samplerate = 22050
10098 freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
10199 f = filterbank(len(freq_list)-2, 1024)
102− # TODO add assert_warns
103− f.set_triangle_bands(fvec(freq_list), samplerate)
100+ with assert_warns(UserWarning):
101+ f.set_triangle_bands(fvec(freq_list), samplerate)
104102
105103 def test_triangle_freqs_with_triple(self):
106104 """make sure set_triangle_bands works with 3 duplicate freqs"""
107105 samplerate = 22050
108106 freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
109107 f = filterbank(len(freq_list)-2, 1024)
110− # TODO add assert_warns
111− f.set_triangle_bands(fvec(freq_list), samplerate)
108+ with assert_warns(UserWarning):
109+ f.set_triangle_bands(fvec(freq_list), samplerate)
110+
112111
113112 def test_triangle_freqs_without_norm(self):
114113 """make sure set_triangle_bands works without """
@@ -168,5 +167,5 @@ class aubio_filterbank_mel_test_case(TestCase): · 53 unmodified lines
168167
169168
170169 if __name__ == '__main__':
171− import nose2
172− nose2.main()
170+ from unittest import main
171+ main()
python/tests/test_fvec.py+1−1
@@ -1,6 +1,5 @@
11 #! /usr/bin/env python
22
3−from unittest import main
43 import numpy as np
54 from numpy.testing import TestCase, assert_equal, assert_almost_equal
65 from aubio import fvec, zero_crossing_rate, alpha_norm, min_removal
@@ -148,4 +147,5 @@ class aubio_fvec_test_memory(TestCase): · 141 unmodified lines
148147 del c
149148
150149 if __name__ == '__main__':
150+ from unittest import main
151151 main()
python/tests/test_fvec_shift.py+1−1
@@ -30,6 +30,6 @@ class aubio_shift_test_case(TestCase): · 29 unmodified lines
3030 def test_can_shift_fvec_odd(self):
3131 self.run_shift_ishift(7)
3232
33−from unittest import main
3433 if __name__ == '__main__':
34+ from unittest import main
3535 main()
python/tests/test_hztomel.py+11−8
@@ -3,6 +3,7 @@ · 2 unmodified lines
33 from unittest import main
44 from numpy.testing import TestCase
55 from numpy.testing import assert_equal, assert_almost_equal
6+from _tools import assert_warns
67 import numpy as np
78 import aubio
89
@@ -37,12 +38,12 @@ class aubio_hztomel_test_case(TestCase): · 28 unmodified lines
3738 assert_almost_equal(meltohz(hztomel(f)) - f, 0, decimal=1)
3839
3940 def test_meltohz_negative(self):
40− # TODO add assert_warns
41− assert_equal(meltohz(-1), 0)
41+ with assert_warns(UserWarning):
42+ assert_equal(meltohz(-1), 0)
4243
4344 def test_hztomel_negative(self):
44− # TODO add assert_warns
45− assert_equal(hztomel(-1), 0)
45+ with assert_warns(UserWarning):
46+ assert_equal(hztomel(-1), 0)
4647
4748
4849 class aubio_hztomel_htk_test_case(TestCase):
@@ -57,14 +58,16 @@ class aubio_hztomel_htk_test_case(TestCase): · 8 unmodified lines
5758 assert_almost_equal(hztomel(6300, htk=True), 2595., decimal=1)
5859
5960 def test_meltohz_negative(self):
60− # TODO add assert_warns
61− assert_equal(meltohz(-1, htk=True), 0)
61+ with assert_warns(UserWarning):
62+ assert_equal(meltohz(-1, htk=True), 0)
6263 assert_almost_equal(meltohz(2000, htk=True), 3428.7, decimal=1)
6364 assert_almost_equal(meltohz(1000, htk=True), 1000., decimal=1)
6465
6566 def test_hztomel_negative(self):
66− # TODO add assert_warns
67− assert_equal(hztomel(-1, htk=True), 0)
67+ with assert_warns(UserWarning):
68+ assert_equal(meltohz(-1, htk=True), 0)
69+ with assert_warns(UserWarning):
70+ assert_equal(hztomel(-1, htk=True), 0)
6871 assert_almost_equal(hztomel(1000, htk=True), 1000., decimal=1)
6972
7073 def test_hztomel_htk(self):
python/tests/test_mathutils.py+1−1
@@ -1,6 +1,5 @@
11 #! /usr/bin/env python
22
3−from unittest import main
43 from numpy.testing import TestCase, assert_equal
54 from numpy import array, arange, isnan, isinf
65 from aubio import bintomidi, miditobin, freqtobin, bintofreq, freqtomidi, miditofreq
@@ -101,4 +100,5 @@ class aubio_mathutils(TestCase): · 94 unmodified lines
101100 assert_equal ( array(b) < 0, False )
102101
103102 if __name__ == '__main__':
103+ from unittest import main
104104 main()
python/tests/test_mfcc.py+17−21
@@ -1,7 +1,6 @@
11 #! /usr/bin/env python
22
3−from nose2 import main
4−from nose2.tools import params
3+from _tools import parametrize, assert_raises
54 from numpy import random, count_nonzero
65 from numpy.testing import TestCase
76 from aubio import mfcc, cvec, float_type
@@ -15,28 +14,21 @@ samplerate = 44100 · 7 unmodified lines
1514 new_params = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
1615 new_deflts = [1024, 40, 13, 44100]
1716
18−class aubio_mfcc(TestCase):
17+class Test_aubio_mfcc(object):
1918
20− def setUp(self):
21− self.o = mfcc()
19+ members_args = 'name'
2220
23− def test_default_creation(self):
24− pass
25−
26− def test_delete(self):
27− del self.o
28−
29− @params(*new_params)
21+ @parametrize(members_args, new_params)
3022 def test_read_only_member(self, name):
31− o = self.o
32− with self.assertRaises((TypeError, AttributeError)):
23+ o = mfcc()
24+ with assert_raises((TypeError, AttributeError)):
3325 setattr(o, name, 0)
3426
35− @params(*zip(new_params, new_deflts))
27+ @parametrize('name, expected', zip(new_params, new_deflts))
3628 def test_default_param(self, name, expected):
3729 """ test mfcc.{:s} = {:d} """.format(name, expected)
38− o = self.o
39− self.assertEqual( getattr(o, name), expected)
30+ o = mfcc()
31+ assert getattr(o, name) == expected
4032
4133 class aubio_mfcc_wrong_params(TestCase):
4234
@@ -82,9 +74,9 @@ class aubio_mfcc_compute(TestCase): · 39 unmodified lines
8274 #print coeffs
8375
8476
85−class aubio_mfcc_all_parameters(TestCase):
77+class Test_aubio_mfcc_all_parameters(object):
8678
87− @params(
79+ run_values = [
8880 (2048, 40, 13, 44100),
8981 (1024, 40, 13, 44100),
9082 (512, 40, 13, 44100),
@@ -100,7 +92,10 @@ class aubio_mfcc_all_parameters(TestCase): · 9 unmodified lines
10092 #(1024, 30, 20, 44100),
10193 (1024, 40, 40, 44100),
10294 (1024, 40, 3, 44100),
103− )
95+ ]
96+ run_args = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
97+
98+ @parametrize(run_args, run_values)
10499 def test_run_with_params(self, buf_size, n_filters, n_coeffs, samplerate):
105100 " check mfcc can run with reasonable parameters "
106101 o = mfcc(buf_size, n_filters, n_coeffs, samplerate)
@@ -148,4 +143,5 @@ class aubio_mfcc_fb_params(TestCase): · 41 unmodified lines
148143 assert m.get_scale() == 1
149144
150145 if __name__ == '__main__':
151− main()
146+ from _tools import run_module_suite
147+ run_module_suite()
python/tests/test_midi2note.py+11−12
@@ -2,8 +2,7 @@ · 1 unmodified line
22 # -*- coding: utf-8 -*-
33
44 from aubio import midi2note
5−from nose2.tools import params
6−import unittest
5+from _tools import parametrize, assert_raises
76
87 list_of_known_midis = (
98 ( 0, 'C-1' ),
@@ -15,31 +14,31 @@ list_of_known_midis = ( · 5 unmodified lines
1514 ( 127, 'G9' ),
1615 )
1716
18−class midi2note_good_values(unittest.TestCase):
17+class Test_midi2note_good_values(object):
1918
20− @params(*list_of_known_midis)
19+ @parametrize('midi, note', list_of_known_midis)
2120 def test_midi2note_known_values(self, midi, note):
2221 " known values are correctly converted "
23− self.assertEqual ( midi2note(midi), note )
22+ assert midi2note(midi) == (note)
2423
25−class midi2note_wrong_values(unittest.TestCase):
24+class Test_midi2note_wrong_values(object):
2625
2726 def test_midi2note_negative_value(self):
2827 " fails when passed a negative value "
29− self.assertRaises(ValueError, midi2note, -2)
28+ assert_raises(ValueError, midi2note, -2)
3029
3130 def test_midi2note_large(self):
3231 " fails when passed a value greater than 127 "
33− self.assertRaises(ValueError, midi2note, 128)
32+ assert_raises(ValueError, midi2note, 128)
3433
3534 def test_midi2note_floating_value(self):
3635 " fails when passed a floating point "
37− self.assertRaises(TypeError, midi2note, 69.2)
36+ assert_raises(TypeError, midi2note, 69.2)
3837
3938 def test_midi2note_character_value(self):
4039 " fails when passed a value that can not be transformed to integer "
41− self.assertRaises(TypeError, midi2note, "a")
40+ assert_raises(TypeError, midi2note, "a")
4241
4342 if __name__ == '__main__':
44− import nose2
45− nose2.main()
43+ from _tools import run_module_suite
44+ run_module_suite()
python/tests/test_musicutils.py+2−2
@@ -1,9 +1,8 @@
11 #! /usr/bin/env python
22
3−from unittest import main
43 import numpy as np
54 from numpy.testing import TestCase
6−from numpy.testing.utils import assert_equal, assert_almost_equal
5+from numpy.testing import assert_equal, assert_almost_equal
76 from aubio import window, level_lin, db_spl, silence_detection, level_detection
87 from aubio import fvec, float_type
98
@@ -85,4 +84,5 @@ class aubio_level_detection(TestCase): · 75 unmodified lines
8584 assert level_detection(ones(1024, dtype = float_type), -70) == 0
8685
8786 if __name__ == '__main__':
87+ from unittest import main
8888 main()
python/tests/test_note2midi.py+24−19
@@ -4,8 +4,8 @@ · 3 unmodified lines
44 from __future__ import unicode_literals
55
66 from aubio import note2midi, freq2note, note2freq, float_type
7−from nose2.tools import params
8−import unittest
7+from numpy.testing import TestCase
8+from _tools import parametrize, assert_raises, skipTest
99
1010 list_of_known_notes = (
1111 ( 'C-1', 0 ),
@@ -44,29 +44,32 @@ list_of_unknown_notes = ( · 32 unmodified lines
4444 ( '2' ),
4545 )
4646
47−class note2midi_good_values(unittest.TestCase):
47+class Test_note2midi_good_values(object):
4848
49− @params(*list_of_known_notes)
49+ @parametrize('note, midi', list_of_known_notes)
5050 def test_note2midi_known_values(self, note, midi):
5151 " known values are correctly converted "
52− self.assertEqual ( note2midi(note), midi )
52+ assert note2midi(note) == midi
5353
54− @params(*list_of_known_notes_with_unicode_issues)
54+ @parametrize('note, midi', list_of_known_notes_with_unicode_issues)
5555 def test_note2midi_known_values_with_unicode_issues(self, note, midi):
56− " known values are correctly converted, unless decoding is expected to fail"
56+ " difficult values are correctly converted unless expected failure "
5757 try:
58− self.assertEqual ( note2midi(note), midi )
58+ assert note2midi(note) == midi
5959 except UnicodeEncodeError as e:
60+ # platforms with decoding failures include:
61+ # - osx: python <= 2.7.10
62+ # - win: python <= 2.7.12
6063 import sys
61− strfmt = "len(u'\\U0001D12A') != 1, excpected decoding failure | {:s} | {:s} {:s}"
62− strres = strfmt.format(e, sys.platform, sys.version)
63− # happens with: darwin 2.7.10, windows 2.7.12
64+ strmsg = "len(u'\\U0001D12A') != 1, expected decoding failure"
65+ strmsg += " | upgrade to Python 3 to fix"
66+ strmsg += " | {:s} | {:s} {:s}"
6467 if len('\U0001D12A') != 1 and sys.version[0] == '2':
65− self.skipTest(strres + " | upgrade to Python 3 to fix")
68+ skipTest(strmsg.format(repr(e), sys.platform, sys.version))
6669 else:
6770 raise
6871
69−class note2midi_wrong_values(unittest.TestCase):
72+class note2midi_wrong_values(TestCase):
7073
7174 def test_note2midi_missing_octave(self):
7275 " fails when passed only one character"
@@ -104,12 +107,14 @@ class note2midi_wrong_values(unittest.TestCase): · 31 unmodified lines
104107 " fails when passed a note with a note name longer than expected"
105108 self.assertRaises(ValueError, note2midi, 'CB+-3')
106109
107− @params(*list_of_unknown_notes)
110+class Test_note2midi_unknown_values(object):
111+
112+ @parametrize('note', list_of_unknown_notes)
108113 def test_note2midi_unknown_values(self, note):
109114 " unknown values throw out an error "
110− self.assertRaises(ValueError, note2midi, note)
115+ assert_raises(ValueError, note2midi, note)
111116
112−class freq2note_simple_test(unittest.TestCase):
117+class freq2note_simple_test(TestCase):
113118
114119 def test_freq2note_above(self):
115120 " make sure freq2note(441) == A4 "
@@ -119,7 +124,7 @@ class freq2note_simple_test(unittest.TestCase): · 3 unmodified lines
119124 " make sure freq2note(439) == A4 "
120125 self.assertEqual("A4", freq2note(439))
121126
122−class note2freq_simple_test(unittest.TestCase):
127+class note2freq_simple_test(TestCase):
123128
124129 def test_note2freq(self):
125130 " make sure note2freq('A3') == 220"
@@ -133,5 +138,5 @@ class note2freq_simple_test(unittest.TestCase): · 7 unmodified lines
133138 self.assertLess(abs(note2freq("A4")-440), 1.e-12)
134139
135140 if __name__ == '__main__':
136− import nose2
137− nose2.main()
141+ from _tools import run_module_suite
142+ run_module_suite()
python/tests/test_notes.py+6−7
@@ -1,8 +1,11 @@
11 #! /usr/bin/env python
22
3−from unittest import main
43 from numpy.testing import TestCase, assert_equal, assert_almost_equal
5−from aubio import notes
4+from aubio import notes, source
5+import numpy as np
6+from utils import list_all_sounds
7+
8+list_of_sounds = list_all_sounds('sounds')
69
710 AUBIO_DEFAULT_NOTES_SILENCE = -70.
811 AUBIO_DEFAULT_NOTES_RELEASE_DROP = 10.
@@ -52,14 +55,9 @@ class aubio_notes_params(TestCase): · 43 unmodified lines
5255 with self.assertRaises(ValueError):
5356 self.o.set_release_drop(val)
5457
55−from .utils import list_all_sounds
56−list_of_sounds = list_all_sounds('sounds')
57−
5858 class aubio_notes_sinewave(TestCase):
5959
6060 def analyze_file(self, filepath, samplerate=0):
61− from aubio import source
62− import numpy as np
6361 win_s = 512 # fft size
6462 hop_s = 256 # hop size
6563
@@ -92,4 +90,5 @@ class aubio_notes_sinewave(TestCase): · 26 unmodified lines
9290 assert_equal (results[0][1], [69, 123, -1])
9391
9492 if __name__ == '__main__':
93+ from unittest import main
9594 main()
python/tests/test_onset.py+1−1
@@ -1,6 +1,5 @@
11 #! /usr/bin/env python
22
3−from unittest import main
43 from numpy.testing import TestCase, assert_equal, assert_almost_equal
54 from aubio import onset, fvec
65
@@ -116,4 +115,5 @@ class aubio_onset_coverate(TestCase): · 109 unmodified lines
116115
117116
118117 if __name__ == '__main__':
118+ from unittest import main
119119 main()
python/tests/test_phasevoc.py+13−8
@@ -1,9 +1,8 @@
11 #! /usr/bin/env python
22
33 from numpy.testing import TestCase, assert_equal, assert_array_less
4+from _tools import parametrize
45 from aubio import fvec, cvec, pvoc, float_type
5−from nose2 import main
6−from nose2.tools import params
76 import numpy as np
87
98 if float_type == 'float32':
@@ -18,7 +17,7 @@ def create_sine(hop_s, freq, samplerate): · 8 unmodified lines
1817 def create_noise(hop_s):
1918 return np.random.rand(hop_s).astype(float_type) * 2. - 1.
2019
21−class aubio_pvoc_test_case(TestCase):
20+class Test_aubio_pvoc_test_case(object):
2221 """ pvoc object test case """
2322
2423 def test_members_automatic_sizes_default(self):
@@ -65,7 +64,8 @@ class aubio_pvoc_test_case(TestCase): · 40 unmodified lines
6564 r = f.rdo(s)
6665 assert_equal ( t, 0.)
6766
68− @params(
67+ resynth_noise_args = "hop_s, ratio"
68+ resynth_noise_values = [
6969 ( 256, 8),
7070 ( 256, 4),
7171 ( 256, 2),
@@ -87,13 +87,16 @@ class aubio_pvoc_test_case(TestCase): · 15 unmodified lines
8787 (8192, 8),
8888 (8192, 4),
8989 (8192, 2),
90− )
90+ ]
91+
92+ @parametrize(resynth_noise_args, resynth_noise_values)
9193 def test_resynth_steps_noise(self, hop_s, ratio):
9294 """ check the resynthesis of a random signal is correct """
9395 sigin = create_noise(hop_s)
9496 self.reconstruction(sigin, hop_s, ratio)
9597
96− @params(
98+ resynth_sine_args = "samplerate, hop_s, ratio, freq"
99+ resynth_sine_values = [
97100 (44100, 256, 8, 441),
98101 (44100, 256, 4, 1203),
99102 (44100, 256, 2, 3045),
@@ -108,7 +111,9 @@ class aubio_pvoc_test_case(TestCase): · 8 unmodified lines
108111 (22050, 256, 8, 445),
109112 (96000, 1024, 8, 47000),
110113 (96000, 1024, 8, 20),
111− )
114+ ]
115+
116+ @parametrize(resynth_sine_args, resynth_sine_values)
112117 def test_resynth_steps_sine(self, samplerate, hop_s, ratio, freq):
113118 """ check the resynthesis of a sine is correct """
114119 sigin = create_sine(hop_s, freq, samplerate)
@@ -199,5 +204,5 @@ class aubio_pvoc_wrong_params(TestCase): · 84 unmodified lines
199204 self.skipTest('creating aubio.pvoc with size %d did not fail' % win_s)
200205
201206 if __name__ == '__main__':
207+ from unittest import main
202208 main()
203−
python/tests/test_pitch.py+5−5
@@ -1,7 +1,6 @@
11 #! /usr/bin/env python
22
3−from unittest import TestCase, main
4−from numpy.testing import assert_equal
3+from numpy.testing import TestCase, assert_equal
54 from numpy import sin, arange, mean, median, isnan, pi
65 from aubio import fvec, pitch, freqtomidi, float_type
76
@@ -116,10 +115,11 @@ def create_test (algo, mode): · 108 unmodified lines
116115
117116 for algo in pitch_algorithms:
118117 for mode in signal_modes:
119− test_method = create_test (algo, mode)
120− test_method.__name__ = 'test_pitch_%s_%d_%d_%dHz_sin_%.0f' % ( algo,
118+ _test_method = create_test (algo, mode)
119+ _test_method.__name__ = 'test_pitch_%s_%d_%d_%dHz_sin_%.0f' % ( algo,
121120 mode[0], mode[1], mode[2], mode[3] )
122− setattr (aubio_pitch_Sinusoid, test_method.__name__, test_method)
121+ setattr (aubio_pitch_Sinusoid, _test_method.__name__, _test_method)
123122
124123 if __name__ == '__main__':
124+ from unittest import main
125125 main()
python/tests/test_sink.py+16−22
@@ -1,13 +1,9 @@
11 #! /usr/bin/env python
22
3−from nose2 import main
4−from nose2.tools import params
53 from numpy.testing import TestCase
64 from aubio import fvec, source, sink
7−from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
8−
9−import warnings
10−warnings.filterwarnings('ignore', category=UserWarning, append=True)
5+from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
6+from _tools import parametrize, skipTest, assert_raises
117
128 list_of_sounds = list_all_sounds('sounds')
139 samplerates = [0, 44100, 8000, 32000]
@@ -23,30 +19,26 @@ for soundfile in list_of_sounds: · 9 unmodified lines
2319 for samplerate in samplerates:
2420 all_params.append((hop_size, samplerate, soundfile))
2521
26−class aubio_sink_test_case(TestCase):
27−
28− def setUp(self):
29− if not len(list_of_sounds):
30− self.skipTest('add some sound files in \'python/tests/sounds\'')
22+class Test_aubio_sink(object):
3123
3224 def test_wrong_filename(self):
33− with self.assertRaises(RuntimeError):
25+ with assert_raises(RuntimeError):
3426 sink('')
3527
3628 def test_wrong_samplerate(self):
37− with self.assertRaises(RuntimeError):
29+ with assert_raises(RuntimeError):
3830 sink(get_tmp_sink_path(), -1)
3931
4032 def test_wrong_samplerate_too_large(self):
41− with self.assertRaises(RuntimeError):
33+ with assert_raises(RuntimeError):
4234 sink(get_tmp_sink_path(), 1536001, 2)
4335
4436 def test_wrong_channels(self):
45− with self.assertRaises(RuntimeError):
37+ with assert_raises(RuntimeError):
4638 sink(get_tmp_sink_path(), 44100, -1)
4739
4840 def test_wrong_channels_too_large(self):
49− with self.assertRaises(RuntimeError):
41+ with assert_raises(RuntimeError):
5042 sink(get_tmp_sink_path(), 44100, 202020)
5143
5244 def test_many_sinks(self):
@@ -66,13 +58,13 @@ class aubio_sink_test_case(TestCase): · 13 unmodified lines
6658 g.close()
6759 shutil.rmtree(tmpdir)
6860
69− @params(*all_params)
61+ @parametrize('hop_size, samplerate, path', all_params)
7062 def test_read_and_write(self, hop_size, samplerate, path):
71−
7263 try:
7364 f = source(path, samplerate, hop_size)
7465 except RuntimeError as e:
75− self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
66+ err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
67+ skipTest(err_msg.format(str(e), hop_size, samplerate))
7668 if samplerate == 0: samplerate = f.samplerate
7769 sink_path = get_tmp_sink_path()
7870 g = sink(sink_path, samplerate)
@@ -84,12 +76,13 @@ class aubio_sink_test_case(TestCase): · 5 unmodified lines
8476 if read < f.hop_size: break
8577 del_tmp_sink_path(sink_path)
8678
87− @params(*all_params)
79+ @parametrize('hop_size, samplerate, path', all_params)
8880 def test_read_and_write_multi(self, hop_size, samplerate, path):
8981 try:
9082 f = source(path, samplerate, hop_size)
9183 except RuntimeError as e:
92− self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
84+ err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
85+ skipTest(err_msg.format(str(e), hop_size, samplerate))
9386 if samplerate == 0: samplerate = f.samplerate
9487 sink_path = get_tmp_sink_path()
9588 g = sink(sink_path, samplerate, channels = f.channels)
@@ -125,4 +118,5 @@ class aubio_sink_test_case(TestCase): · 29 unmodified lines
125118 g(vec, 128)
126119
127120 if __name__ == '__main__':
128− main()
121+ from _tools import run_module_suite
122+ run_module_suite()
python/tests/test_slicing.py+3−3
@@ -1,10 +1,9 @@
11 #! /usr/bin/env python
22
3−from unittest import main
43 from numpy.testing import TestCase, assert_equal
54 from aubio import slice_source_at_stamps
6−from .utils import count_files_in_directory, get_default_test_sound
7−from .utils import count_samples_in_directory, count_samples_in_file
5+from utils import count_files_in_directory, get_default_test_sound
6+from utils import count_samples_in_directory, count_samples_in_file
87
98 import tempfile
109 import shutil
@@ -167,4 +166,5 @@ class aubio_slicing_wrong_ends_test_case(TestCase): · 156 unmodified lines
167166 shutil.rmtree(self.output_dir)
168167
169168 if __name__ == '__main__':
169+ from unittest import main
170170 main()
python/tests/test_source.py+56−53
@@ -1,19 +1,17 @@
11 #! /usr/bin/env python
22
3−from nose2 import main
4−from nose2.tools import params
3+
54 from numpy.testing import TestCase, assert_equal
65 from aubio import source
7−from .utils import list_all_sounds
8−
9−import warnings
10−warnings.filterwarnings('ignore', category=UserWarning, append=True)
6+from utils import list_all_sounds
7+import unittest
8+from _tools import parametrize, assert_raises, assert_equal, skipTest
119
1210 list_of_sounds = list_all_sounds('sounds')
1311 samplerates = [0, 44100, 8000, 32000]
1412 hop_sizes = [512, 1024, 64]
1513
16−path = None
14+default_test_sound = len(list_of_sounds) and list_of_sounds[0] or None
1715
1816 all_params = []
1917 for soundfile in list_of_sounds:
@@ -21,24 +19,20 @@ for soundfile in list_of_sounds: · 1 unmodified line
2119 for samplerate in samplerates:
2220 all_params.append((hop_size, samplerate, soundfile))
2321
22+no_sounds_msg = "no test sounds, add some in 'python/tests/sounds/'!"
2423
25−class aubio_source_test_case_base(TestCase):
26−
27− def setUp(self):
28− if not len(list_of_sounds):
29− self.skipTest('add some sound files in \'python/tests/sounds\'')
30− self.default_test_sound = list_of_sounds[0]
24+_debug = False
3125
32−class aubio_source_test_case(aubio_source_test_case_base):
26+class Test_aubio_source_test_case(object):
3327
34− @params(*list_of_sounds)
28+ @parametrize('filename', list_of_sounds)
3529 def test_close_file(self, filename):
3630 samplerate = 0 # use native samplerate
3731 hop_size = 256
3832 f = source(filename, samplerate, hop_size)
3933 f.close()
4034
41− @params(*list_of_sounds)
35+ @parametrize('filename', list_of_sounds)
4236 def test_close_file_twice(self, filename):
4337 samplerate = 0 # use native samplerate
4438 hop_size = 256
@@ -46,7 +40,7 @@ class aubio_source_test_case(aubio_source_test_case_base): · 1 unmodified line
4640 f.close()
4741 f.close()
4842
49−class aubio_source_read_test_case(aubio_source_test_case_base):
43+class Test_aubio_source_read(object):
5044
5145 def read_from_source(self, f):
5246 total_frames = 0
@@ -56,47 +50,51 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 3 unmodified lines
5650 if read < f.hop_size:
5751 assert_equal(samples[read:], 0)
5852 break
59− #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}"
60− #result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri
61− #print (result_str.format(*result_params))
53+ if _debug:
54+ result_str = "read {:.2f}s ({:d} frames"
55+ result_str += " in {:d} blocks at {:d}Hz) from {:s}"
56+ result_params = total_frames / float(f.samplerate), total_frames, \
57+ total_frames//f.hop_size, f.samplerate, f.uri
58+ print (result_str.format(*result_params))
6259 return total_frames
6360
64− @params(*all_params)
61+ @parametrize('hop_size, samplerate, soundfile', all_params)
6562 def test_samplerate_hopsize(self, hop_size, samplerate, soundfile):
6663 try:
6764 f = source(soundfile, samplerate, hop_size)
6865 except RuntimeError as e:
69− self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
66+ err_msg = 'failed opening with hop_s={:d}, samplerate={:d} ({:s})'
67+ skipTest(err_msg.format(hop_size, samplerate, str(e)))
7068 assert f.samplerate != 0
7169 read_frames = self.read_from_source(f)
7270 if 'f_' in soundfile and samplerate == 0:
7371 import re
74− f = re.compile('.*_\([0:9]*f\)_.*')
72+ f = re.compile(r'.*_\([0:9]*f\)_.*')
7573 match_f = re.findall('([0-9]*)f_', soundfile)
7674 if len(match_f) == 1:
7775 expected_frames = int(match_f[0])
78− self.assertEqual(expected_frames, read_frames)
76+ assert_equal(expected_frames, read_frames)
7977
80− @params(*list_of_sounds)
78+ @parametrize('p', list_of_sounds)
8179 def test_samplerate_none(self, p):
8280 f = source(p)
8381 assert f.samplerate != 0
8482 self.read_from_source(f)
8583
86− @params(*list_of_sounds)
84+ @parametrize('p', list_of_sounds)
8785 def test_samplerate_0(self, p):
8886 f = source(p, 0)
8987 assert f.samplerate != 0
9088 self.read_from_source(f)
9189
92− @params(*list_of_sounds)
90+ @parametrize('p', list_of_sounds)
9391 def test_zero_hop_size(self, p):
9492 f = source(p, 0, 0)
9593 assert f.samplerate != 0
9694 assert f.hop_size != 0
9795 self.read_from_source(f)
9896
99− @params(*list_of_sounds)
97+ @parametrize('p', list_of_sounds)
10098 def test_seek_to_half(self, p):
10199 from random import randint
102100 f = source(p, 0, 0)
@@ -108,7 +106,7 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 5 unmodified lines
108106 b = self.read_from_source(f)
109107 assert a == b + c
110108
111− @params(*list_of_sounds)
109+ @parametrize('p', list_of_sounds)
112110 def test_duration(self, p):
113111 total_frames = 0
114112 f = source(p)
@@ -117,43 +115,44 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 2 unmodified lines
117115 _, read = f()
118116 total_frames += read
119117 if read < f.hop_size: break
120− self.assertEqual(duration, total_frames)
118+ assert_equal (duration, total_frames)
121119
122120
123−class aubio_source_test_wrong_params(TestCase):
121+class Test_aubio_source_wrong_params(object):
124122
125123 def test_wrong_file(self):
126− with self.assertRaises(RuntimeError):
124+ with assert_raises(RuntimeError):
127125 source('path_to/unexisting file.mp3')
128126
129−class aubio_source_test_wrong_params_with_file(aubio_source_test_case_base):
127+@unittest.skipIf(default_test_sound is None, no_sounds_msg)
128+class Test_aubio_source_wrong_params_with_file(TestCase):
130129
131130 def test_wrong_samplerate(self):
132− with self.assertRaises(ValueError):
133− source(self.default_test_sound, -1)
131+ with assert_raises(ValueError):
132+ source(default_test_sound, -1)
134133
135134 def test_wrong_hop_size(self):
136− with self.assertRaises(ValueError):
137− source(self.default_test_sound, 0, -1)
135+ with assert_raises(ValueError):
136+ source(default_test_sound, 0, -1)
138137
139138 def test_wrong_channels(self):
140− with self.assertRaises(ValueError):
141− source(self.default_test_sound, 0, 0, -1)
139+ with assert_raises(ValueError):
140+ source(default_test_sound, 0, 0, -1)
142141
143142 def test_wrong_seek(self):
144− f = source(self.default_test_sound)
145− with self.assertRaises(ValueError):
143+ f = source(default_test_sound)
144+ with assert_raises(ValueError):
146145 f.seek(-1)
147146
148147 def test_wrong_seek_too_large(self):
149− f = source(self.default_test_sound)
148+ f = source(default_test_sound)
150149 try:
151− with self.assertRaises(ValueError):
150+ with assert_raises(ValueError):
152151 f.seek(f.duration + f.samplerate * 10)
153− except AssertionError:
154− self.skipTest('seeking after end of stream failed raising ValueError')
152+ except:
153+ skipTest('seeking after end of stream failed raising ValueError')
155154
156−class aubio_source_readmulti_test_case(aubio_source_read_test_case):
155+class Test_aubio_source_readmulti(Test_aubio_source_read):
157156
158157 def read_from_source(self, f):
159158 total_frames = 0
@@ -163,15 +162,18 @@ class aubio_source_readmulti_test_case(aubio_source_read_test_case): · 3 unmodified lines
163162 if read < f.hop_size:
164163 assert_equal(samples[:,read:], 0)
165164 break
166− #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"
167− #result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri
168− #print (result_str.format(*result_params))
165+ if _debug:
166+ result_str = "read {:.2f}s ({:d} frames in {:d} channels"
167+ result_str += " and {:d} blocks at {:d}Hz) from {:s}"
168+ result_params = total_frames / float(f.samplerate), total_frames, \
169+ f.channels, int(total_frames/f.hop_size), \
170+ f.samplerate, f.uri
171+ print (result_str.format(*result_params))
169172 return total_frames
170173
171−class aubio_source_with(aubio_source_test_case_base):
174+class Test_aubio_source_with(object):
172175
173− #@params(*list_of_sounds)
174− @params(*list_of_sounds)
176+ @parametrize('filename', list_of_sounds)
175177 def test_read_from_mono(self, filename):
176178 total_frames = 0
177179 hop_size = 2048
@@ -185,4 +187,5 @@ class aubio_source_with(aubio_source_test_case_base): · 7 unmodified lines
185187 assert_equal(total_frames, input_source.duration)
186188
187189 if __name__ == '__main__':
188− main()
190+ from _tools import run_module_suite
191+ run_module_suite()
python/tests/test_source_channels.py+1−1
@@ -8,7 +8,7 @@ import unittest · 7 unmodified lines
88 import aubio
99 import numpy as np
1010 from numpy.testing import assert_equal
11−from .utils import get_tmp_sink_path
11+from utils import get_tmp_sink_path
1212
1313 class aubio_source_test_case(unittest.TestCase):
1414
python/tests/test_specdesc.py+1−1
@@ -1,6 +1,5 @@
11 #! /usr/bin/env python
22
3−from unittest import main
43 from numpy.testing import TestCase, assert_equal, assert_almost_equal
54 from numpy import random, arange, log, zeros
65 from aubio import specdesc, cvec, float_type
@@ -229,4 +228,5 @@ class aubio_specdesc_wrong(TestCase): · 222 unmodified lines
229228 specdesc("unknown", 512)
230229
231230 if __name__ == '__main__':
231+ from unittest import main
232232 main()
python/tests/test_zero_crossing_rate.py+1−1
@@ -1,6 +1,5 @@
11 #! /usr/bin/env python
22
3−from unittest import main
43 from numpy.testing import TestCase
54 from aubio import fvec, zero_crossing_rate
65
@@ -43,4 +42,5 @@ class zero_crossing_rate_test_case(TestCase): · 36 unmodified lines
4342 self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
4443
4544 if __name__ == '__main__':
45+ from unittest import main
4646 main()
python/tests/utils.py+6−12
@@ -8,11 +8,8 @@ from tempfile import mkstemp · 7 unmodified lines
88 DEFAULT_SOUND = '22050Hz_5s_brownnoise.wav'
99
1010 def array_from_text_file(filename, dtype = 'float'):
11− filename = os.path.join(os.path.dirname(__file__), filename)
12− with open(filename) as f:
13− lines = f.readlines()
14− return np.array([line.split() for line in lines],
15− dtype = dtype)
11+ realpathname = os.path.join(os.path.dirname(__file__), filename)
12+ return np.loadtxt(realpathname, dtype = dtype)
1613
1714 def list_all_sounds(rel_dir):
1815 datadir = os.path.join(os.path.dirname(__file__), rel_dir)
@@ -38,13 +35,10 @@ def del_tmp_sink_path(path): · 19 unmodified lines
3835 try:
3936 os.unlink(path)
4037 except WindowsError as e:
41− print("deleting {:s} failed ({:s}), reopening".format(path, repr(e)))
42− with open(path, 'wb') as f:
43− f.close()
44− try:
45− os.unlink(path)
46− except WindowsError as f:
47− print("deleting {:s} failed ({:s}), aborting".format(path, repr(e)))
38+ # removing the temporary directory sometimes fails on windows
39+ import warnings
40+ errmsg = "failed deleting temporary file {:s} ({:s})"
41+ warnings.warn(UserWarning(errmsg.format(path, repr(e))))
4842
4943 def array_from_yaml_file(filename):
5044 import yaml

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