diff --git a/AutoTransformPy/rotate.py b/AutoTransformPy/rotate.py index 736a63e..942bbde 100644 --- a/AutoTransformPy/rotate.py +++ b/AutoTransformPy/rotate.py @@ -8,6 +8,7 @@ from skimage.io import imread from skimage.transform import rotate as rot import numpy as np +import os def rotate (image_path, num_images, max_rotation): """Returns an array of images of length num_images randomly rotated a random degree up to max_rotation @@ -48,6 +49,9 @@ def rotate (image_path, num_images, max_rotation): if max_rotation < 1 or max_rotation > 360: raise ValueError("The maximum rotation must be between 1 and 360.") + if not os.path.isfile(image_path): + raise FileNotFoundError("No image found at path") + # Perform image rotation rotations = np.random.randint(-max_rotation, max_rotation, num_images) org_image = imread(image_path) diff --git a/tests/test_rotate.py b/tests/test_rotate.py index a988305..052c6f4 100644 --- a/tests/test_rotate.py +++ b/tests/test_rotate.py @@ -14,6 +14,9 @@ def test_inputs(): rot.rotate("../tests/imgs/milad.jpg", 7, 500) # Outside of the rotation range rot.rotate("../tests/imgs/milad.jpg", -1, 500) # Nonsense number of images to return + with pytest.raises(FileNotFoundError): + rot.rotate("../tests/imgs/Path.jpg") # Incorrect directory/file not in location + def test_return_imgs(): # Tests that the number of images returned from rotate is correct test_img = imread("../tests/imgs/milad.jpg") returned_arr = rot.rotate("../tests/imgs/milad.jpg", 5, 180)