Changeset 2fe24df


Ignore:
Timestamp:
Apr 30, 2016, 4:01:25 PM (9 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:
5f5f843
Parents:
797435f
Message:

python/tests/test_sink.py: switch to nose2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_sink.py

    r797435f r2fe24df  
    22
    33from numpy.testing import TestCase, assert_equal, assert_almost_equal
     4from nose2.tools import params
    45from aubio import fvec, source, sink
    56from numpy import array
     
    78
    89list_of_sounds = list_all_sounds('sounds')
     10samplerates = [0, 44100, 8000, 32000]
     11hop_sizes = [512, 1024, 64]
     12
    913path = None
    1014
    1115many_files = 300 # 256 opened files is too much
    1216
     17all_params = []
     18for soundfile in list_of_sounds:
     19    for hop_size in hop_sizes:
     20        for samplerate in samplerates:
     21            all_params.append((hop_size, samplerate, soundfile))
     22
    1323class aubio_sink_test_case(TestCase):
     24
     25    def setUp(self):
     26        if not len(list_of_sounds):
     27            self.skipTest('add some sound files in \'python/tests/sounds\'')
    1428
    1529    def test_many_sinks(self):
     
    3044        shutil.rmtree(tmpdir)
    3145
    32     def test_read_and_write(self):
     46    @params(*all_params)
     47    def test_read_and_write(self, hop_size, samplerate, path):
    3348
    34         if not len(list_of_sounds):
    35             self.skipTest('add some sound files in \'python/tests/sounds\'')
     49        try:
     50            f = source(path, samplerate, hop_size)
     51        except RuntimeError as e:
     52            self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, e))
     53        if samplerate == 0: samplerate = f.samplerate
     54        sink_path = get_tmp_sink_path()
     55        g = sink(sink_path, samplerate)
     56        total_frames = 0
     57        while True:
     58            vec, read = f()
     59            g(vec, read)
     60            total_frames += read
     61            if read < f.hop_size: break
     62        del_tmp_sink_path(sink_path)
    3663
    37         for path in list_of_sounds:
    38             for samplerate, hop_size in zip([0, 44100, 8000, 32000], [512, 1024, 64, 256]):
    39                 f = source(path, samplerate, hop_size)
    40                 if samplerate == 0: samplerate = f.samplerate
    41                 sink_path = get_tmp_sink_path()
    42                 g = sink(sink_path, samplerate)
    43                 total_frames = 0
    44                 while True:
    45                     vec, read = f()
    46                     g(vec, read)
    47                     total_frames += read
    48                     if read < f.hop_size: break
    49                 del_tmp_sink_path(sink_path)
    50 
    51     def test_read_and_write_multi(self):
    52 
    53         if not len(list_of_sounds):
    54             self.skipTest('add some sound files in \'python/tests/sounds\'')
    55 
    56         for path in list_of_sounds:
    57             for samplerate, hop_size in zip([0, 44100, 8000, 32000], [512, 1024, 64, 256]):
    58                 f = source(path, samplerate, hop_size)
    59                 if samplerate == 0: samplerate = f.samplerate
    60                 sink_path = get_tmp_sink_path()
    61                 g = sink(sink_path, samplerate, channels = f.channels)
    62                 total_frames = 0
    63                 while True:
    64                     vec, read = f.do_multi()
    65                     g.do_multi(vec, read)
    66                     total_frames += read
    67                     if read < f.hop_size: break
    68                 del_tmp_sink_path(sink_path)
     64    @params(*all_params)
     65    def test_read_and_write_multi(self, hop_size, samplerate, path):
     66        try:
     67            f = source(path, samplerate, hop_size)
     68        except RuntimeError as e:
     69            self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, e))
     70        if samplerate == 0: samplerate = f.samplerate
     71        sink_path = get_tmp_sink_path()
     72        g = sink(sink_path, samplerate, channels = f.channels)
     73        total_frames = 0
     74        while True:
     75            vec, read = f.do_multi()
     76            g.do_multi(vec, read)
     77            total_frames += read
     78            if read < f.hop_size: break
     79        del_tmp_sink_path(sink_path)
    6980
    7081    def test_close_file(self):
     
    8495
    8596if __name__ == '__main__':
    86     from unittest import main
     97    from nose2 import main
    8798    main()
Note: See TracChangeset for help on using the changeset viewer.