Changeset 41b985f for python/tests


Ignore:
Timestamp:
Mar 12, 2017, 11:26:24 AM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
sampler
Children:
bde49c4a
Parents:
71f2e5f (diff), 67b6618 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge 'origin/master' into sampler

Conflicts:

.travis.yml
Makefile
examples/aubionotes.c
examples/parse_args.h
python/demos/demo_timestretch_online.py
python/lib/moresetuptools.py
python/tests/test_source.py
setup.py
src/io/source.c

Location:
python/tests
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • python/tests/eval_pitch

    r71f2e5f r41b985f  
    2525import os.path
    2626import numpy
    27 from utils import array_from_text_file, array_from_yaml_file
     27from .utils import array_from_text_file, array_from_yaml_file
    2828from aubio import source, pitch, freqtomidi
    2929
  • python/tests/test_aubio.py

    r71f2e5f r41b985f  
    1010        import aubio
    1111
     12    def test_version(self):
     13        """ test aubio.version """
     14        import aubio
     15        self.assertEqual('0', aubio.version[0])
     16
    1217if __name__ == '__main__':
    1318    main()
  • python/tests/test_fft.py

    r71f2e5f r41b985f  
    3434        fftgrain = f (timegrain)
    3535        assert_equal ( fftgrain.norm, 0 )
    36         assert_equal ( fftgrain.phas, 0 )
     36        try:
     37            assert_equal ( fftgrain.phas, 0 )
     38        except AssertionError:
     39            assert_equal (fftgrain.phas[fftgrain.phas > 0], +pi)
     40            assert_equal (fftgrain.phas[fftgrain.phas < 0], -pi)
     41            assert_equal (np.abs(fftgrain.phas[np.abs(fftgrain.phas) != pi]), 0)
     42            self.skipTest('fft(fvec(%d)).phas != +0, ' % win_s \
     43                    + 'This is expected when using fftw3 on powerpc.')
    3744
    3845    def test_impulse(self):
  • python/tests/test_filter.py

    r71f2e5f r41b985f  
    44from numpy.testing import TestCase, assert_equal, assert_almost_equal
    55from aubio import fvec, digital_filter
    6 from utils import array_from_text_file
     6from .utils import array_from_text_file
    77
    88class aubio_filter_test_case(TestCase):
  • python/tests/test_filterbank.py

    r71f2e5f r41b985f  
    66import numpy as np
    77from aubio import cvec, filterbank, float_type
    8 from utils import array_from_text_file
     8from .utils import array_from_text_file
    99
    1010class aubio_filterbank_test_case(TestCase):
  • python/tests/test_midi2note.py

    r71f2e5f r41b985f  
    33
    44from aubio import midi2note
     5from nose2.tools import params
    56import unittest
    67
     
    1718class midi2note_good_values(unittest.TestCase):
    1819
    19     def test_midi2note_known_values(self):
     20    @params(*list_of_known_midis)
     21    def test_midi2note_known_values(self, midi, note):
    2022        " known values are correctly converted "
    21         for midi, note in list_of_known_midis:
    22             self.assertEqual ( midi2note(midi), note )
     23        self.assertEqual ( midi2note(midi), note )
    2324
    2425class midi2note_wrong_values(unittest.TestCase):
     
    4142
    4243if __name__ == '__main__':
    43     unittest.main()
     44    import nose2
     45    nose2.main()
  • python/tests/test_note2midi.py

    r71f2e5f r41b985f  
    55
    66from aubio import note2midi, freq2note
     7from nose2.tools import params
    78import unittest
    89
     
    1415        ( 'B3', 59 ),
    1516        ( 'B#3', 60 ),
     17        ( 'C♯4', 61 ),
    1618        ( 'A4', 69 ),
    1719        ( 'A#4', 70 ),
     20        ( 'A♯4', 70 ),
     21        ( 'A\u266f4', 70 ),
    1822        ( 'Bb4', 70 ),
    1923        ( 'B♭4', 70 ),
     24        ( 'B\u266d4', 70 ),
    2025        ( 'G8', 115 ),
    2126        ( 'G♯8', 116 ),
    2227        ( 'G9', 127 ),
    23         ( 'G\udd2a2', 45 ),
    24         ( 'B\ufffd2', 45 ),
    2528        ( 'A♮2', 45 ),
     29        )
     30
     31list_of_known_notes_with_unicode_issues = (
     32        ('C𝄪4', 62 ),
     33        ('E𝄫4', 62 ),
     34        )
     35
     36list_of_unknown_notes = (
     37        ( 'G\udd2a2' ),
     38        ( 'B\ufffd2' ),
     39        ( 'B\u266e\u266e2' ),
     40        ( 'B\u266f\u266d3' ),
     41        ( 'B33' ),
     42        ( 'C.3' ),
     43        ( 'A' ),
     44        ( '2' ),
    2645        )
    2746
    2847class note2midi_good_values(unittest.TestCase):
    2948
    30     def test_note2midi_known_values(self):
     49    @params(*list_of_known_notes)
     50    def test_note2midi_known_values(self, note, midi):
    3151        " known values are correctly converted "
    32         for note, midi in list_of_known_notes:
     52        self.assertEqual ( note2midi(note), midi )
     53
     54    @params(*list_of_known_notes_with_unicode_issues)
     55    def test_note2midi_known_values_with_unicode_issues(self, note, midi):
     56        " known values are correctly converted, unless decoding is expected to fail"
     57        try:
    3358            self.assertEqual ( note2midi(note), midi )
     59        except UnicodeEncodeError as e:
     60            import sys
     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
     64            if len('\U0001D12A') != 1 and sys.version[0] == '2':
     65                self.skipTest(strres + " | upgrade to Python 3 to fix")
     66            else:
     67                raise
    3468
    3569class note2midi_wrong_values(unittest.TestCase):
     
    67101        self.assertRaises(TypeError, note2midi, 123)
    68102
     103    def test_note2midi_wrong_data_too_long(self):
     104        " fails when passed a note with a note name longer than expected"
     105        self.assertRaises(ValueError, note2midi, 'CB+-3')
     106
     107    @params(*list_of_unknown_notes)
     108    def test_note2midi_unknown_values(self, note):
     109        " unknown values throw out an error "
     110        self.assertRaises(ValueError, note2midi, note)
    69111
    70112class freq2note_simple_test(unittest.TestCase):
     
    75117
    76118if __name__ == '__main__':
    77     unittest.main()
     119    import nose2
     120    nose2.main()
  • python/tests/test_phasevoc.py

    r71f2e5f r41b985f  
    4747            assert_equal ( t, 0.)
    4848            assert_equal ( s.norm, 0.)
    49             assert_equal ( s.phas, 0.)
     49            try:
     50                assert_equal ( s.phas, 0 )
     51            except AssertionError:
     52                assert_equal (s.phas[s.phas > 0], +np.pi)
     53                assert_equal (s.phas[s.phas < 0], -np.pi)
     54                assert_equal (np.abs(s.phas[np.abs(s.phas) != np.pi]), 0)
     55                self.skipTest('pvoc(fvec(%d)).phas != +0, ' % win_s \
     56                        + 'This is expected when using fftw3 on powerpc.')
    5057            assert_equal ( r, 0.)
    5158
  • python/tests/test_sink.py

    r71f2e5f r41b985f  
    55from numpy.testing import TestCase
    66from aubio import fvec, source, sink
    7 from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
     7from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
     8
     9import warnings
     10warnings.filterwarnings('ignore', category=UserWarning, append=True)
    811
    912list_of_sounds = list_all_sounds('sounds')
     
    2629        if not len(list_of_sounds):
    2730            self.skipTest('add some sound files in \'python/tests/sounds\'')
     31
     32    def test_wrong_filename(self):
     33        with self.assertRaises(RuntimeError):
     34            sink('')
     35
     36    def test_wrong_samplerate(self):
     37        with self.assertRaises(RuntimeError):
     38            sink(get_tmp_sink_path(), -1)
     39
     40    def test_wrong_samplerate_too_large(self):
     41        with self.assertRaises(RuntimeError):
     42            sink(get_tmp_sink_path(), 1536001, 2)
     43
     44    def test_wrong_channels(self):
     45        with self.assertRaises(RuntimeError):
     46            sink(get_tmp_sink_path(), 44100, -1)
     47
     48    def test_wrong_channels_too_large(self):
     49        with self.assertRaises(RuntimeError):
     50            sink(get_tmp_sink_path(), 44100, 202020)
    2851
    2952    def test_many_sinks(self):
     
    94117        del_tmp_sink_path(sink_path)
    95118
     119    def test_read_with(self):
     120        sink_path =get_tmp_sink_path()
     121        vec = fvec(128)
     122        with sink(sink_path, samplerate) as g:
     123            for i in range(10):
     124                g(vec, 128)
     125
    96126if __name__ == '__main__':
    97127    main()
  • python/tests/test_slicing.py

    r71f2e5f r41b985f  
    44from numpy.testing import TestCase, assert_equal
    55from aubio import slice_source_at_stamps
    6 from utils import count_files_in_directory, get_default_test_sound
    7 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
    88
    99import tempfile
  • python/tests/test_source.py

    r71f2e5f r41b985f  
    55from numpy.testing import TestCase, assert_equal
    66from aubio import source
    7 from utils import list_all_sounds
     7from .utils import list_all_sounds
    88import numpy as np
    99
     
    5757            if read < f.hop_size:
    5858                assert_equal(samples[read:], 0)
    59                 if 'brownnoise' in f.uri:
    60                     self.assertEquals(np.count_nonzero(samples[:read]), read)
    6159                break
    6260        #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}"
     
    7270            self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
    7371        assert f.samplerate != 0
    74         self.read_from_source(f)
     72        read_frames = self.read_from_source(f)
     73        if 'f_' in soundfile and samplerate == 0:
     74            import re
     75            f = re.compile('.*_\([0:9]*f\)_.*')
     76            match_f = re.findall('([0-9]*)f_', soundfile)
     77            if len(match_f) == 1:
     78                expected_frames = int(match_f[0])
     79                self.assertEqual(expected_frames, read_frames)
    7580
    7681    @params(*list_of_sounds)
     
    159164            if read < f.hop_size:
    160165                assert_equal(samples[:,read:], 0)
    161                 if 'brownnoise' in f.uri:
    162                     self.assertEquals(np.count_nonzero(samples[:,:read]), read)
    163166                break
    164167        #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"
     
    167170        return total_frames
    168171
     172class aubio_source_with(aubio_source_test_case_base):
     173
     174    #@params(*list_of_sounds)
     175    @params(*list_of_sounds)
     176    def test_read_from_mono(self, filename):
     177        total_frames = 0
     178        hop_size = 2048
     179        with source(filename, 0, hop_size) as input_source:
     180            assert_equal(input_source.hop_size, hop_size)
     181            #assert_equal(input_source.samplerate, samplerate)
     182            total_frames = 0
     183            for frames in input_source:
     184                total_frames += frames.shape[-1]
     185            # check we read as many samples as we expected
     186            assert_equal(total_frames, input_source.duration)
     187
    169188if __name__ == '__main__':
    170189    main()
Note: See TracChangeset for help on using the changeset viewer.