def test_read_after_close(self): samplerate = 0 # use native samplerate hop_size = 256 f = source(default_test_sound, samplerate, hop_size) read, frames = f() f.close() with assert_raises(RuntimeError): read, frames = f() with assert_raises(RuntimeError): read, frames = f.do_multi()
def test_process_2d_bounds(): # behavior: _process_2d_bounds accepts all possible ways to set x and y # bounds in 2d plots and returns a 1d array with equally spaced # intervals between the lower and upper bound of the data. The number # of elements in the 1d array must be of one element larger than the # shape of the data, because it includes the upper bound. height, width = 20, 10 array_data = np.ones(shape=(height, width)) plot = Plot() # bounds is None : infer from array_data shape xs = plot._process_2d_bounds(None, array_data, 1) assert xs.shape[0] == width + 1 ys = plot._process_2d_bounds(None, array_data, 0) assert ys.shape[0] == height + 1 # bounds is a tuple : it defines lower and upper range bounds = (1.0, 100.0) xs = plot._process_2d_bounds(bounds, array_data, 1) assert xs.shape[0] == width + 1 assert xs[0] == bounds[0] and xs[-1] == bounds[1] # bounds is a 1D array: the first and last elements are used to create # equally spaced intervals. Bounds must be of one element larger than the # corresponding axis in array_data, or it will raise a Value error bounds = np.zeros((height + 1, )) bounds[0], bounds[-1] = 0.2, 21.3 ys = plot._process_2d_bounds(bounds, array_data, 0) assert ys.shape[0] == height + 1 assert ys[0] == bounds[0] and ys[-1] == bounds[-1] with assert_raises(ValueError): bounds = np.zeros((width // 2, )) plot._process_2d_bounds(bounds, array_data, 0) # bounds is a 2D array: the first and last elements along the appropriate # axis are used to create equally spaced intervals. # The size of the bounds must be the same as the data array, or this # sill raise a ValueError xbounds, ybounds = np.meshgrid(np.arange(width), np.arange(height)) xs = plot._process_2d_bounds(xbounds, array_data, 1) assert xs.shape[0] == width + 1 assert xs[0] == xbounds[0, 0] and xs[-2] == xbounds[0, -1] with assert_raises(ValueError): plot._process_2d_bounds(xbounds[:5, :], array_data, 1) ys = plot._process_2d_bounds(ybounds, array_data, 0) assert ys.shape[0] == height + 1 assert ys[0] == ybounds[0, 0] and ys[-2] == ybounds[-1, 0]
def test_process_2d_bounds(): # behavior: _process_2d_bounds accepts all possible ways to set x and y # bounds in 2d plots and returns a 1d array with equally spaced # intervals between the lower and upper bound of the data. The number # of elements in the 1d array must be of one element larger than the # shape of the data, because it includes the upper bound. height, width = 20, 10 array_data = np.ones(shape=(height, width)) plot = Plot() # bounds is None : infer from array_data shape xs = plot._process_2d_bounds(None, array_data, 1) assert xs.shape[0] == width + 1 ys = plot._process_2d_bounds(None, array_data, 0) assert ys.shape[0] == height + 1 # bounds is a tuple : it defines lower and upper range bounds = (1.0, 100.0) xs = plot._process_2d_bounds(bounds, array_data, 1) assert xs.shape[0] == width + 1 assert xs[0] == bounds[0] and xs[-1] == bounds[1] # bounds is a 1D array: the first and last elements are used to create # equally spaced intervals. Bounds must be of one element larger than the # corresponding axis in array_data, or it will raise a Value error bounds = np.zeros((height+1, )) bounds[0], bounds[-1] = 0.2, 21.3 ys = plot._process_2d_bounds(bounds, array_data, 0) assert ys.shape[0] == height + 1 assert ys[0] == bounds[0] and ys[-1] == bounds[-1] with assert_raises(ValueError): bounds = np.zeros((width // 2, )) plot._process_2d_bounds(bounds, array_data, 0) # bounds is a 2D array: the first and last elements along the appropriate # axis are used to create equally spaced intervals. # The size of the bounds must be the same as the data array, or this # sill raise a ValueError xbounds, ybounds = np.meshgrid(np.arange(width), np.arange(height)) xs = plot._process_2d_bounds(xbounds, array_data, 1) assert xs.shape[0] == width + 1 assert xs[0] == xbounds[0,0] and xs[-2] == xbounds[0,-1] with assert_raises(ValueError): plot._process_2d_bounds(xbounds[:5,:], array_data, 1) ys = plot._process_2d_bounds(ybounds, array_data, 0) assert ys.shape[0] == height + 1 assert ys[0] == ybounds[0,0] and ys[-2] == ybounds[-1,0]
def test_wrong_seek_too_large(self): f = source(default_test_sound) try: with assert_raises(ValueError): f.seek(f.duration + f.samplerate * 10) except: skipTest('seeking after end of stream failed raising ValueError')
def test_note2midi_unknown_values(self, note): " unknown values throw out an error " assert_raises(ValueError, note2midi, note)
def test_midi2note_floating_value(self): " fails when passed a floating point " assert_raises(TypeError, midi2note, 69.2)
def test_midi2note_negative_value(self): " fails when passed a negative value " assert_raises(ValueError, midi2note, -2)
def test_wrong_channels(self): with assert_raises(RuntimeError): sink(get_tmp_sink_path(), 44100, -1)
def test_wrong_file(self): with assert_raises(RuntimeError): source('path_to/unexisting file.mp3')
def test_wrong_seek(self): f = source(default_test_sound) with assert_raises(ValueError): f.seek(-1)
def test_wrong_channels(self): with assert_raises(ValueError): source(default_test_sound, 0, 0, -1)
def test_wrong_hop_size(self): with assert_raises(ValueError): source(default_test_sound, 0, -1)
def test_wrong_samplerate(self): with assert_raises(ValueError): source(default_test_sound, -1)
def test_wrong_samplerate_too_large(self): with assert_raises(RuntimeError): sink(get_tmp_sink_path(), 1536001, 2)
def test_wrong_channels_too_large(self): with assert_raises(RuntimeError): sink(get_tmp_sink_path(), 44100, 202020)
def test_midi2note_large(self): " fails when passed a value greater than 127 " assert_raises(ValueError, midi2note, 128)
def test_midi2note_character_value(self): " fails when passed a value that can not be transformed to integer " assert_raises(TypeError, midi2note, "a")
def test_wrong_filename(self): with assert_raises(RuntimeError): sink('')
def test_wrong_samplerate(self): with assert_raises(RuntimeError): sink(get_tmp_sink_path(), -1)
def test_read_only_member(self, name): o = mfcc() with assert_raises((TypeError, AttributeError)): setattr(o, name, 0)