Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_sink.py

    r6448d31 rb4445fb  
    11#! /usr/bin/env python
    22
    3 from nose2 import main
    4 from nose2.tools import params
    53from numpy.testing import TestCase
    64from 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)
     5from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
     6from utils import parse_file_samplerate
     7from _tools import parametrize, skipTest, assert_raises, assert_warns
    118
    129list_of_sounds = list_all_sounds('sounds')
     
    2421            all_params.append((hop_size, samplerate, soundfile))
    2522
    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\'')
     23class Test_aubio_sink(object):
    3124
    3225    def test_wrong_filename(self):
    33         with self.assertRaises(RuntimeError):
     26        with assert_raises(RuntimeError):
    3427            sink('')
    3528
    3629    def test_wrong_samplerate(self):
    37         with self.assertRaises(RuntimeError):
     30        with assert_raises(RuntimeError):
    3831            sink(get_tmp_sink_path(), -1)
    3932
    4033    def test_wrong_samplerate_too_large(self):
    41         with self.assertRaises(RuntimeError):
     34        with assert_raises(RuntimeError):
    4235            sink(get_tmp_sink_path(), 1536001, 2)
    4336
    4437    def test_wrong_channels(self):
    45         with self.assertRaises(RuntimeError):
     38        with assert_raises(RuntimeError):
    4639            sink(get_tmp_sink_path(), 44100, -1)
    4740
    4841    def test_wrong_channels_too_large(self):
    49         with self.assertRaises(RuntimeError):
     42        with assert_raises(RuntimeError):
    5043            sink(get_tmp_sink_path(), 44100, 202020)
    5144
     
    6760        shutil.rmtree(tmpdir)
    6861
    69     @params(*all_params)
     62    @parametrize('hop_size, samplerate, path', all_params)
    7063    def test_read_and_write(self, hop_size, samplerate, path):
    71 
     64        orig_samplerate = parse_file_samplerate(soundfile)
    7265        try:
    73             f = source(path, samplerate, hop_size)
     66            if orig_samplerate is not None and orig_samplerate < samplerate:
     67                # upsampling should emit a warning
     68                with assert_warns(UserWarning):
     69                    f = source(soundfile, samplerate, hop_size)
     70            else:
     71                f = source(soundfile, samplerate, hop_size)
    7472        except RuntimeError as e:
    75             self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
     73            err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
     74            skipTest(err_msg.format(str(e), hop_size, samplerate))
    7675        if samplerate == 0: samplerate = f.samplerate
    7776        sink_path = get_tmp_sink_path()
     
    8584        del_tmp_sink_path(sink_path)
    8685
    87     @params(*all_params)
     86    @parametrize('hop_size, samplerate, path', all_params)
    8887    def test_read_and_write_multi(self, hop_size, samplerate, path):
     88        orig_samplerate = parse_file_samplerate(soundfile)
    8989        try:
    90             f = source(path, samplerate, hop_size)
     90            if orig_samplerate is not None and orig_samplerate < samplerate:
     91                # upsampling should emit a warning
     92                with assert_warns(UserWarning):
     93                    f = source(soundfile, samplerate, hop_size)
     94            else:
     95                f = source(soundfile, samplerate, hop_size)
    9196        except RuntimeError as e:
    92             self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
     97            err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
     98            skipTest(err_msg.format(str(e), hop_size, samplerate))
    9399        if samplerate == 0: samplerate = f.samplerate
    94100        sink_path = get_tmp_sink_path()
     
    126132
    127133if __name__ == '__main__':
    128     main()
     134    from _tools import run_module_suite
     135    run_module_suite()
Note: See TracChangeset for help on using the changeset viewer.