ref: 38592a6b5f751b65cbf6f8def3e0068045a54bf4
parent: 98972b9ac8ac077ef54f081e0bb60d5803b2c970
author: Paul Brossier <piem@piem.org>
date: Thu Nov 1 18:30:57 EDT 2018
[tests] use _tools in test_mfcc
--- /dev/null
+++ b/python/tests/_tools.py
@@ -1,0 +1,50 @@
+"""
+This file imports test methods from different testing modules, in this
+order:
+
+ - if 'nose2' is found in the list of loaded module, use it
+ - otherwise, try using 'pytest'
+ - if that also fails, fallback to 'numpy.testing'
+"""
+
+import sys
+
+_has_pytest = False
+_has_nose2 = False
+
+# if nose2 has already been imported, use it
+if 'nose2' in sys.modules:
+ from nose2.tools import params, such
+ def parametrize(argnames, argvalues):
+ return params(*argvalues)
+ assert_raises = such.helper.assertRaises
+ assert_warns = such.helper.assertWarns
+ skipTest = such.helper.skipTest
+ _has_nose2 = True
+ print ('using nose2')
+
+# otherwise, check if we have pytest
+if not _has_nose2:
+ try:
+ import pytest
+ parametrize = pytest.mark.parametrize
+ _has_pytest = True
+ assert_raises = pytest.raises
+ assert_warns = pytest.warns
+ skipTest = pytest.skip
+ print ('using pytest')
+ except:
+ pass
+
+# otherwise fallback on numpy.testing
+if not _has_pytest and not _has_nose2:
+ from numpy.testing import dec, assert_raises, assert_warns
+ from numpy.testing import SkipTest
+ parametrize = dec.parametrize
+ def skipTest(msg):
+ raise SkipTest(msg)
+ print ('using numpy')
+
+# always use numpy's assert_equal
+import numpy
+assert_equal = numpy.testing.assert_equal
--- a/python/tests/checks.py
+++ /dev/null
@@ -1,50 +1,0 @@
-"""
-This file imports test methods from different testing modules, in this
-order:
-
- - if 'nose2' is found in the list of loaded module, use it
- - otherwise, try using 'pytest'
- - if that also fails, fallback to 'numpy.testing'
-"""
-
-import sys
-
-_has_pytest = False
-_has_nose2 = False
-
-# if nose2 has already been imported, use it
-if 'nose2' in sys.modules:
- from nose2.tools import params, such
- def parametrize(argnames, argvalues):
- return params(*argvalues)
- assert_raises = such.helper.assertRaises
- assert_warns = such.helper.assertWarns
- skipTest = such.helper.skipTest
- _has_nose2 = True
- print ('using nose2')
-
-# otherwise, check if we have pytest
-if not _has_nose2:
- try:
- import pytest
- parametrize = pytest.mark.parametrize
- _has_pytest = True
- assert_raises = pytest.raises
- assert_warns = pytest.warns
- skipTest = pytest.skip
- print ('using pytest')
- except:
- pass
-
-# otherwise fallback on numpy.testing
-if not _has_pytest and not _has_nose2:
- from numpy.testing import dec, assert_raises, assert_warns
- from numpy.testing import SkipTest
- parametrize = dec.parametrize
- def skipTest(msg):
- raise SkipTest(msg)
- print ('using numpy')
-
-# always use numpy's assert_equal
-import numpy
-assert_equal = numpy.testing.assert_equal
--- a/python/tests/test_mfcc.py
+++ b/python/tests/test_mfcc.py
@@ -1,7 +1,6 @@
#! /usr/bin/env python
-from nose2 import main
-from nose2.tools import params
+from ._tools import parametrize, assert_raises
from numpy import random, count_nonzero
from numpy.testing import TestCase
from aubio import mfcc, cvec, float_type
@@ -15,28 +14,21 @@
new_params = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
new_deflts = [1024, 40, 13, 44100]
-class aubio_mfcc(TestCase):
+class Test_aubio_mfcc:
- def setUp(self):
- self.o = mfcc()
+ members_args = 'name'
- def test_default_creation(self):
- pass
-
- def test_delete(self):
- del self.o
-
- @params(*new_params)
+ @parametrize(members_args, new_params)
def test_read_only_member(self, name):
- o = self.o
- with self.assertRaises((TypeError, AttributeError)):
+ o = mfcc()
+ with assert_raises((TypeError, AttributeError)):
setattr(o, name, 0)
- @params(*zip(new_params, new_deflts))
+ @parametrize('name, expected', zip(new_params, new_deflts))
def test_default_param(self, name, expected):
""" test mfcc.{:s} = {:d} """.format(name, expected)
- o = self.o
- self.assertEqual( getattr(o, name), expected)
+ o = mfcc()
+ assert getattr(o, name) == expected
class aubio_mfcc_wrong_params(TestCase):
@@ -82,9 +74,9 @@
#print coeffs
-class aubio_mfcc_all_parameters(TestCase):
+class Test_aubio_mfcc_all_parameters:
- @params(
+ run_values = [
(2048, 40, 13, 44100),
(1024, 40, 13, 44100),
(512, 40, 13, 44100),
@@ -100,7 +92,10 @@
#(1024, 30, 20, 44100),
(1024, 40, 40, 44100),
(1024, 40, 3, 44100),
- )
+ ]
+ run_args = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
+
+ @parametrize(run_args, run_values)
def test_run_with_params(self, buf_size, n_filters, n_coeffs, samplerate):
" check mfcc can run with reasonable parameters "
o = mfcc(buf_size, n_filters, n_coeffs, samplerate)
@@ -111,4 +106,5 @@
#print coeffs
if __name__ == '__main__':
+ from unittest import main
main()