Changes in / [ff28d81:62c2d00]


Ignore:
Files:
3 added
1 deleted
35 edited

Legend:

Unmodified
Added
Removed
  • .appveyor.yml

    rff28d81 r62c2d00  
    8484test_script:
    8585  - "python python\\demos\\demo_create_test_sounds.py"
    86   - "pytest --verbose"
     86  - "nose2 --verbose"
  • .circleci/config.yml

    rff28d81 r62c2d00  
    2020    pip install --user dist/aubio*.whl
    2121
    22 test-pytest: &test-pytest
     22test-nose2: &test-nose2
    2323  name: Test python wheel
    2424  command: |
    2525    make create_test_sounds
    26     PATH=/home/circleci/.local/bin:$PATH pytest -v
     26    PATH=/home/circleci/.local/bin:$PATH nose2 -v
    2727
    28 test-pytest-nosounds: &test-pytest-nosounds
     28test-nose2-nosounds: &test-nose2-nosounds
    2929  name: Test python wheel
    3030  command: |
    31     PATH=/home/circleci/.local/bin:$PATH pytest -v
     31    PATH=/home/circleci/.local/bin:$PATH nose2 -v
    3232
    3333uninstall-wheel: &uninstall-wheel
     
    4848      - run: *build-wheel
    4949      - run: *install-wheel
    50       - run: *test-pytest
     50      - run: *test-nose2
    5151      - run: *uninstall-wheel
    5252      - store_artifacts:
     
    6262      - run: *build-wheel
    6363      - run: *install-wheel
    64       - run: *test-pytest
     64      - run: *test-nose2
    6565      - run: *uninstall-wheel
    6666      - store_artifacts:
     
    7676      - run: *build-wheel
    7777      - run: *install-wheel
    78       - run: *test-pytest
     78      - run: *test-nose2
    7979      - run: *uninstall-wheel
    8080      - store_artifacts:
     
    8989      - run: *build-wheel
    9090      - run: *install-wheel
    91       - run: *test-pytest-nosounds
     91      - run: *test-nose2-nosounds
    9292      - run: *uninstall-wheel
    9393      - store_artifacts:
  • MANIFEST.in

    rff28d81 r62c2d00  
    66include Makefile wscript */wscript_build
    77include aubio.pc.in
     8include nose2.cfg
    89include requirements.txt
    910include src/*.c src/*.h
     
    1415recursive-include python *.py
    1516include python/README.md
     17include python/tests/run_all_tests
    1618include python/tests/eval_pitch
    1719include python/tests/*.expected
  • Makefile

    rff28d81 r62c2d00  
    3636MANDIR?=$(DATAROOTDIR)/man
    3737
    38 # default python test command
    39 PYTEST?=pytest --verbose
     38# default nose2 command
     39NOSE2?=nose2 -N 4 --verbose
    4040
    4141SOX=sox
     
    139139test_python: local_dylib
    140140        # run test with installed package
    141         $(PYTEST)
     141        # ./python/tests/run_all_tests --verbose
     142        # run with nose2, multiple processes
     143        $(NOSE2)
    142144
    143145clean_python:
     
    246248        lcov --capture --no-external --directory . --output-file build/coverage_lib.info
    247249        pip install -v -e .
    248         coverage run `which pytest`
     250        coverage run `which nose2`
    249251        lcov --capture --no-external --directory . --output-file build/coverage_python.info
    250252        lcov -a build/coverage_python.info -a build/coverage_lib.info -o build/coverage.info
  • doc/python_module.rst

    rff28d81 r62c2d00  
    6868------------
    6969
    70 A number of python tests are provided. To run them, use [pytest] from the
    71 aubio source tree:
     70A number of `python tests`_ are provided. To run them, use
     71``python/tests/run_all_tests``.
    7272
    73     $ cd aubio
    74     $ pytest
    75 
    76 Each test script can also be called individually. For instance:
    77 
    78     $ ./python/tests/test_note2midi.py -v
    79 
    80 [pytest]: https://pytest.org
     73.. _demo_filter.py: https://github.com/aubio/aubio/blob/master/python/demos/demo_filter.py
     74.. _python tests: https://github.com/aubio/aubio/blob/master/python/tests
  • python/README.md

    rff28d81 r62c2d00  
    3636-------------------------
    3737
    38 Python tests are in `python/tests` and use [pytest].
     38Python tests are in `python/tests` and use the [nose2 python package][nose2].
    3939
    40 To run the all the python tests:
     40To run the all the python tests, use the script:
    4141
    42     $ cd aubio
    43     $ pytest
     42    $ ./python/tests/run_all_tests
    4443
    4544Each test script can also be called one at a time. For instance:
    4645
    47     $ pytest -v python/tests/test_note2midi.py
     46    $ ./python/tests/test_note2midi.py -v
    4847
    49 [pytest]: https://pytest.org
     48[nose2]: https://github.com/nose-devs/nose2
    5049
    5150Install in a virtualenv
  • python/tests/test_aubio.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase
    45
     
    1516
    1617if __name__ == '__main__':
    17     from unittest import main
    1818    main()
     19
  • python/tests/test_aubio_cmd.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
     3import aubio.cmd
     4from nose2 import main
    35from numpy.testing import TestCase
    4 import aubio.cmd
    56
    67class aubio_cmd(TestCase):
     
    3132
    3233if __name__ == '__main__':
    33     from unittest import main
    3434    main()
  • python/tests/test_aubio_cut.py

    rff28d81 r62c2d00  
    22
    33import aubio.cut
     4from nose2 import main
    45from numpy.testing import TestCase
    56
     
    1314
    1415if __name__ == '__main__':
    15     from unittest import main
    1616    main()
  • python/tests/test_cvec.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34import numpy as np
    45from numpy.testing import TestCase, assert_equal
     
    141142
    142143if __name__ == '__main__':
    143     from unittest import main
    144144    main()
  • python/tests/test_dct.py

    rff28d81 r62c2d00  
    6767        except AssertionError:
    6868            self.skipTest('creating aubio.dct with size %d did not fail' % size)
    69 
    70 if __name__ == '__main__':
    71     from unittest import main
    72     main()
  • python/tests/test_fft.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase
    45from numpy.testing import assert_equal, assert_almost_equal
     
    212213
    213214if __name__ == '__main__':
    214     from unittest import main
    215215    main()
  • python/tests/test_filter.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase, assert_equal, assert_almost_equal
    45from aubio import fvec, digital_filter
    5 from utils import array_from_text_file
     6from .utils import array_from_text_file
    67
    78class aubio_filter_test_case(TestCase):
     
    8485
    8586if __name__ == '__main__':
    86     from unittest import main
    8787    main()
  • python/tests/test_filterbank.py

    rff28d81 r62c2d00  
    55
    66from aubio import cvec, filterbank, float_type
    7 from utils import array_from_text_file
     7from .utils import array_from_text_file
    88
    99class aubio_filterbank_test_case(TestCase):
     
    8888
    8989if __name__ == '__main__':
    90     from unittest import main
    91     main()
     90    import nose2
     91    nose2.main()
  • python/tests/test_filterbank_mel.py

    rff28d81 r62c2d00  
    33import numpy as np
    44from numpy.testing import TestCase, assert_equal, assert_almost_equal
    5 from _tools import assert_warns
    65
    76from aubio import fvec, cvec, filterbank, float_type
     7
     8import warnings
     9warnings.filterwarnings('ignore', category=UserWarning, append=True)
    810
    911class aubio_filterbank_mel_test_case(TestCase):
     
    7476        freq_list = [0, samplerate//4, samplerate // 2 + 1]
    7577        f = filterbank(len(freq_list)-2, 1024)
    76         with assert_warns(UserWarning):
    77             f.set_triangle_bands(fvec(freq_list), samplerate)
     78        # TODO add assert_warns
     79        f.set_triangle_bands(fvec(freq_list), samplerate)
    7880
    7981    def test_triangle_freqs_with_not_enough_filters(self):
     
    8284        freq_list = [0, 100, 1000, 4000, 8000, 10000]
    8385        f = filterbank(len(freq_list)-3, 1024)
    84         with assert_warns(UserWarning):
    85             f.set_triangle_bands(fvec(freq_list), samplerate)
     86        # TODO add assert_warns
     87        f.set_triangle_bands(fvec(freq_list), samplerate)
    8688
    8789    def test_triangle_freqs_with_too_many_filters(self):
     
    9092        freq_list = [0, 100, 1000, 4000, 8000, 10000]
    9193        f = filterbank(len(freq_list)-1, 1024)
    92         with assert_warns(UserWarning):
    93             f.set_triangle_bands(fvec(freq_list), samplerate)
     94        # TODO add assert_warns
     95        f.set_triangle_bands(fvec(freq_list), samplerate)
    9496
    9597    def test_triangle_freqs_with_double_value(self):
     
    98100        freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
    99101        f = filterbank(len(freq_list)-2, 1024)
    100         with assert_warns(UserWarning):
    101             f.set_triangle_bands(fvec(freq_list), samplerate)
     102        # TODO add assert_warns
     103        f.set_triangle_bands(fvec(freq_list), samplerate)
    102104
    103105    def test_triangle_freqs_with_triple(self):
     
    106108        freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
    107109        f = filterbank(len(freq_list)-2, 1024)
    108         with assert_warns(UserWarning):
    109             f.set_triangle_bands(fvec(freq_list), samplerate)
    110 
     110        # TODO add assert_warns
     111        f.set_triangle_bands(fvec(freq_list), samplerate)
    111112
    112113    def test_triangle_freqs_without_norm(self):
     
    168169
    169170if __name__ == '__main__':
    170     from unittest import main
    171     main()
     171    import nose2
     172    nose2.main()
  • python/tests/test_fvec.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34import numpy as np
    45from numpy.testing import TestCase, assert_equal, assert_almost_equal
     
    148149
    149150if __name__ == '__main__':
    150     from unittest import main
    151151    main()
  • python/tests/test_fvec_shift.py

    rff28d81 r62c2d00  
    3131        self.run_shift_ishift(7)
    3232
     33from unittest import main
    3334if __name__ == '__main__':
    34     from unittest import main
    3535    main()
  • python/tests/test_hztomel.py

    rff28d81 r62c2d00  
    44from numpy.testing import TestCase
    55from numpy.testing import assert_equal, assert_almost_equal
    6 from _tools import assert_warns
    76import numpy as np
    87import aubio
     
    3938
    4039    def test_meltohz_negative(self):
    41         with assert_warns(UserWarning):
    42             assert_equal(meltohz(-1), 0)
     40        # TODO add assert_warns
     41        assert_equal(meltohz(-1), 0)
    4342
    4443    def test_hztomel_negative(self):
    45         with assert_warns(UserWarning):
    46             assert_equal(hztomel(-1), 0)
     44        # TODO add assert_warns
     45        assert_equal(hztomel(-1), 0)
    4746
    4847
     
    5958
    6059    def test_meltohz_negative(self):
    61         with assert_warns(UserWarning):
    62             assert_equal(meltohz(-1, htk=True), 0)
     60        # TODO add assert_warns
     61        assert_equal(meltohz(-1, htk=True), 0)
    6362        assert_almost_equal(meltohz(2000, htk=True), 3428.7, decimal=1)
    6463        assert_almost_equal(meltohz(1000, htk=True), 1000., decimal=1)
    6564
    6665    def test_hztomel_negative(self):
    67         with assert_warns(UserWarning):
    68             assert_equal(meltohz(-1, htk=True), 0)
    69         with assert_warns(UserWarning):
    70             assert_equal(hztomel(-1, htk=True), 0)
     66        # TODO add assert_warns
     67        assert_equal(hztomel(-1, htk=True), 0)
    7168        assert_almost_equal(hztomel(1000, htk=True), 1000., decimal=1)
    7269
  • python/tests/test_mathutils.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase, assert_equal
    45from numpy import array, arange, isnan, isinf
     
    101102
    102103if __name__ == '__main__':
    103     from unittest import main
    104104    main()
  • python/tests/test_mfcc.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
    3 from _tools import parametrize, assert_raises
     3from nose2 import main
     4from nose2.tools import params
    45from numpy import random, count_nonzero
    56from numpy.testing import TestCase
     
    1516new_deflts = [1024, 40, 13, 44100]
    1617
    17 class Test_aubio_mfcc(object):
     18class aubio_mfcc(TestCase):
    1819
    19     members_args = 'name'
     20    def setUp(self):
     21        self.o = mfcc()
    2022
    21     @parametrize(members_args, new_params)
     23    def test_default_creation(self):
     24        pass
     25
     26    def test_delete(self):
     27        del self.o
     28
     29    @params(*new_params)
    2230    def test_read_only_member(self, name):
    23         o = mfcc()
    24         with assert_raises((TypeError, AttributeError)):
     31        o = self.o
     32        with self.assertRaises((TypeError, AttributeError)):
    2533            setattr(o, name, 0)
    2634
    27     @parametrize('name, expected', zip(new_params, new_deflts))
     35    @params(*zip(new_params, new_deflts))
    2836    def test_default_param(self, name, expected):
    2937        """ test mfcc.{:s} = {:d} """.format(name, expected)
    30         o = mfcc()
    31         assert getattr(o, name) == expected
     38        o = self.o
     39        self.assertEqual( getattr(o, name), expected)
    3240
    3341class aubio_mfcc_wrong_params(TestCase):
     
    7583
    7684
    77 class Test_aubio_mfcc_all_parameters(object):
     85class aubio_mfcc_all_parameters(TestCase):
    7886
    79     run_values = [
     87    @params(
    8088            (2048, 40, 13, 44100),
    8189            (1024, 40, 13, 44100),
     
    93101            (1024, 40, 40, 44100),
    94102            (1024, 40, 3, 44100),
    95             ]
    96     run_args = ['buf_size', 'n_filters', 'n_coeffs', 'samplerate']
    97 
    98     @parametrize(run_args, run_values)
     103            )
    99104    def test_run_with_params(self, buf_size, n_filters, n_coeffs, samplerate):
    100105        " check mfcc can run with reasonable parameters "
     
    142147
    143148if __name__ == '__main__':
    144     from _tools import run_module_suite
    145     run_module_suite()
     149    main()
  • python/tests/test_midi2note.py

    rff28d81 r62c2d00  
    33
    44from aubio import midi2note
    5 from _tools import parametrize, assert_raises
     5from nose2.tools import params
     6import unittest
    67
    78list_of_known_midis = (
     
    1516        )
    1617
    17 class Test_midi2note_good_values(object):
     18class midi2note_good_values(unittest.TestCase):
    1819
    19     @parametrize('midi, note', list_of_known_midis)
     20    @params(*list_of_known_midis)
    2021    def test_midi2note_known_values(self, midi, note):
    2122        " known values are correctly converted "
    22         assert midi2note(midi) == (note)
     23        self.assertEqual ( midi2note(midi), note )
    2324
    24 class Test_midi2note_wrong_values(object):
     25class midi2note_wrong_values(unittest.TestCase):
    2526
    2627    def test_midi2note_negative_value(self):
    2728        " fails when passed a negative value "
    28         assert_raises(ValueError, midi2note, -2)
     29        self.assertRaises(ValueError, midi2note, -2)
    2930
    3031    def test_midi2note_large(self):
    3132        " fails when passed a value greater than 127 "
    32         assert_raises(ValueError, midi2note, 128)
     33        self.assertRaises(ValueError, midi2note, 128)
    3334
    3435    def test_midi2note_floating_value(self):
    3536        " fails when passed a floating point "
    36         assert_raises(TypeError, midi2note, 69.2)
     37        self.assertRaises(TypeError, midi2note, 69.2)
    3738
    3839    def test_midi2note_character_value(self):
    3940        " fails when passed a value that can not be transformed to integer "
    40         assert_raises(TypeError, midi2note, "a")
     41        self.assertRaises(TypeError, midi2note, "a")
    4142
    4243if __name__ == '__main__':
    43     from _tools import run_module_suite
    44     run_module_suite()
     44    import nose2
     45    nose2.main()
  • python/tests/test_musicutils.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34import numpy as np
    45from numpy.testing import TestCase
    5 from numpy.testing import assert_equal, assert_almost_equal
     6from numpy.testing.utils import assert_equal, assert_almost_equal
    67from aubio import window, level_lin, db_spl, silence_detection, level_detection
    78from aubio import fvec, float_type
     
    8586
    8687if __name__ == '__main__':
    87     from unittest import main
    8888    main()
  • python/tests/test_note2midi.py

    rff28d81 r62c2d00  
    55
    66from aubio import note2midi, freq2note, note2freq, float_type
    7 from numpy.testing import TestCase
    8 from _tools import parametrize, assert_raises, skipTest
     7from nose2.tools import params
     8import unittest
    99
    1010list_of_known_notes = (
     
    4545        )
    4646
    47 class Test_note2midi_good_values(object):
     47class note2midi_good_values(unittest.TestCase):
    4848
    49     @parametrize('note, midi', list_of_known_notes)
     49    @params(*list_of_known_notes)
    5050    def test_note2midi_known_values(self, note, midi):
    5151        " known values are correctly converted "
    52         assert note2midi(note) == midi
     52        self.assertEqual ( note2midi(note), midi )
    5353
    54     @parametrize('note, midi', list_of_known_notes_with_unicode_issues)
     54    @params(*list_of_known_notes_with_unicode_issues)
    5555    def test_note2midi_known_values_with_unicode_issues(self, note, midi):
    56         " difficult values are correctly converted unless expected failure "
     56        " known values are correctly converted, unless decoding is expected to fail"
    5757        try:
    58             assert note2midi(note) == midi
     58            self.assertEqual ( note2midi(note), midi )
    5959        except UnicodeEncodeError as e:
    60             # platforms with decoding failures include:
    61             # - osx: python <= 2.7.10
    62             # - win: python <= 2.7.12
    6360            import sys
    64             strmsg = "len(u'\\U0001D12A') != 1, expected decoding failure"
    65             strmsg += " | upgrade to Python 3 to fix"
    66             strmsg += " | {:s} | {:s} {:s}"
     61            strfmt = "len(u'\\U0001D12A') != 1, excpected decoding failure | {:s} | {:s} {:s}"
     62            strres = strfmt.format(e, sys.platform, sys.version)
     63            # happens with: darwin 2.7.10, windows 2.7.12
    6764            if len('\U0001D12A') != 1 and sys.version[0] == '2':
    68                 skipTest(strmsg.format(repr(e), sys.platform, sys.version))
     65                self.skipTest(strres + " | upgrade to Python 3 to fix")
    6966            else:
    7067                raise
    7168
    72 class note2midi_wrong_values(TestCase):
     69class note2midi_wrong_values(unittest.TestCase):
    7370
    7471    def test_note2midi_missing_octave(self):
     
    108105        self.assertRaises(ValueError, note2midi, 'CB+-3')
    109106
    110 class Test_note2midi_unknown_values(object):
    111 
    112     @parametrize('note', list_of_unknown_notes)
     107    @params(*list_of_unknown_notes)
    113108    def test_note2midi_unknown_values(self, note):
    114109        " unknown values throw out an error "
    115         assert_raises(ValueError, note2midi, note)
     110        self.assertRaises(ValueError, note2midi, note)
    116111
    117 class freq2note_simple_test(TestCase):
     112class freq2note_simple_test(unittest.TestCase):
    118113
    119114    def test_freq2note_above(self):
     
    125120        self.assertEqual("A4", freq2note(439))
    126121
    127 class note2freq_simple_test(TestCase):
     122class note2freq_simple_test(unittest.TestCase):
    128123
    129124    def test_note2freq(self):
     
    139134
    140135if __name__ == '__main__':
    141     from _tools import run_module_suite
    142     run_module_suite()
     136    import nose2
     137    nose2.main()
  • python/tests/test_notes.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase, assert_equal, assert_almost_equal
    4 from aubio import notes, source
    5 import numpy as np
    6 from utils import list_all_sounds
    7 
    8 list_of_sounds = list_all_sounds('sounds')
     5from aubio import notes
    96
    107AUBIO_DEFAULT_NOTES_SILENCE = -70.
     
    5653            self.o.set_release_drop(val)
    5754
     55from .utils import list_all_sounds
     56list_of_sounds = list_all_sounds('sounds')
     57
    5858class aubio_notes_sinewave(TestCase):
    5959
    6060    def analyze_file(self, filepath, samplerate=0):
     61        from aubio import source
     62        import numpy as np
    6163        win_s = 512 # fft size
    6264        hop_s = 256 # hop size
     
    9193
    9294if __name__ == '__main__':
    93     from unittest import main
    9495    main()
  • python/tests/test_onset.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase, assert_equal, assert_almost_equal
    45from aubio import onset
     
    8485
    8586if __name__ == '__main__':
    86     from unittest import main
    8787    main()
  • python/tests/test_phasevoc.py

    rff28d81 r62c2d00  
    22
    33from numpy.testing import TestCase, assert_equal, assert_array_less
    4 from _tools import parametrize
    54from aubio import fvec, cvec, pvoc, float_type
     5from nose2 import main
     6from nose2.tools import params
    67import numpy as np
    78
     
    1819    return np.random.rand(hop_s).astype(float_type) * 2. - 1.
    1920
    20 class Test_aubio_pvoc_test_case(object):
     21class aubio_pvoc_test_case(TestCase):
    2122    """ pvoc object test case """
    2223
     
    5657            assert_equal ( r, 0.)
    5758
    58     resynth_noise_args = "hop_s, ratio"
    59     resynth_noise_values = [
     59    @params(
    6060            ( 256, 8),
    6161            ( 256, 4),
     
    7979            (8192, 4),
    8080            (8192, 2),
    81             ]
    82 
    83     @parametrize(resynth_noise_args, resynth_noise_values)
     81            )
    8482    def test_resynth_steps_noise(self, hop_s, ratio):
    8583        """ check the resynthesis of a random signal is correct """
     
    8785        self.reconstruction(sigin, hop_s, ratio)
    8886
    89     resynth_sine_args = "samplerate, hop_s, ratio, freq"
    90     resynth_sine_values = [
     87    @params(
    9188            (44100,  256, 8,   441),
    9289            (44100,  256, 4,  1203),
     
    103100            (96000, 1024, 8, 47000),
    104101            (96000, 1024, 8,    20),
    105             ]
    106 
    107     @parametrize(resynth_sine_args, resynth_sine_values)
     102            )
    108103    def test_resynth_steps_sine(self, samplerate, hop_s, ratio, freq):
    109104        """ check the resynthesis of a sine is correct """
     
    196191
    197192if __name__ == '__main__':
    198     from unittest import main
    199193    main()
     194
  • python/tests/test_pitch.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
    3 from numpy.testing import TestCase, assert_equal
     3from unittest import TestCase, main
     4from numpy.testing import assert_equal
    45from numpy import sin, arange, mean, median, isnan, pi
    56from aubio import fvec, pitch, freqtomidi, float_type
     
    116117for algo in pitch_algorithms:
    117118    for mode in signal_modes:
    118         _test_method = create_test (algo, mode)
    119         _test_method.__name__ = 'test_pitch_%s_%d_%d_%dHz_sin_%.0f' % ( algo,
     119        test_method = create_test (algo, mode)
     120        test_method.__name__ = 'test_pitch_%s_%d_%d_%dHz_sin_%.0f' % ( algo,
    120121                mode[0], mode[1], mode[2], mode[3] )
    121         setattr (aubio_pitch_Sinusoid, _test_method.__name__, _test_method)
     122        setattr (aubio_pitch_Sinusoid, test_method.__name__, test_method)
    122123
    123124if __name__ == '__main__':
    124     from unittest import main
    125125    main()
  • python/tests/test_sink.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
     3from nose2 import main
     4from nose2.tools import params
    35from numpy.testing import TestCase
    46from aubio import fvec, source, sink
    5 from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
    6 from _tools import parametrize, skipTest, assert_raises
     7from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
     8
     9import warnings
     10warnings.filterwarnings('ignore', category=UserWarning, append=True)
    711
    812list_of_sounds = list_all_sounds('sounds')
     
    2024            all_params.append((hop_size, samplerate, soundfile))
    2125
    22 class Test_aubio_sink(object):
     26class 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\'')
    2331
    2432    def test_wrong_filename(self):
    25         with assert_raises(RuntimeError):
     33        with self.assertRaises(RuntimeError):
    2634            sink('')
    2735
    2836    def test_wrong_samplerate(self):
    29         with assert_raises(RuntimeError):
     37        with self.assertRaises(RuntimeError):
    3038            sink(get_tmp_sink_path(), -1)
    3139
    3240    def test_wrong_samplerate_too_large(self):
    33         with assert_raises(RuntimeError):
     41        with self.assertRaises(RuntimeError):
    3442            sink(get_tmp_sink_path(), 1536001, 2)
    3543
    3644    def test_wrong_channels(self):
    37         with assert_raises(RuntimeError):
     45        with self.assertRaises(RuntimeError):
    3846            sink(get_tmp_sink_path(), 44100, -1)
    3947
    4048    def test_wrong_channels_too_large(self):
    41         with assert_raises(RuntimeError):
     49        with self.assertRaises(RuntimeError):
    4250            sink(get_tmp_sink_path(), 44100, 202020)
    4351
     
    5967        shutil.rmtree(tmpdir)
    6068
    61     @parametrize('hop_size, samplerate, path', all_params)
     69    @params(*all_params)
    6270    def test_read_and_write(self, hop_size, samplerate, path):
     71
    6372        try:
    6473            f = source(path, samplerate, hop_size)
    6574        except RuntimeError as e:
    66             err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
    67             skipTest(err_msg.format(str(e), hop_size, samplerate))
     75            self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
    6876        if samplerate == 0: samplerate = f.samplerate
    6977        sink_path = get_tmp_sink_path()
     
    7785        del_tmp_sink_path(sink_path)
    7886
    79     @parametrize('hop_size, samplerate, path', all_params)
     87    @params(*all_params)
    8088    def test_read_and_write_multi(self, hop_size, samplerate, path):
    8189        try:
    8290            f = source(path, samplerate, hop_size)
    8391        except RuntimeError as e:
    84             err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
    85             skipTest(err_msg.format(str(e), hop_size, samplerate))
     92            self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
    8693        if samplerate == 0: samplerate = f.samplerate
    8794        sink_path = get_tmp_sink_path()
     
    119126
    120127if __name__ == '__main__':
    121     from _tools import run_module_suite
    122     run_module_suite()
     128    main()
  • python/tests/test_slicing.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase, assert_equal
    45from aubio import slice_source_at_stamps
    5 from utils import count_files_in_directory, get_default_test_sound
    6 from utils import count_samples_in_directory, count_samples_in_file
     6from .utils import count_files_in_directory, get_default_test_sound
     7from .utils import count_samples_in_directory, count_samples_in_file
    78
    89import tempfile
     
    167168
    168169if __name__ == '__main__':
    169     from unittest import main
    170170    main()
  • python/tests/test_source.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
    3 
     3from nose2 import main
     4from nose2.tools import params
    45from numpy.testing import TestCase, assert_equal
    56from aubio import source
    6 from utils import list_all_sounds
    7 import unittest
    8 from _tools import parametrize, assert_raises, assert_equal, skipTest
     7from .utils import list_all_sounds
     8
     9import warnings
     10warnings.filterwarnings('ignore', category=UserWarning, append=True)
    911
    1012list_of_sounds = list_all_sounds('sounds')
     
    1214hop_sizes = [512, 1024, 64]
    1315
    14 default_test_sound = len(list_of_sounds) and list_of_sounds[0] or None
     16path = None
    1517
    1618all_params = []
     
    2022            all_params.append((hop_size, samplerate, soundfile))
    2123
    22 no_sounds_msg = "no test sounds, add some in 'python/tests/sounds/'!"
    2324
    24 _debug = False
     25class aubio_source_test_case_base(TestCase):
    2526
    26 class Test_aubio_source_test_case(object):
     27    def setUp(self):
     28        if not len(list_of_sounds):
     29            self.skipTest('add some sound files in \'python/tests/sounds\'')
     30        self.default_test_sound = list_of_sounds[0]
    2731
    28     @parametrize('filename', list_of_sounds)
     32class aubio_source_test_case(aubio_source_test_case_base):
     33
     34    @params(*list_of_sounds)
    2935    def test_close_file(self, filename):
    3036        samplerate = 0 # use native samplerate
     
    3339        f.close()
    3440
    35     @parametrize('filename', list_of_sounds)
     41    @params(*list_of_sounds)
    3642    def test_close_file_twice(self, filename):
    3743        samplerate = 0 # use native samplerate
     
    4147        f.close()
    4248
    43 class Test_aubio_source_read(object):
     49class aubio_source_read_test_case(aubio_source_test_case_base):
    4450
    4551    def read_from_source(self, f):
     
    5157                assert_equal(samples[read:], 0)
    5258                break
    53         if _debug:
    54             result_str = "read {:.2f}s ({:d} frames"
    55             result_str += " in {:d} blocks at {:d}Hz) from {:s}"
    56             result_params = total_frames / float(f.samplerate), total_frames, \
    57                     total_frames//f.hop_size, f.samplerate, f.uri
    58             print (result_str.format(*result_params))
     59        #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}"
     60        #result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri
     61        #print (result_str.format(*result_params))
    5962        return total_frames
    6063
    61     @parametrize('hop_size, samplerate, soundfile', all_params)
     64    @params(*all_params)
    6265    def test_samplerate_hopsize(self, hop_size, samplerate, soundfile):
    6366        try:
    6467            f = source(soundfile, samplerate, hop_size)
    6568        except RuntimeError as e:
    66             err_msg = 'failed opening with hop_s={:d}, samplerate={:d} ({:s})'
    67             skipTest(err_msg.format(hop_size, samplerate, str(e)))
     69            self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
    6870        assert f.samplerate != 0
    6971        read_frames = self.read_from_source(f)
    7072        if 'f_' in soundfile and samplerate == 0:
    7173            import re
    72             f = re.compile(r'.*_\([0:9]*f\)_.*')
     74            f = re.compile('.*_\([0:9]*f\)_.*')
    7375            match_f = re.findall('([0-9]*)f_', soundfile)
    7476            if len(match_f) == 1:
    7577                expected_frames = int(match_f[0])
    76                 assert_equal(expected_frames, read_frames)
     78                self.assertEqual(expected_frames, read_frames)
    7779
    78     @parametrize('p', list_of_sounds)
     80    @params(*list_of_sounds)
    7981    def test_samplerate_none(self, p):
    8082        f = source(p)
     
    8284        self.read_from_source(f)
    8385
    84     @parametrize('p', list_of_sounds)
     86    @params(*list_of_sounds)
    8587    def test_samplerate_0(self, p):
    8688        f = source(p, 0)
     
    8890        self.read_from_source(f)
    8991
    90     @parametrize('p', list_of_sounds)
     92    @params(*list_of_sounds)
    9193    def test_zero_hop_size(self, p):
    9294        f = source(p, 0, 0)
     
    9597        self.read_from_source(f)
    9698
    97     @parametrize('p', list_of_sounds)
     99    @params(*list_of_sounds)
    98100    def test_seek_to_half(self, p):
    99101        from random import randint
     
    107109        assert a == b + c
    108110
    109     @parametrize('p', list_of_sounds)
     111    @params(*list_of_sounds)
    110112    def test_duration(self, p):
    111113        total_frames = 0
     
    116118            total_frames += read
    117119            if read < f.hop_size: break
    118         assert_equal (duration, total_frames)
     120        self.assertEqual(duration, total_frames)
    119121
    120122
    121 class Test_aubio_source_wrong_params(object):
     123class aubio_source_test_wrong_params(TestCase):
    122124
    123125    def test_wrong_file(self):
    124         with assert_raises(RuntimeError):
     126        with self.assertRaises(RuntimeError):
    125127            source('path_to/unexisting file.mp3')
    126128
    127 @unittest.skipIf(default_test_sound is None, no_sounds_msg)
    128 class Test_aubio_source_wrong_params_with_file(TestCase):
     129class aubio_source_test_wrong_params_with_file(aubio_source_test_case_base):
    129130
    130131    def test_wrong_samplerate(self):
    131         with assert_raises(ValueError):
    132             source(default_test_sound, -1)
     132        with self.assertRaises(ValueError):
     133            source(self.default_test_sound, -1)
    133134
    134135    def test_wrong_hop_size(self):
    135         with assert_raises(ValueError):
    136             source(default_test_sound, 0, -1)
     136        with self.assertRaises(ValueError):
     137            source(self.default_test_sound, 0, -1)
    137138
    138139    def test_wrong_channels(self):
    139         with assert_raises(ValueError):
    140             source(default_test_sound, 0, 0, -1)
     140        with self.assertRaises(ValueError):
     141            source(self.default_test_sound, 0, 0, -1)
    141142
    142143    def test_wrong_seek(self):
    143         f = source(default_test_sound)
    144         with assert_raises(ValueError):
     144        f = source(self.default_test_sound)
     145        with self.assertRaises(ValueError):
    145146            f.seek(-1)
    146147
    147148    def test_wrong_seek_too_large(self):
    148         f = source(default_test_sound)
     149        f = source(self.default_test_sound)
    149150        try:
    150             with assert_raises(ValueError):
     151            with self.assertRaises(ValueError):
    151152                f.seek(f.duration + f.samplerate * 10)
    152         except:
    153             skipTest('seeking after end of stream failed raising ValueError')
     153        except AssertionError:
     154            self.skipTest('seeking after end of stream failed raising ValueError')
    154155
    155 class Test_aubio_source_readmulti(Test_aubio_source_read):
     156class aubio_source_readmulti_test_case(aubio_source_read_test_case):
    156157
    157158    def read_from_source(self, f):
     
    163164                assert_equal(samples[:,read:], 0)
    164165                break
    165         if _debug:
    166             result_str = "read {:.2f}s ({:d} frames in {:d} channels"
    167             result_str += " and {:d} blocks at {:d}Hz) from {:s}"
    168             result_params = total_frames / float(f.samplerate), total_frames, \
    169                     f.channels, int(total_frames/f.hop_size), \
    170                     f.samplerate, f.uri
    171             print (result_str.format(*result_params))
     166        #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"
     167        #result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri
     168        #print (result_str.format(*result_params))
    172169        return total_frames
    173170
    174 class Test_aubio_source_with(object):
     171class aubio_source_with(aubio_source_test_case_base):
    175172
    176     @parametrize('filename', list_of_sounds)
     173    #@params(*list_of_sounds)
     174    @params(*list_of_sounds)
    177175    def test_read_from_mono(self, filename):
    178176        total_frames = 0
     
    188186
    189187if __name__ == '__main__':
    190     from _tools import run_module_suite
    191     run_module_suite()
     188    main()
  • python/tests/test_specdesc.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase, assert_equal, assert_almost_equal
    45from numpy import random, arange, log, zeros
     
    229230
    230231if __name__ == '__main__':
    231     from unittest import main
    232232    main()
  • python/tests/test_zero_crossing_rate.py

    rff28d81 r62c2d00  
    11#! /usr/bin/env python
    22
     3from unittest import main
    34from numpy.testing import TestCase
    45from aubio import fvec, zero_crossing_rate
     
    4344
    4445if __name__ == '__main__':
    45     from unittest import main
    4646    main()
  • python/tests/utils.py

    rff28d81 r62c2d00  
    99
    1010def array_from_text_file(filename, dtype = 'float'):
    11     realpathname = os.path.join(os.path.dirname(__file__), filename)
    12     return np.loadtxt(realpathname, dtype = dtype)
     11    filename = os.path.join(os.path.dirname(__file__), filename)
     12    with open(filename) as f:
     13        lines = f.readlines()
     14    return np.array([line.split() for line in lines],
     15            dtype = dtype)
    1316
    1417def list_all_sounds(rel_dir):
     
    3639        os.unlink(path)
    3740    except WindowsError as e:
    38         # removing the temporary directory sometimes fails on windows
    39         import warnings
    40         errmsg = "failed deleting temporary file {:s} ({:s})"
    41         warnings.warn(UserWarning(errmsg.format(path, repr(e))))
     41        print("deleting {:s} failed ({:s}), reopening".format(path, repr(e)))
     42        with open(path, 'wb') as f:
     43            f.close()
     44        try:
     45            os.unlink(path)
     46        except WindowsError as f:
     47            print("deleting {:s} failed ({:s}), aborting".format(path, repr(e)))
    4248
    4349def array_from_yaml_file(filename):
  • requirements.txt

    rff28d81 r62c2d00  
    11numpy
    2 pytest
     2nose2
  • setup.py

    rff28d81 r62c2d00  
    9090        ],
    9191    },
     92    test_suite = 'nose2.collector.collector',
     93    extras_require = {
     94        'tests': ['numpy'],
     95        },
    9296    )
Note: See TracChangeset for help on using the changeset viewer.