Skip to content

Commit

Permalink
split_blocks: Fix dimension checks.
Browse files Browse the repository at this point in the history
Make dimensions checks of the shape, block shape, and halo shape proper
`ValueError`s instead of being assertions. Also adds some tests to make
sure these cases are properly raised.
  • Loading branch information
jakirkham committed Dec 5, 2016
1 parent d65b1eb commit da222d6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
16 changes: 10 additions & 6 deletions kenjutsu/kenjutsu.py
Expand Up @@ -333,13 +333,17 @@ def split_blocks(space_shape, block_shape, block_halo=None):
ifilter, imap = filter, map

if block_halo is not None:
assert (len(space_shape) == len(block_shape) == len(block_halo)), \
"The dimensions of `space_shape`, `block_shape`, and " + \
"`block_halo` should be the same."
if not (len(space_shape) == len(block_shape) == len(block_halo)):
raise ValueError(
"The dimensions of `space_shape`, `block_shape`, and"
" `block_halo` should be the same."
)
else:
assert (len(space_shape) == len(block_shape)), \
"The dimensions of `space_shape` and `block_shape` " + \
"should be the same."
if not (len(space_shape) == len(block_shape)):
raise ValueError(
"The dimensions of `space_shape` and `block_shape` should be"
" the same."
)

block_halo = tuple()
for i in irange(len(space_shape)):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_kenjutsu.py
Expand Up @@ -196,6 +196,24 @@ def test_len_slices(self):


def test_split_blocks(self):
with self.assertRaises(ValueError) as e:
kenjutsu.split_blocks((1,), (1, 2), (1, 2, 3))

self.assertEqual(
str(e.exception),
"The dimensions of `space_shape`, `block_shape`, and `block_halo`"
" should be the same."
)

with self.assertRaises(ValueError) as e:
kenjutsu.split_blocks((1,), (1, 2))

self.assertEqual(
str(e.exception),
"The dimensions of `space_shape` and `block_shape` should be the"
" same."
)

blocks = kenjutsu.split_blocks((2,), (1,))
self.assertEqual(
blocks,
Expand Down

0 comments on commit da222d6

Please sign in to comment.