Changeset 633400d for python/tests


Ignore:
Timestamp:
Dec 5, 2018, 10:34:39 PM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
Children:
283a619a
Parents:
5b46bc3 (diff), f19db54 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into feature/pitchshift

Location:
python/tests
Files:
9 added
16 edited

Legend:

Unmodified
Added
Removed
  • python/tests/eval_pitch

    r5b46bc3 r633400d  
    2525import os.path
    2626import numpy
    27 from utils import array_from_text_file, array_from_yaml_file
     27from .utils import array_from_text_file, array_from_yaml_file
    2828from aubio import source, pitch, freqtomidi
    2929
  • python/tests/test_aubio.py

    r5b46bc3 r633400d  
    1010        import aubio
    1111
     12    def test_version(self):
     13        """ test aubio.version """
     14        import aubio
     15        self.assertEqual('0', aubio.version[0])
     16
    1217if __name__ == '__main__':
    1318    main()
  • python/tests/test_fft.py

    r5b46bc3 r633400d  
    3434        fftgrain = f (timegrain)
    3535        assert_equal ( fftgrain.norm, 0 )
    36         assert_equal ( fftgrain.phas, 0 )
     36        try:
     37            assert_equal ( fftgrain.phas, 0 )
     38        except AssertionError:
     39            assert_equal (fftgrain.phas[fftgrain.phas > 0], +pi)
     40            assert_equal (fftgrain.phas[fftgrain.phas < 0], -pi)
     41            assert_equal (np.abs(fftgrain.phas[np.abs(fftgrain.phas) != pi]), 0)
     42            self.skipTest('fft(fvec(%d)).phas != +0, ' % win_s \
     43                    + 'This is expected when using fftw3 on powerpc.')
    3744
    3845    def test_impulse(self):
     
    136143        assert_almost_equal ( r[1:], 0)
    137144
     145class aubio_fft_odd_sizes(TestCase):
     146
     147    def test_reconstruct_with_odd_size(self):
     148        win_s = 29
     149        self.recontruct(win_s, 'odd sizes not supported')
     150
     151    def test_reconstruct_with_radix15(self):
     152        win_s = 2 ** 4 * 15
     153        self.recontruct(win_s, 'radix 15 supported')
     154
     155    def test_reconstruct_with_radix5(self):
     156        win_s = 2 ** 4 * 5
     157        self.recontruct(win_s, 'radix 5 supported')
     158
     159    def test_reconstruct_with_radix3(self):
     160        win_s = 2 ** 4 * 3
     161        self.recontruct(win_s, 'radix 3 supported')
     162
     163    def recontruct(self, win_s, skipMessage):
     164        try:
     165            f = fft(win_s)
     166        except RuntimeError:
     167            self.skipTest(skipMessage)
     168        input_signal = fvec(win_s)
     169        input_signal[win_s//2] = 1
     170        c = f(input_signal)
     171        output_signal = f.rdo(c)
     172        assert_almost_equal(input_signal, output_signal)
     173
     174class aubio_fft_wrong_params(TestCase):
     175
    138176    def test_large_input_timegrain(self):
    139177        win_s = 1024
     
    163201        with self.assertRaises(ValueError):
    164202            f.rdo(s)
    165 
    166 class aubio_fft_wrong_params(TestCase):
    167203
    168204    def test_wrong_buf_size(self):
     
    170206        with self.assertRaises(ValueError):
    171207            fft(win_s)
    172 
    173     def test_buf_size_not_power_of_two(self):
    174         # when compiled with fftw3, aubio supports non power of two fft sizes
    175         win_s = 320
    176         try:
    177             with self.assertRaises(RuntimeError):
    178                 fft(win_s)
    179         except AssertionError:
    180             self.skipTest('creating aubio.fft with size %d did not fail' % win_s)
    181208
    182209    def test_buf_size_too_small(self):
  • python/tests/test_filter.py

    r5b46bc3 r633400d  
    44from numpy.testing import TestCase, assert_equal, assert_almost_equal
    55from aubio import fvec, digital_filter
    6 from utils import array_from_text_file
     6from .utils import array_from_text_file
    77
    88class aubio_filter_test_case(TestCase):
     
    7878            f.set_biquad(0., 0., 0, 0., 0.)
    7979
     80    def test_all_available_presets(self):
     81        f = digital_filter(7)
     82        for sr in [8000, 11025, 16000, 22050, 24000, 32000,
     83                44100, 48000, 88200, 96000, 192000]:
     84            f.set_a_weighting(sr)
     85        f = digital_filter(5)
     86        for sr in [8000, 11025, 16000, 22050, 24000, 32000,
     87                44100, 48000, 88200, 96000, 192000]:
     88            f.set_c_weighting(sr)
     89
    8090class aubio_filter_wrong_params(TestCase):
    8191
  • python/tests/test_filterbank.py

    r5b46bc3 r633400d  
    11#! /usr/bin/env python
    22
    3 from unittest import main
    4 from numpy.testing import TestCase
    5 from numpy.testing import assert_equal, assert_almost_equal
    63import numpy as np
     4from numpy.testing import TestCase, assert_equal, assert_almost_equal
     5
    76from aubio import cvec, filterbank, float_type
    8 from utils import array_from_text_file
     7from .utils import array_from_text_file
    98
    109class aubio_filterbank_test_case(TestCase):
     
    6362        assert_almost_equal ( expected, f.get_coeffs() )
    6463
     64    def test_mfcc_coeffs_get_coeffs(self):
     65        f = filterbank(40, 512)
     66        coeffs = f.get_coeffs()
     67        self.assertIsInstance(coeffs, np.ndarray)
     68        assert_equal (coeffs, 0)
     69        assert_equal (np.shape(coeffs), (40, 512 / 2 + 1))
     70
    6571class aubio_filterbank_wrong_values(TestCase):
    6672
     
    8288
    8389if __name__ == '__main__':
    84     main()
     90    import nose2
     91    nose2.main()
  • python/tests/test_filterbank_mel.py

    r5b46bc3 r633400d  
    11#! /usr/bin/env python
    22
    3 from unittest import main
    4 from numpy.testing import TestCase
    5 from numpy.testing import assert_equal, assert_almost_equal
    6 from numpy import array, shape
    7 from aubio import cvec, filterbank, float_type
     3import numpy as np
     4from numpy.testing import TestCase, assert_equal, assert_almost_equal
     5
     6from aubio import fvec, cvec, filterbank, float_type
     7
     8import warnings
     9warnings.filterwarnings('ignore', category=UserWarning, append=True)
    810
    911class aubio_filterbank_mel_test_case(TestCase):
     
    1315        f.set_mel_coeffs_slaney(16000)
    1416        a = f.get_coeffs()
    15         assert_equal(shape (a), (40, 512/2 + 1) )
     17        assert_equal(np.shape (a), (40, 512/2 + 1) )
    1618
    1719    def test_other_slaney(self):
    1820        f = filterbank(40, 512*2)
    1921        f.set_mel_coeffs_slaney(44100)
    20         _ = f.get_coeffs()
     22        self.assertIsInstance(f.get_coeffs(), np.ndarray)
    2123        #print "sum is", sum(sum(a))
    2224        for win_s in [256, 512, 1024, 2048, 4096]:
    2325            f = filterbank(40, win_s)
    2426            f.set_mel_coeffs_slaney(32000)
    25             _ = f.get_coeffs()
    2627            #print "sum is", sum(sum(a))
     28            self.assertIsInstance(f.get_coeffs(), np.ndarray)
    2729
    2830    def test_triangle_freqs_zeros(self):
    2931        f = filterbank(9, 1024)
    3032        freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
    31         freqs = array(freq_list, dtype = float_type)
     33        freqs = np.array(freq_list, dtype = float_type)
    3234        f.set_triangle_bands(freqs, 48000)
    33         _ = f.get_coeffs().T
    3435        assert_equal ( f(cvec(1024)), 0)
     36        self.assertIsInstance(f.get_coeffs(), np.ndarray)
    3537
    3638    def test_triangle_freqs_ones(self):
    3739        f = filterbank(9, 1024)
    3840        freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
    39         freqs = array(freq_list, dtype = float_type)
     41        freqs = np.array(freq_list, dtype = float_type)
    4042        f.set_triangle_bands(freqs, 48000)
    41         _ = f.get_coeffs().T
     43        self.assertIsInstance(f.get_coeffs(), np.ndarray)
    4244        spec = cvec(1024)
    4345        spec.norm[:] = 1
     
    4648                    0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345])
    4749
     50    def test_triangle_freqs_with_zeros(self):
     51        """make sure set_triangle_bands works when list starts with 0"""
     52        freq_list = [0, 40, 80]
     53        freqs = np.array(freq_list, dtype = float_type)
     54        f = filterbank(len(freqs)-2, 1024)
     55        f.set_triangle_bands(freqs, 48000)
     56        assert_equal ( f(cvec(1024)), 0)
     57        self.assertIsInstance(f.get_coeffs(), np.ndarray)
     58
     59    def test_triangle_freqs_with_wrong_negative(self):
     60        """make sure set_triangle_bands fails when list contains a negative"""
     61        freq_list = [-10, 0, 80]
     62        f = filterbank(len(freq_list)-2, 1024)
     63        with self.assertRaises(ValueError):
     64            f.set_triangle_bands(fvec(freq_list), 48000)
     65
     66    def test_triangle_freqs_with_wrong_ordering(self):
     67        """make sure set_triangle_bands fails when list not ordered"""
     68        freq_list = [0, 80, 40]
     69        f = filterbank(len(freq_list)-2, 1024)
     70        with self.assertRaises(ValueError):
     71            f.set_triangle_bands(fvec(freq_list), 48000)
     72
     73    def test_triangle_freqs_with_large_freq(self):
     74        """make sure set_triangle_bands warns when freq > nyquist"""
     75        samplerate = 22050
     76        freq_list = [0, samplerate//4, samplerate // 2 + 1]
     77        f = filterbank(len(freq_list)-2, 1024)
     78        # TODO add assert_warns
     79        f.set_triangle_bands(fvec(freq_list), samplerate)
     80
     81    def test_triangle_freqs_with_not_enough_filters(self):
     82        """make sure set_triangle_bands warns when not enough filters"""
     83        samplerate = 22050
     84        freq_list = [0, 100, 1000, 4000, 8000, 10000]
     85        f = filterbank(len(freq_list)-3, 1024)
     86        # TODO add assert_warns
     87        f.set_triangle_bands(fvec(freq_list), samplerate)
     88
     89    def test_triangle_freqs_with_too_many_filters(self):
     90        """make sure set_triangle_bands warns when too many filters"""
     91        samplerate = 22050
     92        freq_list = [0, 100, 1000, 4000, 8000, 10000]
     93        f = filterbank(len(freq_list)-1, 1024)
     94        # TODO add assert_warns
     95        f.set_triangle_bands(fvec(freq_list), samplerate)
     96
     97    def test_triangle_freqs_with_double_value(self):
     98        """make sure set_triangle_bands works with 2 duplicate freqs"""
     99        samplerate = 22050
     100        freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
     101        f = filterbank(len(freq_list)-2, 1024)
     102        # TODO add assert_warns
     103        f.set_triangle_bands(fvec(freq_list), samplerate)
     104
     105    def test_triangle_freqs_with_triple(self):
     106        """make sure set_triangle_bands works with 3 duplicate freqs"""
     107        samplerate = 22050
     108        freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
     109        f = filterbank(len(freq_list)-2, 1024)
     110        # TODO add assert_warns
     111        f.set_triangle_bands(fvec(freq_list), samplerate)
     112
     113    def test_triangle_freqs_without_norm(self):
     114        """make sure set_triangle_bands works without """
     115        samplerate = 22050
     116        freq_list = fvec([0, 100, 1000, 10000])
     117        f = filterbank(len(freq_list) - 2, 1024)
     118        f.set_norm(0)
     119        f.set_triangle_bands(freq_list, samplerate)
     120        expected = f.get_coeffs()
     121        f.set_norm(1)
     122        f.set_triangle_bands(fvec(freq_list), samplerate)
     123        assert_almost_equal(f.get_coeffs().T,
     124                expected.T * 2. / (freq_list[2:] - freq_list[:-2]))
     125
     126    def test_triangle_freqs_wrong_norm(self):
     127        f = filterbank(10, 1024)
     128        with self.assertRaises(ValueError):
     129            f.set_norm(-1)
     130
     131    def test_triangle_freqs_with_power(self):
     132        f = filterbank(9, 1024)
     133        freqs = fvec([40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000,
     134            24000])
     135        f.set_power(2)
     136        f.set_triangle_bands(freqs, 48000)
     137        spec = cvec(1024)
     138        spec.norm[:] = .1
     139        expected = fvec([0.02070313, 0.02138672, 0.02127604, 0.02135417,
     140            0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345])
     141        expected /= 100.
     142        assert_almost_equal(f(spec), expected)
     143
     144    def test_mel_coeffs(self):
     145        f = filterbank(40, 1024)
     146        f.set_mel_coeffs(44100, 0, 44100 / 2)
     147
     148    def test_zero_fmax(self):
     149        f = filterbank(40, 1024)
     150        f.set_mel_coeffs(44100, 0, 0)
     151
     152    def test_wrong_mel_coeffs(self):
     153        f = filterbank(40, 1024)
     154        with self.assertRaises(ValueError):
     155            f.set_mel_coeffs_slaney(0)
     156        with self.assertRaises(ValueError):
     157            f.set_mel_coeffs(44100, 0, -44100 / 2)
     158        with self.assertRaises(ValueError):
     159            f.set_mel_coeffs(44100, -0.1, 44100 / 2)
     160        with self.assertRaises(ValueError):
     161            f.set_mel_coeffs(-44100, 0.1, 44100 / 2)
     162        with self.assertRaises(ValueError):
     163            f.set_mel_coeffs_htk(-1, 0, 0)
     164
     165    def test_mel_coeffs_htk(self):
     166        f = filterbank(40, 1024)
     167        f.set_mel_coeffs_htk(44100, 0, 44100 / 2)
     168
     169
    48170if __name__ == '__main__':
    49     main()
     171    import nose2
     172    nose2.main()
  • python/tests/test_fvec.py

    r5b46bc3 r633400d  
    6060        self.assertRaises(IndexError, a.__getitem__, 3)
    6161        self.assertRaises(IndexError, a.__getitem__, 2)
     62
     63    def test_wrong_dimensions(self):
     64        a = np.array([[[1, 2], [3, 4]]], dtype=float_type)
     65        self.assertRaises(ValueError, fvec, a)
     66
     67    def test_wrong_size(self):
     68        a = np.ndarray([0,], dtype=float_type)
     69        self.assertRaises(ValueError, fvec, a)
    6270
    6371class aubio_wrong_fvec_input(TestCase):
  • python/tests/test_mfcc.py

    r5b46bc3 r633400d  
    111111        #print coeffs
    112112
     113
     114class aubio_mfcc_fb_params(TestCase):
     115
     116    def test_set_scale(self):
     117        buf_size, n_filters, n_coeffs, samplerate = 512, 20, 10, 16000
     118        m = mfcc(buf_size, n_filters, n_coeffs, samplerate)
     119        m.set_scale(10.5)
     120        assert m.get_scale() == 10.5
     121        m(cvec(buf_size))
     122
     123    def test_set_power(self):
     124        buf_size, n_filters, n_coeffs, samplerate = 512, 20, 10, 16000
     125        m = mfcc(buf_size, n_filters, n_coeffs, samplerate)
     126        m.set_power(2.5)
     127        assert m.get_power() == 2.5
     128        m(cvec(buf_size))
     129
     130    def test_set_mel_coeffs(self):
     131        buf_size, n_filters, n_coeffs, samplerate = 512, 20, 10, 16000
     132        m = mfcc(buf_size, n_filters, n_coeffs, samplerate)
     133        m.set_mel_coeffs(0., samplerate/2.)
     134        m(cvec(buf_size))
     135
     136    def test_set_mel_coeffs_htk(self):
     137        buf_size, n_filters, n_coeffs, samplerate = 512, 20, 10, 16000
     138        m = mfcc(buf_size, n_filters, n_coeffs, samplerate)
     139        m.set_mel_coeffs_htk(0., samplerate/2.)
     140        m(cvec(buf_size))
     141
     142    def test_set_mel_coeffs_slaney(self):
     143        buf_size, n_filters, n_coeffs, samplerate = 512, 40, 10, 16000
     144        m = mfcc(buf_size, n_filters, n_coeffs, samplerate)
     145        m.set_mel_coeffs_slaney()
     146        m(cvec(buf_size))
     147        assert m.get_power() == 1
     148        assert m.get_scale() == 1
     149
    113150if __name__ == '__main__':
    114151    main()
  • python/tests/test_midi2note.py

    r5b46bc3 r633400d  
    33
    44from aubio import midi2note
     5from nose2.tools import params
    56import unittest
    67
     
    1718class midi2note_good_values(unittest.TestCase):
    1819
    19     def test_midi2note_known_values(self):
     20    @params(*list_of_known_midis)
     21    def test_midi2note_known_values(self, midi, note):
    2022        " known values are correctly converted "
    21         for midi, note in list_of_known_midis:
    22             self.assertEqual ( midi2note(midi), note )
     23        self.assertEqual ( midi2note(midi), note )
    2324
    2425class midi2note_wrong_values(unittest.TestCase):
     
    4142
    4243if __name__ == '__main__':
    43     unittest.main()
     44    import nose2
     45    nose2.main()
  • python/tests/test_note2midi.py

    r5b46bc3 r633400d  
    44from __future__ import unicode_literals
    55
    6 from aubio import note2midi, freq2note
     6from aubio import note2midi, freq2note, note2freq, float_type
     7from nose2.tools import params
    78import unittest
    89
     
    1415        ( 'B3', 59 ),
    1516        ( 'B#3', 60 ),
     17        ( 'C♯4', 61 ),
    1618        ( 'A4', 69 ),
    1719        ( 'A#4', 70 ),
     20        ( 'A♯4', 70 ),
     21        ( 'A\u266f4', 70 ),
    1822        ( 'Bb4', 70 ),
    1923        ( 'B♭4', 70 ),
     24        ( 'B\u266d4', 70 ),
    2025        ( 'G8', 115 ),
    2126        ( 'G♯8', 116 ),
    2227        ( 'G9', 127 ),
    23         ( 'G\udd2a2', 45 ),
    24         ( 'B\ufffd2', 45 ),
    2528        ( 'A♮2', 45 ),
     29        )
     30
     31list_of_known_notes_with_unicode_issues = (
     32        ('C𝄪4', 62 ),
     33        ('E𝄫4', 62 ),
     34        )
     35
     36list_of_unknown_notes = (
     37        ( 'G\udd2a2' ),
     38        ( 'B\ufffd2' ),
     39        ( 'B\u266e\u266e2' ),
     40        ( 'B\u266f\u266d3' ),
     41        ( 'B33' ),
     42        ( 'C.3' ),
     43        ( 'A' ),
     44        ( '2' ),
    2645        )
    2746
    2847class note2midi_good_values(unittest.TestCase):
    2948
    30     def test_note2midi_known_values(self):
     49    @params(*list_of_known_notes)
     50    def test_note2midi_known_values(self, note, midi):
    3151        " known values are correctly converted "
    32         for note, midi in list_of_known_notes:
     52        self.assertEqual ( note2midi(note), midi )
     53
     54    @params(*list_of_known_notes_with_unicode_issues)
     55    def test_note2midi_known_values_with_unicode_issues(self, note, midi):
     56        " known values are correctly converted, unless decoding is expected to fail"
     57        try:
    3358            self.assertEqual ( note2midi(note), midi )
     59        except UnicodeEncodeError as e:
     60            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            if len('\U0001D12A') != 1 and sys.version[0] == '2':
     65                self.skipTest(strres + " | upgrade to Python 3 to fix")
     66            else:
     67                raise
    3468
    3569class note2midi_wrong_values(unittest.TestCase):
     
    67101        self.assertRaises(TypeError, note2midi, 123)
    68102
     103    def test_note2midi_wrong_data_too_long(self):
     104        " fails when passed a note with a note name longer than expected"
     105        self.assertRaises(ValueError, note2midi, 'CB+-3')
     106
     107    @params(*list_of_unknown_notes)
     108    def test_note2midi_unknown_values(self, note):
     109        " unknown values throw out an error "
     110        self.assertRaises(ValueError, note2midi, note)
    69111
    70112class freq2note_simple_test(unittest.TestCase):
    71113
    72     def test_freq2note(self):
     114    def test_freq2note_above(self):
    73115        " make sure freq2note(441) == A4 "
    74116        self.assertEqual("A4", freq2note(441))
    75117
     118    def test_freq2note_under(self):
     119        " make sure freq2note(439) == A4 "
     120        self.assertEqual("A4", freq2note(439))
     121
     122class note2freq_simple_test(unittest.TestCase):
     123
     124    def test_note2freq(self):
     125        " make sure note2freq('A3') == 220"
     126        self.assertEqual(220, note2freq("A3"))
     127
     128    def test_note2freq_under(self):
     129        " make sure note2freq(A4) == 440"
     130        if float_type == 'float32':
     131            self.assertEqual(440, note2freq("A4"))
     132        else:
     133            self.assertLess(abs(note2freq("A4")-440), 1.e-12)
     134
    76135if __name__ == '__main__':
    77     unittest.main()
     136    import nose2
     137    nose2.main()
  • python/tests/test_onset.py

    r5b46bc3 r633400d  
    33from unittest import main
    44from numpy.testing import TestCase, assert_equal, assert_almost_equal
    5 from aubio import onset
     5from aubio import onset, fvec
    66
    77class aubio_onset_default(TestCase):
     
    2020
    2121    def test_get_delay(self):
    22         assert_equal (self.o.get_delay(), int(4.3 * self.o.hop_size))
     22        self.assertGreater(self.o.get_delay(), 0)
    2323
    2424    def test_get_delay_s(self):
    25         assert_almost_equal (self.o.get_delay_s(), self.o.get_delay() / float(self.samplerate))
     25        self.assertGreater(self.o.get_delay_s(), 0.)
    2626
    2727    def test_get_delay_ms(self):
    28         assert_almost_equal (self.o.get_delay_ms(), self.o.get_delay() * 1000. / self.samplerate, 5)
     28        self.assertGreater(self.o.get_delay_ms(), 0.)
    2929
    3030    def test_get_minioi(self):
    31         assert_almost_equal (self.o.get_minioi(), 0.02 * self.samplerate)
     31        self.assertGreater(self.o.get_minioi(), 0)
    3232
    3333    def test_get_minioi_s(self):
    34         assert_almost_equal (self.o.get_minioi_s(), 0.02)
     34        self.assertGreater(self.o.get_minioi_s(), 0.)
    3535
    3636    def test_get_minioi_ms(self):
    37         assert_equal (self.o.get_minioi_ms(), 20.)
     37        self.assertGreater(self.o.get_minioi_ms(), 0.)
    3838
    3939    def test_get_threshold(self):
    40         assert_almost_equal (self.o.get_threshold(), 0.3)
     40        self.assertGreater(self.o.get_threshold(), 0.)
    4141
    4242    def test_set_delay(self):
     
    8484    samplerate = 8000
    8585
     86class aubio_onset_coverate(TestCase):
     87    # extra tests to execute the C routines and improve coverage
     88
     89    def test_all_methods(self):
     90        for method in ['default', 'energy', 'hfc', 'complexdomain', 'complex',
     91                'phase', 'wphase', 'mkl', 'kl', 'specflux', 'specdiff',
     92                'old_default']:
     93            o = onset(method=method, buf_size=512, hop_size=256)
     94            o(fvec(256))
     95
     96    def test_get_methods(self):
     97        o = onset(method='default', buf_size=512, hop_size=256)
     98
     99        assert o.get_silence() == -70
     100        o.set_silence(-20)
     101        assert_almost_equal(o.get_silence(), -20)
     102
     103        assert o.get_compression() == 1
     104        o.set_compression(.99)
     105        assert_almost_equal(o.get_compression(), .99)
     106
     107        assert o.get_awhitening() == 0
     108        o.set_awhitening(1)
     109        assert o.get_awhitening() == 1
     110
     111        o.get_last()
     112        o.get_last_ms()
     113        o.get_last_s()
     114        o.get_descriptor()
     115        o.get_thresholded_descriptor()
     116
     117
    86118if __name__ == '__main__':
    87119    main()
  • python/tests/test_phasevoc.py

    r5b46bc3 r633400d  
    4747            assert_equal ( t, 0.)
    4848            assert_equal ( s.norm, 0.)
    49             assert_equal ( s.phas, 0.)
     49            try:
     50                assert_equal ( s.phas, 0 )
     51            except AssertionError:
     52                assert_equal (s.phas[s.phas > 0], +np.pi)
     53                assert_equal (s.phas[s.phas < 0], -np.pi)
     54                assert_equal (np.abs(s.phas[np.abs(s.phas) != np.pi]), 0)
     55                self.skipTest('pvoc(fvec(%d)).phas != +0, ' % win_s \
     56                        + 'This is expected when using fftw3 on powerpc.')
    5057            assert_equal ( r, 0.)
     58
     59    def test_no_overlap(self):
     60        win_s, hop_s = 1024, 1024
     61        f = pvoc (win_s, hop_s)
     62        t = fvec (hop_s)
     63        for _ in range(4):
     64            s = f(t)
     65            r = f.rdo(s)
     66            assert_equal ( t, 0.)
    5167
    5268    @params(
  • python/tests/test_pitch.py

    r5b46bc3 r633400d  
    7171        #print 'median errors: ', median(errors), 'median pitches: ', median(pitches)
    7272
    73 pitch_algorithms = [ "default", "yinfft", "yin", "schmitt", "mcomb", "fcomb" , "specacf" ]
    74 pitch_algorithms = [ "default", "yinfft", "yin", "schmitt", "mcomb", "fcomb" ]
     73pitch_algorithms = [ "default", "yinfft", "yin", "yinfast", "schmitt", "mcomb", "fcomb" , "specacf" ]
     74pitch_algorithms = [ "default", "yinfft", "yin", "yinfast", "schmitt", "mcomb", "fcomb" ]
    7575
    7676#freqs = [ 27.5, 55., 110., 220., 440., 880., 1760., 3520. ]
  • python/tests/test_sink.py

    r5b46bc3 r633400d  
    55from numpy.testing import TestCase
    66from aubio import fvec, source, sink
    7 from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
     7from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
     8
     9import warnings
     10warnings.filterwarnings('ignore', category=UserWarning, append=True)
    811
    912list_of_sounds = list_all_sounds('sounds')
     
    2629        if not len(list_of_sounds):
    2730            self.skipTest('add some sound files in \'python/tests/sounds\'')
     31
     32    def test_wrong_filename(self):
     33        with self.assertRaises(RuntimeError):
     34            sink('')
     35
     36    def test_wrong_samplerate(self):
     37        with self.assertRaises(RuntimeError):
     38            sink(get_tmp_sink_path(), -1)
     39
     40    def test_wrong_samplerate_too_large(self):
     41        with self.assertRaises(RuntimeError):
     42            sink(get_tmp_sink_path(), 1536001, 2)
     43
     44    def test_wrong_channels(self):
     45        with self.assertRaises(RuntimeError):
     46            sink(get_tmp_sink_path(), 44100, -1)
     47
     48    def test_wrong_channels_too_large(self):
     49        with self.assertRaises(RuntimeError):
     50            sink(get_tmp_sink_path(), 44100, 202020)
    2851
    2952    def test_many_sinks(self):
     
    94117        del_tmp_sink_path(sink_path)
    95118
     119    def test_read_with(self):
     120        samplerate = 44100
     121        sink_path = get_tmp_sink_path()
     122        vec = fvec(128)
     123        with sink(sink_path, samplerate) as g:
     124            for _ in range(10):
     125                g(vec, 128)
     126
    96127if __name__ == '__main__':
    97128    main()
  • python/tests/test_slicing.py

    r5b46bc3 r633400d  
    44from numpy.testing import TestCase, assert_equal
    55from 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
     6from .utils import count_files_in_directory, get_default_test_sound
     7from .utils import count_samples_in_directory, count_samples_in_file
    88
    99import tempfile
     
    2424    def test_slice_start_only_no_zero(self):
    2525        regions_start = [i*1000 for i in range(1, n_slices)]
    26         slice_source_at_stamps(self.source_file, regions_start, output_dir = self.output_dir)
     26        slice_source_at_stamps(self.source_file, regions_start,
     27                output_dir = self.output_dir, create_first=True)
    2728
    2829    def test_slice_start_beyond_end(self):
    2930        regions_start = [i*1000 for i in range(1, n_slices)]
    3031        regions_start += [count_samples_in_file(self.source_file) + 1000]
    31         slice_source_at_stamps(self.source_file, regions_start, output_dir = self.output_dir)
     32        slice_source_at_stamps(self.source_file, regions_start,
     33                output_dir = self.output_dir, create_first=True)
    3234
    3335    def test_slice_start_every_blocksize(self):
    3436        hopsize = 200
    35         regions_start = [i*hopsize for i in range(1, n_slices)]
     37        regions_start = [i*hopsize for i in range(0, n_slices)]
    3638        slice_source_at_stamps(self.source_file, regions_start, output_dir = self.output_dir,
    3739                hopsize = 200)
     40
     41    def test_slice_start_every_half_blocksize(self):
     42        hopsize = 200
     43        regions_start = [i*hopsize//2 for i in range(0, n_slices)]
     44        slice_source_at_stamps(self.source_file, regions_start,
     45                output_dir = self.output_dir, hopsize = 200)
    3846
    3947    def tearDown(self):
     
    92100            "number of samples written different from number of original samples")
    93101
     102    def test_slice_start_and_ends_with_missing_end(self):
     103        regions_start = [i*1000 for i in range(n_slices)]
     104        regions_ends = [r-1 for r in regions_start[1:]]
     105        slice_source_at_stamps(self.source_file, regions_start, regions_ends,
     106                output_dir = self.output_dir)
     107        written_samples = count_samples_in_directory(self.output_dir)
     108        original_samples = count_samples_in_file(self.source_file)
     109        total_files = count_files_in_directory(self.output_dir)
     110        assert_equal(n_slices, total_files,
     111            "number of slices created different from expected")
     112        assert_equal(written_samples, original_samples,
     113            "number of samples written different from number of original samples")
     114
    94115    def tearDown(self):
    95116        shutil.rmtree(self.output_dir)
     
    134155        regions_end = None
    135156        slice_source_at_stamps (self.source_file, regions_start, regions_end,
    136                 output_dir = self.output_dir)
     157                output_dir = self.output_dir, create_first=True)
    137158        total_files = count_files_in_directory(self.output_dir)
    138159        assert_equal(n_slices, total_files,
  • python/tests/test_source.py

    r5b46bc3 r633400d  
    33from nose2 import main
    44from nose2.tools import params
    5 from numpy.testing import TestCase
     5from numpy.testing import TestCase, assert_equal
    66from aubio import source
    7 from utils import list_all_sounds
     7from .utils import list_all_sounds
    88
    99import warnings
     
    5252        total_frames = 0
    5353        while True:
    54             _ , read = f()
     54            samples , read = f()
    5555            total_frames += read
    56             if read < f.hop_size: break
     56            if read < f.hop_size:
     57                assert_equal(samples[read:], 0)
     58                break
    5759        #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}"
    5860        #result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri
     
    6769            self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
    6870        assert f.samplerate != 0
    69         self.read_from_source(f)
     71        read_frames = self.read_from_source(f)
     72        if 'f_' in soundfile and samplerate == 0:
     73            import re
     74            f = re.compile('.*_\([0:9]*f\)_.*')
     75            match_f = re.findall('([0-9]*)f_', soundfile)
     76            if len(match_f) == 1:
     77                expected_frames = int(match_f[0])
     78                self.assertEqual(expected_frames, read_frames)
    7079
    7180    @params(*list_of_sounds)
     
    150159        total_frames = 0
    151160        while True:
    152             _, read = f.do_multi()
     161            samples, read = f.do_multi()
    153162            total_frames += read
    154             if read < f.hop_size: break
     163            if read < f.hop_size:
     164                assert_equal(samples[:,read:], 0)
     165                break
    155166        #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"
    156167        #result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri
     
    158169        return total_frames
    159170
     171class aubio_source_with(aubio_source_test_case_base):
     172
     173    #@params(*list_of_sounds)
     174    @params(*list_of_sounds)
     175    def test_read_from_mono(self, filename):
     176        total_frames = 0
     177        hop_size = 2048
     178        with source(filename, 0, hop_size) as input_source:
     179            assert_equal(input_source.hop_size, hop_size)
     180            #assert_equal(input_source.samplerate, samplerate)
     181            total_frames = 0
     182            for frames in input_source:
     183                total_frames += frames.shape[-1]
     184            # check we read as many samples as we expected
     185            assert_equal(total_frames, input_source.duration)
     186
    160187if __name__ == '__main__':
    161188    main()
Note: See TracChangeset for help on using the changeset viewer.