Skip to content

Commit

Permalink
blocks(): check if one of {blocksize, out} is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier committed Jul 27, 2014
1 parent a0c5997 commit 64e5d55
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pysoundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,10 @@ def blocks(self, blocksize=None, overlap=0, frames=-1, dtype='float64',
if self.mode == 'w':
raise RuntimeError("blocks() is not allowed in write mode")

if out is not None:
if out is None:
if blocksize is None:
raise TypeError("One of {blocksize, out} must be specified")
else:
if blocksize is not None:
raise TypeError(
"Only one of {blocksize, out} may be specified")
Expand Down
7 changes: 6 additions & 1 deletion tests/test_pysoundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ def assert_equal_list_of_arrays(list1, list2):
assert np.all(item1 == item2)


def test_blocks_without_blocksize():
with pytest.raises(TypeError):
list(sf.blocks(filename_stereo))


def test_blocks_full_last_block():
blocks = list(sf.blocks(filename_stereo, blocksize=2))
assert_equal_list_of_arrays(blocks, [data_stereo[0:2], data_stereo[2:4]])
Expand Down Expand Up @@ -241,7 +246,7 @@ def test_blocks_with_stop():


def test_blocks_with_too_large_start():
blocks = list(sf.blocks(filename_stereo, start=666))
blocks = list(sf.blocks(filename_stereo, blocksize=2, start=666))
assert_equal_list_of_arrays(blocks, [[]])


Expand Down

0 comments on commit 64e5d55

Please sign in to comment.