Skip to content

Commit

Permalink
TEST: Remove try block around dtype and dimension checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomastweets committed Aug 18, 2016
1 parent 9da49dc commit aaa9a95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
18 changes: 6 additions & 12 deletions nibabel/tests/test_files_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,9 @@ def test_files_spatialimages():
aff = np.eye(4)
# some Image types accept only a few datatypes and shapes
# so we check and force a type change to a compatible dtype
try:
supported_dims = supported_dimensions(klass.header_class())
if len(arr.shape) not in supported_dims:
arr = np.ones(tuple([d+2 for d in range(supported_dims.pop())]))
except:
pass
supported_dims = supported_dimensions(klass.header_class())
if len(arr.shape) not in supported_dims:
arr = np.ones(tuple([d+2 for d in range(supported_dims.pop())]))
supported_dtypes = supported_np_types(klass.header_class())
if arr.dtype not in supported_dtypes:
arr = arr.astype(supported_dtypes.pop())
Expand Down Expand Up @@ -103,12 +100,9 @@ def test_round_trip_spatialimages():
aff = np.eye(4)
# some Image types accept only a few datatypes and shapes
# so we check and force a type change to a compatible dtype
try:
supported_dims = supported_dimensions(klass.header_class())
if len(data.shape) not in supported_dims:
data = np.ones(tuple([d+2 for d in range(supported_dims.pop())]))
except:
pass
supported_dims = supported_dimensions(klass.header_class())
if len(data.shape) not in supported_dims:
data = np.ones(tuple([d+2 for d in range(supported_dims.pop())]))
supported_dtypes = supported_np_types(klass.header_class())
if data.dtype not in supported_dtypes:
data = data.astype(supported_dtypes.pop())
Expand Down
27 changes: 9 additions & 18 deletions nibabel/tests/test_image_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,9 @@ def validate_filenames(self, imaker, params):
new_dtype = np.float32
# some Image types accept only a few datatypes and shapes
# so we check and force a type change to a compatible dtype
try:
supported_dtypes = supported_np_types(img.header_class())
if new_dtype not in supported_dtypes:
new_dtype = supported_dtypes.pop()
except:
pass
supported_dtypes = supported_np_types(img.header_class())
if new_dtype not in supported_dtypes:
new_dtype = supported_dtypes.pop()
img.set_data_dtype(new_dtype)
# The bytesio_round_trip helper tests bytesio load / save via file_map
rt_img = bytesio_round_trip(img)
Expand Down Expand Up @@ -370,19 +367,13 @@ def obj_params(self):
aff = np.diag([1, 2, 3, 1])

# Try to retrieve allowed dims
try:
supported_dims = supported_dimensions(self.header_maker())
self.example_shapes = (shape for shape in self.example_shapes
if len(shape) in supported_dims)
except:
pass
supported_dims = supported_dimensions(self.header_maker())
self.example_shapes = (shape for shape in self.example_shapes
if len(shape) in supported_dims)
# Try to retrieve allowed dtypes
try:
supported_dtypes = supported_np_types(self.header_maker())
self.example_dtypes = (dtype for dtype in self.example_dtypes
if dtype in supported_dtypes)
except:
pass
supported_dtypes = supported_np_types(self.header_maker())
self.example_dtypes = (dtype for dtype in self.example_dtypes
if dtype in supported_dtypes)

def make_imaker(arr, aff, header=None):
return lambda: self.image_maker(arr, aff, header)
Expand Down

0 comments on commit aaa9a95

Please sign in to comment.