From: Paul Brossier Date: Sun, 23 Dec 2018 04:50:07 +0000 (+0100) Subject: [tests] check resampling a source raises a warning when expected X-Git-Tag: 0.4.9~13 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=51b5f9cfcba37e5526886177f9f396e284ac7cda;p=aubio.git [tests] check resampling a source raises a warning when expected --- diff --git a/python/tests/test_source.py b/python/tests/test_source.py index 97290ebf..8b35e774 100755 --- a/python/tests/test_source.py +++ b/python/tests/test_source.py @@ -3,9 +3,10 @@ from numpy.testing import TestCase, assert_equal from aubio import source -from utils import list_all_sounds +from utils import list_all_sounds, parse_file_samplerate import unittest -from _tools import parametrize, assert_raises, assert_equal, skipTest +from _tools import assert_raises, assert_equal, assert_warns +from _tools import parametrize, skipTest list_of_sounds = list_all_sounds('sounds') samplerates = [0, 44100, 8000, 32000] @@ -23,6 +24,7 @@ no_sounds_msg = "no test sounds, add some in 'python/tests/sounds/'!" _debug = False + class Test_aubio_source_test_case(TestCase): def setUp(self): @@ -74,8 +76,14 @@ class Test_aubio_source_read(object): @parametrize('hop_size, samplerate, soundfile', all_params) def test_samplerate_hopsize(self, hop_size, samplerate, soundfile): + orig_samplerate = parse_file_samplerate(soundfile) try: - f = source(soundfile, samplerate, hop_size) + if orig_samplerate is not None and orig_samplerate < samplerate: + # upsampling should emit a warning + with assert_warns(UserWarning): + f = source(soundfile, samplerate, hop_size) + else: + f = source(soundfile, samplerate, hop_size) except RuntimeError as e: err_msg = 'failed opening with hop_s={:d}, samplerate={:d} ({:s})' skipTest(err_msg.format(hop_size, samplerate, str(e)))