shithub: aubio

Download patch

ref: 51b5f9cfcba37e5526886177f9f396e284ac7cda
parent: cd4689242b0192990ef21faf1301fe2d95504325
author: Paul Brossier <piem@piem.org>
date: Sun Dec 23 00:50:07 EST 2018

[tests] check resampling a source raises a warning when expected

--- 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 @@
 
 _debug = False
 
+
 class Test_aubio_source_test_case(TestCase):
 
     def setUp(self):
@@ -74,8 +76,14 @@
 
     @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)))