From 38592a6b5f751b65cbf6f8def3e0068045a54bf4 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 1 Nov 2018 22:30:57 +0100 Subject: [PATCH] [tests] use _tools in test_mfcc --- python/tests/{checks.py => _tools.py} | 0 python/tests/test_mfcc.py | 36 ++++++++++++++++------------------- 2 files changed, 16 insertions(+), 20 deletions(-) rename python/tests/{checks.py => _tools.py} (100%) diff --git a/python/tests/checks.py b/python/tests/_tools.py similarity index 100% rename from python/tests/checks.py rename to python/tests/_tools.py diff --git a/python/tests/test_mfcc.py b/python/tests/test_mfcc.py index e7f3b186..c88d2fef 100755 --- 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 @@ samplerate = 44100 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 @@ class aubio_mfcc_compute(TestCase): #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 @@ class aubio_mfcc_all_parameters(TestCase): #(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 @@ class aubio_mfcc_all_parameters(TestCase): #print coeffs if __name__ == '__main__': + from unittest import main main() -- 2.11.0