Changeset 36e8956 for python


Ignore:
Timestamp:
May 14, 2016, 5:22:28 AM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
3865924
Parents:
ed938a2
Message:

python/tests/test_source.py: simplify, quieten

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_source.py

    red938a2 r36e8956  
    88
    99list_of_sounds = list_all_sounds('sounds')
     10default_test_sound = list_of_sounds[0]
    1011samplerates = [0, 44100, 8000, 32000]
    1112hop_sizes = [512, 1024, 64]
     
    5152            if read < f.hop_size: break
    5253        result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}"
    53         result_params = total_frames / float(f.samplerate), total_frames, int(total_frames/f.hop_size), f.samplerate, f.uri
    54         print (result_str.format(*result_params))
     54        result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri
     55        #print (result_str.format(*result_params))
    5556        return total_frames
    5657
     
    7576        assert f.samplerate != 0
    7677        self.read_from_source(f)
    77 
    78     @params(*list_of_sounds)
    79     def test_wrong_samplerate(self, p):
    80         try:
    81             f = source(p, -1)
    82         except ValueError as e:
    83             pass
    84         else:
    85             self.fail('negative samplerate does not raise ValueError')
    86 
    87     @params(*list_of_sounds)
    88     def test_wrong_hop_size(self, p):
    89         try:
    90             f = source(p, 0, -1)
    91         except ValueError as e:
    92             pass
    93         else:
    94             self.fail('negative hop_size does not raise ValueError')
    9578
    9679    @params(*list_of_sounds)
     
    124107        self.assertEqual(duration, total_frames)
    125108
     109
     110class aubio_source_test_wrong_params(TestCase):
     111
     112    def test_wrong_file(self):
     113        with self.assertRaises(RuntimeError):
     114            f = source('path_to/unexisting file.mp3')
     115
     116    def test_wrong_samplerate(self):
     117        with self.assertRaises(ValueError):
     118            f = source(default_test_sound, -1)
     119
     120    def test_wrong_hop_size(self):
     121        with self.assertRaises(ValueError):
     122            f = source(default_test_sound, 0, -1)
     123
     124    def test_wrong_channels(self):
     125        with self.assertRaises(ValueError):
     126            f = source(default_test_sound, 0, 0, -1)
     127
     128    def test_wrong_seek(self):
     129        f = source(default_test_sound)
     130        with self.assertRaises(ValueError):
     131            f.seek(-1)
     132
     133    def test_wrong_seek_too_large(self):
     134        f = source(default_test_sound)
     135        try:
     136            with self.assertRaises(ValueError):
     137                f.seek(f.duration + f.samplerate * 10)
     138        except AssertionError as e:
     139            self.skipTest('seeking after end of stream failed raising ValueError')
     140
    126141class aubio_source_readmulti_test_case(aubio_source_read_test_case):
    127142
     
    134149        result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"
    135150        result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri
    136         print (result_str.format(*result_params))
     151        #print (result_str.format(*result_params))
    137152        return total_frames
    138153
Note: See TracChangeset for help on using the changeset viewer.