Skip to content

Commit 989fce6

Browse files
committed
refactored error message and created unit test.
1 parent 8fa2c0d commit 989fce6

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/aspire/source/image.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,8 +774,10 @@ def __init__(self, im, metadata=None, angles=None):
774774
try:
775775
im = Image(im)
776776
except Exception as e:
777-
logger.error("Creating Image object from Numpy array failed.")
778-
raise e
777+
raise RuntimeError(
778+
"Creating Image object from Numpy array failed."
779+
f" Original error: {str(e)}"
780+
)
779781

780782
super().__init__(
781783
L=im.res, n=im.n_images, dtype=im.dtype, metadata=metadata, memory=None

tests/test_array_image_source.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ def testArrayImageSourceFromNumpy(self):
7171
# Comparison should be yield identity
7272
self.assertTrue(np.allclose(ims_np, self.ims_np))
7373

74+
def testArrayImageSourceNumpyError(self):
75+
"""
76+
Test that ArrayImageSource when instantiated with incorrect input
77+
gives appropriate error.
78+
"""
79+
80+
# Test we raise with expected message from getter.
81+
with raises(RuntimeError, match=r"Creating Image object from Numpy.*"):
82+
_ = ArrayImageSource(np.empty((3, 2, 1)))
83+
7484
def testArrayImageSourceAngGetterError(self):
7585
"""
7686
Test that ArrayImageSource when instantiated without required

0 commit comments

Comments
 (0)