Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanklut committed Dec 12, 2023
1 parent 46c4e64 commit ff8d16a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ jobs:
run: conda info
- name: Conda list
run: conda list

- name: Test image utils
run: |
python tests/test_image_utils.py
- name: Test input utils
run: |
python tests/test_input_utils.py
44 changes: 43 additions & 1 deletion tests/test_input_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path

sys.path.append(str(Path(__file__).resolve().parent.joinpath("..")))
from utils.input_utils import clean_input_paths
from utils.input_utils import clean_input_paths, get_file_paths


class TestInputUtils(unittest.TestCase):
Expand Down Expand Up @@ -40,6 +40,48 @@ def test_mixed_type_input(self):
with self.assertRaises(TypeError):
clean_input_paths(mixed_input)

def test_empty_input_paths(self):
input_path = None
formats = {".jpg", ".png"}
with self.assertRaises(TypeError):
get_file_paths(input_path, formats)

def test_empty_formats(self):
input_path = "/path/to/single/file.jpg"
formats = set()
with self.assertRaises(ValueError):
get_file_paths(input_path, formats)

def test_nonexistent_input_path(self):
input_path = "/nonexistent/path"
formats = {".jpg", ".png"}
with self.assertRaises(FileNotFoundError):
get_file_paths(input_path, formats)

def test_permission_error_input_path(self):
input_path = "/protected/path"
formats = {".jpg", ".png"}
with self.assertRaises(PermissionError):
get_file_paths(input_path, formats)

def test_invalid_file_type(self):
input_path = "/path/to/file.txt"
formats = {".jpg", ".png"}
with self.assertRaises(ValueError):
get_file_paths(input_path, formats)

def test_directory_with_no_supported_files(self):
input_path = "/path/to/empty/directory"
formats = {".jpg", ".png"}
with self.assertRaises(FileNotFoundError):
get_file_paths(input_path, formats)

def test_txt_file_with_nonexistent_paths(self):
input_path = "/path/to/invalid/files.txt"
formats = {".jpg", ".png"}
with self.assertRaises(FileNotFoundError):
get_file_paths(input_path, formats)


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion utils/input_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_file_paths(
raise TypeError("Cannot run when the input path is None")

if not formats:
raise ValueError("Must provide the accepted image types")
raise ValueError("Must provide the accepted file formats (extensions)")

input_paths = clean_input_paths(input_paths)

Expand Down

0 comments on commit ff8d16a

Please sign in to comment.