Changeset 0b6d23d for python/tests


Ignore:
Timestamp:
May 16, 2016, 5:08:18 AM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
a6f9ebf
Parents:
58a5fb9
Message:

python/tests: fix most prospect warnings

Location:
python/tests
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_aubio.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
    3 from numpy.testing import TestCase, run_module_suite
     3from unittest import main
     4from numpy.testing import TestCase
    45
    56class aubiomodule_test_case(TestCase):
    67
    7   def test_import(self):
    8     """ try importing aubio """
    9     import aubio
     8    def test_import(self):
     9        """ try importing aubio """
     10        import aubio
    1011
    1112if __name__ == '__main__':
    12   from unittest import main
    13   main()
     13    main()
    1414
  • python/tests/test_cvec.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
    3 from numpy.testing import TestCase
    4 from numpy.testing import assert_equal, assert_almost_equal
     3from unittest import main
     4import numpy as np
     5from numpy.testing import TestCase, assert_equal
    56from aubio import cvec, fvec, float_type
    6 import numpy as np
    77
    88wrong_type = 'float32' if float_type == 'float64' else 'float64'
     
    1414        assert_equal(a.norm.shape[0], 10 / 2 + 1)
    1515        assert_equal(a.phas.shape[0], 10 / 2 + 1)
    16         a.norm[0]
     16        _ = a.norm[0]
    1717        assert_equal(a.norm, 0.)
    1818        assert_equal(a.phas, 0.)
     
    143143
    144144if __name__ == '__main__':
    145     from nose2 import main
    146145    main()
  • python/tests/test_fft.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase
    45from numpy.testing import assert_equal, assert_almost_equal
     6import numpy as np
    57from aubio import fvec, fft, cvec
    6 from math import pi
     8from math import pi, floor
     9from random import random
    710
    811class aubio_fft_test_case(TestCase):
     
    3538    def test_impulse(self):
    3639        """ check the transform of one impulse at a random place """
    37         from random import random
    38         from math import floor
    3940        win_s = 256
    4041        i = int(floor(random()*win_s))
     
    5051
    5152    def test_impulse_negative(self):
    52         """ check the transform of one impulse at a random place """
    53         from random import random
    54         from math import floor
     53        """ check the transform of a negative impulse at a random place """
    5554        win_s = 256
    56         i = 0
    57         impulse = -10.
     55        i = int(floor(random()*win_s))
     56        impulse = -.1
    5857        f = fft(win_s)
    5958        timegrain = fvec(win_s)
     59        timegrain[0] = 0
    6060        timegrain[i] = impulse
    6161        fftgrain = f ( timegrain )
    6262        #self.plot_this ( fftgrain.phas )
    63         assert_almost_equal ( fftgrain.norm, abs(impulse), decimal = 6 )
     63        assert_almost_equal ( fftgrain.norm, abs(impulse), decimal = 5 )
    6464        if impulse < 0:
    6565            # phase can be pi or -pi, as it is not unwrapped
    66             assert_almost_equal ( abs(fftgrain.phas[1:-1]) , pi, decimal = 6 )
     66            #assert_almost_equal ( abs(fftgrain.phas[1:-1]) , pi, decimal = 6 )
    6767            assert_almost_equal ( fftgrain.phas[0], pi, decimal = 6)
    68             assert_almost_equal ( fftgrain.phas[-1], pi, decimal = 6)
     68            assert_almost_equal ( np.fmod(fftgrain.phas[-1], pi), 0, decimal = 6)
    6969        else:
    70             assert_equal ( fftgrain.phas[1:-1] == 0, True)
    71             assert_equal ( fftgrain.phas[0] == 0, True)
    72             assert_equal ( fftgrain.phas[-1] == 0, True)
     70            #assert_equal ( fftgrain.phas[1:-1] == 0, True)
     71            assert_equal ( fftgrain.phas[0], 0)
     72            assert_almost_equal ( np.fmod(fftgrain.phas[-1], pi), 0, decimal = 6)
    7373        # now check the resynthesis
    7474        synthgrain = f.rdo ( fftgrain )
     
    9696        """ check running fft.rdo before fft.do works """
    9797        win_s = 1024
    98         impulse = pi
    9998        f = fft(win_s)
    10099        fftgrain = cvec(win_s)
     
    178177            with self.assertRaises(RuntimeError):
    179178                fft(win_s)
    180         except AssertionError as e:
     179        except AssertionError:
    181180            self.skipTest('creating aubio.fft with size %d did not fail' % win_s)
    182181
     
    187186
    188187if __name__ == '__main__':
    189     from nose2 import main
    190188    main()
  • python/tests/test_filter.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase, assert_equal, assert_almost_equal
    45from aubio import fvec, digital_filter
    5 from numpy import array
    66from utils import array_from_text_file
    77
     
    8585
    8686if __name__ == '__main__':
    87     from unittest import main
    8887    main()
  • python/tests/test_filterbank.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase
    45from numpy.testing import assert_equal, assert_almost_equal
     
    8182
    8283if __name__ == '__main__':
    83     from nose2 import main
    8484    main()
    85 
  • python/tests/test_filterbank_mel.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
    3 from numpy.testing import TestCase, run_module_suite
     3from unittest import main
     4from numpy.testing import TestCase
    45from numpy.testing import assert_equal, assert_almost_equal
    56from numpy import array, shape
     
    89class aubio_filterbank_mel_test_case(TestCase):
    910
    10   def test_slaney(self):
    11     f = filterbank(40, 512)
    12     f.set_mel_coeffs_slaney(16000)
    13     a = f.get_coeffs()
    14     assert_equal(shape (a), (40, 512/2 + 1) )
     11    def test_slaney(self):
     12        f = filterbank(40, 512)
     13        f.set_mel_coeffs_slaney(16000)
     14        a = f.get_coeffs()
     15        assert_equal(shape (a), (40, 512/2 + 1) )
    1516
    16   def test_other_slaney(self):
    17     f = filterbank(40, 512*2)
    18     f.set_mel_coeffs_slaney(44100)
    19     a = f.get_coeffs()
    20     #print "sum is", sum(sum(a))
    21     for win_s in [256, 512, 1024, 2048, 4096]:
    22       f = filterbank(40, win_s)
    23       f.set_mel_coeffs_slaney(320000)
    24       a = f.get_coeffs()
    25       #print "sum is", sum(sum(a))
     17    def test_other_slaney(self):
     18        f = filterbank(40, 512*2)
     19        f.set_mel_coeffs_slaney(44100)
     20        _ = f.get_coeffs()
     21        #print "sum is", sum(sum(a))
     22        for win_s in [256, 512, 1024, 2048, 4096]:
     23            f = filterbank(40, win_s)
     24            f.set_mel_coeffs_slaney(32000)
     25            _ = f.get_coeffs()
     26            #print "sum is", sum(sum(a))
    2627
    27   def test_triangle_freqs_zeros(self):
    28     f = filterbank(9, 1024)
    29     freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
    30     freqs = array(freq_list, dtype = float_type)
    31     f.set_triangle_bands(freqs, 48000)
    32     f.get_coeffs().T
    33     assert_equal ( f(cvec(1024)), 0)
     28    def test_triangle_freqs_zeros(self):
     29        f = filterbank(9, 1024)
     30        freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
     31        freqs = array(freq_list, dtype = float_type)
     32        f.set_triangle_bands(freqs, 48000)
     33        _ = f.get_coeffs().T
     34        assert_equal ( f(cvec(1024)), 0)
    3435
    35   def test_triangle_freqs_ones(self):
    36     f = filterbank(9, 1024)
    37     freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
    38     freqs = array(freq_list, dtype = float_type)
    39     f.set_triangle_bands(freqs, 48000)
    40     f.get_coeffs().T
    41     spec = cvec(1024)
    42     spec.norm[:] = 1
    43     assert_almost_equal ( f(spec),
    44             [ 0.02070313,  0.02138672,  0.02127604,  0.02135417,
    45         0.02133301, 0.02133301,  0.02133311,  0.02133334, 0.02133345])
     36    def test_triangle_freqs_ones(self):
     37        f = filterbank(9, 1024)
     38        freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
     39        freqs = array(freq_list, dtype = float_type)
     40        f.set_triangle_bands(freqs, 48000)
     41        _ = f.get_coeffs().T
     42        spec = cvec(1024)
     43        spec.norm[:] = 1
     44        assert_almost_equal ( f(spec),
     45                [ 0.02070313, 0.02138672, 0.02127604, 0.02135417,
     46                    0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345])
    4647
    4748if __name__ == '__main__':
    48   from unittest import main
    49   main()
    50 
    51 
     49    main()
  • python/tests/test_fvec.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34import numpy as np
    45from numpy.testing import TestCase, assert_equal, assert_almost_equal
     
    5051        self.assertRaises(ValueError, fvec, -10)
    5152
    52     def test_negative_length(self):
     53    def test_zero_length(self):
    5354        """ test creating fvec with zero length fails (pure python) """
    5455        self.assertRaises(ValueError, fvec, 0)
     
    129130    def test_pass_to_numpy(self):
    130131        a = fvec(10)
    131         a = 1.
     132        a[:] = 1.
    132133        b = a
    133134        del a
     
    140141
    141142if __name__ == '__main__':
    142     from unittest import main
    143143    main()
  • python/tests/test_mathutils.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase, assert_equal
    45from numpy import array, arange, isnan, isinf
     
    2425        unwrap2pi(a)
    2526        a = pi/100. * arange(-600,600).astype("float")
    26         b = unwrap2pi (a)
     27        unwrap2pi(a)
    2728        #print zip(a, b)
    2829
    29         try:
    30             print (unwrap2pi(["23.","24.",25.]))
    31         except Exception as e:
    32             pass
     30    def test_unwrap2pi_fails_on_list(self):
     31        with self.assertRaises(TypeError):
     32            unwrap2pi(["23.","24.",25.])
    3333
    3434    def test_unwrap2pi_takes_fvec(self):
     
    102102
    103103if __name__ == '__main__':
    104     from unittest import main
    105104    main()
  • python/tests/test_mfcc.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
    3 from numpy.testing import TestCase, assert_equal, assert_almost_equal
    4 from numpy import random, arange, log, zeros, count_nonzero
     3from nose2 import main
     4from nose2.tools import params
     5from numpy import random, count_nonzero
     6from numpy.testing import TestCase
    57from aubio import mfcc, cvec, float_type
    6 from math import pi
    78
    89buf_size = 2048
     
    1112samplerate = 44100
    1213
    13 from nose2.tools import params
    1414
    1515new_params = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
     
    102102        spec = cvec(buf_size)
    103103        spec.phas[0] = 0.2
    104         for i in range(10):
    105             coeffs = o(spec)
     104        for _ in range(10):
     105            o(spec)
    106106        #print coeffs
    107107
    108108if __name__ == '__main__':
    109     import nose2
    110     nose2.main()
     109    main()
  • python/tests/test_midi2note.py

    r58a5fb9 r0b6d23d  
    2828        self.assertRaises(ValueError, midi2note, -2)
    2929
    30     def test_midi2note_negative_value(self):
     30    def test_midi2note_large(self):
    3131        " fails when passed a value greater than 127 "
    3232        self.assertRaises(ValueError, midi2note, 128)
  • python/tests/test_musicutils.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
     3from unittest import main
     4import numpy as np
    35from numpy.testing import TestCase
    46from numpy.testing.utils import assert_equal, assert_almost_equal
    5 from numpy import cos, arange
    6 from math import pi
    7 
    87from aubio import window, level_lin, db_spl, silence_detection, level_detection
    9 
    108from aubio import fvec, float_type
    119
     
    2624        size = 1024
    2725        aubio_window = window("hanning", size)
    28         numpy_window = .5 - .5 * cos(2. * pi * arange(size) / size)
     26        numpy_window = .5 - .5 * np.cos(2. * np.pi * np.arange(size) / size)
    2927        assert_almost_equal(aubio_window, numpy_window)
    3028
     
    3432
    3533    def test_fail_not_fvec(self):
    36         try:
     34        with self.assertRaises(ValueError):
    3735            level_lin("default")
    38         except ValueError as e:
    39             pass
    40         else:
    41             self.fail('non-number input phase does not raise a TypeError')
    4236
    4337    def test_zeros_is_zeros(self):
     
    4539
    4640    def test_minus_ones_is_one(self):
    47         from numpy import ones
    48         assert_equal(level_lin(-ones(1024, dtype = float_type)), 1.)
     41        assert_equal(level_lin(-np.ones(1024, dtype = float_type)), 1.)
    4942
    5043class aubio_db_spl(TestCase):
     
    5346
    5447    def test_fail_not_fvec(self):
    55         try:
     48        with self.assertRaises(ValueError):
    5649            db_spl("default")
    57         except ValueError as e:
    58             pass
    59         else:
    60             self.fail('non-number input phase does not raise a TypeError')
    6150
    6251    def test_zeros_is_inf(self):
    63         from math import isinf
    64         assert isinf(db_spl(fvec(1024)))
     52        assert np.isinf(db_spl(fvec(1024)))
    6553
    6654    def test_minus_ones_is_zero(self):
    67         from numpy import ones
    68         assert_equal(db_spl(-ones(1024, dtype = float_type)), 0.)
     55        assert_equal(db_spl(-np.ones(1024, dtype = float_type)), 0.)
    6956
    7057class aubio_silence_detection(TestCase):
     
    7360
    7461    def test_fail_not_fvec(self):
    75         try:
     62        with self.assertRaises(ValueError):
    7663            silence_detection("default", -70)
    77         except ValueError as e:
    78             pass
    79         else:
    80             self.fail('non-number input phase does not raise a TypeError')
    8164
    8265    def test_zeros_is_one(self):
    83         from math import isinf
    8466        assert silence_detection(fvec(1024), -70) == 1
    8567
     
    9375
    9476    def test_fail_not_fvec(self):
    95         try:
     77        with self.assertRaises(ValueError):
    9678            level_detection("default", -70)
    97         except ValueError as e:
    98             pass
    99         else:
    100             self.fail('non-number input phase does not raise a TypeError')
    10179
    10280    def test_zeros_is_one(self):
    103         from math import isinf
    10481        assert level_detection(fvec(1024), -70) == 1
    10582
     
    10986
    11087if __name__ == '__main__':
    111     from unittest import main
    11288    main()
  • python/tests/test_note2midi.py

    r58a5fb9 r0b6d23d  
    5959        self.assertRaises(ValueError, note2midi, 'W9')
    6060
    61     def test_note2midi_wrong_octave(self):
    62         " fails when passed a note with a wrong octave"
     61    def test_note2midi_low_octave(self):
     62        " fails when passed a note with a too low octave"
    6363        self.assertRaises(ValueError, note2midi, 'C-9')
    6464
  • python/tests/test_onset.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
    3 from numpy.testing import TestCase, run_module_suite
    4 from numpy.testing import assert_equal, assert_almost_equal
     3from unittest import main
     4from numpy.testing import TestCase, assert_equal, assert_almost_equal
    55from aubio import onset
    66
     
    8585
    8686if __name__ == '__main__':
    87     from unittest import main
    8887    main()
  • python/tests/test_phasevoc.py

    r58a5fb9 r0b6d23d  
    33from numpy.testing import TestCase, assert_equal, assert_array_less
    44from aubio import fvec, cvec, pvoc, float_type
     5from nose2 import main
    56from nose2.tools import params
    67import numpy as np
     
    4142        f = pvoc (win_s, hop_s)
    4243        t = fvec (hop_s)
    43         for time in range( int ( 4 * win_s / hop_s ) ):
     44        for _ in range( int ( 4 * win_s / hop_s ) ):
    4445            s = f(t)
    4546            r = f.rdo(s)
     
    103104        zeros = fvec(hop_s)
    104105        r2 = f.rdo( f(sigin) )
    105         for i in range(1, ratio):
     106        for _ in range(1, ratio):
    106107            r2 = f.rdo( f(zeros) )
    107108        # compute square errors
     
    178179            with self.assertRaises(RuntimeError):
    179180                pvoc(win_s, hop_s)
    180         except AssertionError as e:
     181        except AssertionError:
    181182            # when compiled with fftw3, aubio supports non power of two fft sizes
    182183            self.skipTest('creating aubio.pvoc with size %d did not fail' % win_s)
    183184
    184185if __name__ == '__main__':
    185     from nose2 import main
    186186    main()
    187187
  • python/tests/test_pitch.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
    3 from unittest import TestCase
    4 from numpy.testing import assert_equal, assert_almost_equal
    5 from numpy import random, sin, arange, mean, median, isnan
    6 from math import pi
     3from unittest import TestCase, main
     4from numpy.testing import assert_equal
     5from numpy import sin, arange, mean, median, isnan, pi
    76from aubio import fvec, pitch, freqtomidi, float_type
    87
     
    2524        p = pitch('default', 2048, 512, 32000)
    2625        f = fvec (512)
    27         for i in range(10): assert_equal (p(f), 0.)
     26        for _ in range(10): assert_equal (p(f), 0.)
    2827
    2928    def test_run_on_ones(self):
     
    3231        f = fvec (512)
    3332        f[:] = 1
    34         for i in range(10): assert_equal (p(f), 0.)
     33        for _ in range(10): assert_equal (p(f), 0.)
    3534
    3635class aubio_pitch_Sinusoid(TestCase):
     
    5453
    5554    def run_pitch(self, p, input_vec, freq):
    56         count = 0
    5755        pitches, errors = [], []
    5856        input_blocks = input_vec.reshape((-1, p.hop_size))
     
    6462        assert_equal ( isnan(pitches), False )
    6563        # cut the first candidates
    66         cut = ( p.buf_size - p.hop_size ) / p.hop_size
     64        #cut = ( p.buf_size - p.hop_size ) / p.hop_size
    6765        pitches = pitches[2:]
    6866        errors = errors[2:]
     
    125123
    126124if __name__ == '__main__':
    127     from unittest import main
    128125    main()
  • python/tests/test_sink.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
    3 from numpy.testing import TestCase, assert_equal, assert_almost_equal
     3from nose2 import main
    44from nose2.tools import params
     5from numpy.testing import TestCase
    56from aubio import fvec, source, sink
    6 from numpy import array
    77from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
    88
     
    3838            sink_list.append(g)
    3939            write = 32
    40             for n in range(200):
     40            for _ in range(200):
    4141                vec = fvec(write)
    4242                g(vec, write)
     
    9595
    9696if __name__ == '__main__':
    97     from nose2 import main
    9897    main()
  • python/tests/test_slicing.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
    3 from numpy.testing import TestCase, run_module_suite
    4 from numpy.testing import assert_equal, assert_almost_equal
    5 
     3from unittest import main
     4from numpy.testing import TestCase, assert_equal
    65from aubio import slice_source_at_stamps
    7 from utils import *
     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
     
    147147
    148148if __name__ == '__main__':
    149     from unittest import main
    150149    main()
  • python/tests/test_source.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
    3 from numpy.testing import TestCase, assert_equal, assert_almost_equal
    4 from aubio import fvec, source
    5 from numpy import array
     3from nose2 import main
     4from nose2.tools import params
     5from numpy.testing import TestCase
     6from aubio import source
    67from utils import list_all_sounds
    7 from nose2.tools import params
    88
    99list_of_sounds = list_all_sounds('sounds')
     
    4848        total_frames = 0
    4949        while True:
    50             vec, read = f()
     50            _ , read = f()
    5151            total_frames += read
    5252            if read < f.hop_size: break
    53         result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}"
    54         result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri
     53        #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}"
     54        #result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri
    5555        #print (result_str.format(*result_params))
    5656        return total_frames
     
    102102        duration = f.duration
    103103        while True:
    104             vec, read = f()
     104            _, read = f()
    105105            total_frames += read
    106106            if read < f.hop_size: break
     
    112112    def test_wrong_file(self):
    113113        with self.assertRaises(RuntimeError):
    114             f = source('path_to/unexisting file.mp3')
     114            source('path_to/unexisting file.mp3')
    115115
    116116class aubio_source_test_wrong_params_with_file(aubio_source_test_case_base):
     
    118118    def test_wrong_samplerate(self):
    119119        with self.assertRaises(ValueError):
    120             f = source(self.default_test_sound, -1)
     120            source(self.default_test_sound, -1)
    121121
    122122    def test_wrong_hop_size(self):
    123123        with self.assertRaises(ValueError):
    124             f = source(self.default_test_sound, 0, -1)
     124            source(self.default_test_sound, 0, -1)
    125125
    126126    def test_wrong_channels(self):
    127127        with self.assertRaises(ValueError):
    128             f = source(self.default_test_sound, 0, 0, -1)
     128            source(self.default_test_sound, 0, 0, -1)
    129129
    130130    def test_wrong_seek(self):
     
    138138            with self.assertRaises(ValueError):
    139139                f.seek(f.duration + f.samplerate * 10)
    140         except AssertionError as e:
     140        except AssertionError:
    141141            self.skipTest('seeking after end of stream failed raising ValueError')
    142142
     
    146146        total_frames = 0
    147147        while True:
    148             vec, read = f.do_multi()
     148            _, read = f.do_multi()
    149149            total_frames += read
    150150            if read < f.hop_size: break
    151         result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"
    152         result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri
     151        #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"
     152        #result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri
    153153        #print (result_str.format(*result_params))
    154154        return total_frames
    155155
    156156if __name__ == '__main__':
    157     from nose2 import main
    158157    main()
  • python/tests/test_specdesc.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase, assert_equal, assert_almost_equal
    45from numpy import random, arange, log, zeros
    56from aubio import specdesc, cvec, float_type
    6 from math import pi
    77
    88methods = ["default",
     
    3030
    3131        for method in methods:
    32           o = specdesc(method, buf_size)
    33           assert_equal ([o.buf_size, o.method], [buf_size, method])
    34 
    35           spec = cvec(buf_size)
    36           spec.norm[0] = 1
    37           spec.norm[1] = 1./2.
    38           #print "%20s" % method, str(o(spec))
    39           o(spec)
    40           spec.norm = random.random_sample((len(spec.norm),)).astype(float_type)
    41           spec.phas = random.random_sample((len(spec.phas),)).astype(float_type)
    42           #print "%20s" % method, str(o(spec))
    43           assert (o(spec) != 0.)
    44 
    45     def test_hfc(self):
    46         o = specdesc("hfc", buf_size)
    47         spec = cvec(buf_size)
    48         # hfc of zeros is zero
    49         assert_equal (o(spec), 0.)
    50         # hfc of ones is sum of all bin numbers
    51         spec.norm[:] = 1
    52         expected = sum(range(buf_size/2 + 2))
    53         assert_equal (o(spec), expected)
    54         # changing phase doesn't change anything
    55         spec.phas[:] = 1
    56         assert_equal (o(spec), sum(range(buf_size/2 + 2)))
     32            o = specdesc(method, buf_size)
     33            assert_equal ([o.buf_size, o.method], [buf_size, method])
     34
     35            spec = cvec(buf_size)
     36            spec.norm[0] = 1
     37            spec.norm[1] = 1./2.
     38            #print "%20s" % method, str(o(spec))
     39            o(spec)
     40            spec.norm = random.random_sample((len(spec.norm),)).astype(float_type)
     41            spec.phas = random.random_sample((len(spec.phas),)).astype(float_type)
     42            #print "%20s" % method, str(o(spec))
     43            assert (o(spec) != 0.)
    5744
    5845    def test_phase(self):
     
    223210        assert_equal( 0., o(c))
    224211        a = arange(c.length * 2, 0, -2, dtype=float_type)
    225         k = arange(c.length, dtype=float_type)
    226212        c.norm = a
    227213        cumsum = .95*sum(a*a)
    228214        i = 0; rollsum = 0
    229215        while rollsum < cumsum:
    230           rollsum += a[i]*a[i]
    231           i+=1
     216            rollsum += a[i]*a[i]
     217            i+=1
    232218        rolloff = i
    233219        assert_equal (rolloff, o(c))
     
    237223    def test_negative(self):
    238224        with self.assertRaises(ValueError):
    239             o = specdesc("default", -10)
     225            specdesc("default", -10)
    240226
    241227    def test_unknown(self):
    242228        # FIXME should fail?
    243229        with self.assertRaises(ValueError):
    244             o = specdesc("unknown", 512)
     230            specdesc("unknown", 512)
    245231            self.skipTest('todo: new_specdesc should fail on wrong method')
    246232
    247233if __name__ == '__main__':
    248     from unittest import main
    249234    main()
  • python/tests/test_zero_crossing_rate.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase
    4 
    55from aubio import fvec, zero_crossing_rate
    66
     
    4444
    4545if __name__ == '__main__':
    46     from unittest import main
    4746    main()
  • python/tests/utils.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
     3import os
     4import glob
     5import numpy as np
     6from tempfile import mkstemp
     7
    38def array_from_text_file(filename, dtype = 'float'):
    4     import os.path
    5     from numpy import array
    69    filename = os.path.join(os.path.dirname(__file__), filename)
    710    with open(filename) as f:
    811        lines = f.readlines()
    9     return array([line.split() for line in lines],
     12    return np.array([line.split() for line in lines],
    1013            dtype = dtype)
    1114
    1215def list_all_sounds(rel_dir):
    13     import os.path, glob
    1416    datadir = os.path.join(os.path.dirname(__file__), rel_dir)
    1517    return glob.glob(os.path.join(datadir,'*.*'))
     
    2325
    2426def get_tmp_sink_path():
    25     from tempfile import mkstemp
    26     import os
    2727    fd, path = mkstemp()
    2828    os.close(fd)
     
    3030
    3131def del_tmp_sink_path(path):
    32     import os
    3332    os.unlink(path)
    3433
     
    4645    total_frames = 0
    4746    while True:
    48         samples, read = s()
     47        _, read = s()
    4948        total_frames += read
    5049        if read < hopsize: break
     
    5251
    5352def count_samples_in_directory(samples_dir):
    54     import os
    5553    total_frames = 0
    5654    for f in os.walk(samples_dir):
     
    6361
    6462def count_files_in_directory(samples_dir):
    65     import os
    6663    total_files = 0
    6764    for f in os.walk(samples_dir):
Note: See TracChangeset for help on using the changeset viewer.