Skip to content

Commit

Permalink
Ensure input to gather_file_paths is a directory
Browse files Browse the repository at this point in the history
It does not make sense to use this function on a single file
  • Loading branch information
thompsonmj committed Jul 29, 2024
1 parent da3547d commit 809e179
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/sumbuddy/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ def __init__(self, input_directory):
message = f"The directory {input_directory} and subdirectories (if any) contain no files. \nPlease provide a directory with files."
super().__init__(message)

class NotADirectoryError(Exception):
def __init__(self, input_directory):
message = f"The input path '{input_directory}' is not a directory. \nPlease provide a directory with files."
super().__init__(message)

class NoFilesAfterFilteringError(Exception):
def __init__(self, input_directory, ignore_file):
message = f"The directory {input_directory} contains files, but all are filtered out. \nCheck patterns in your {ignore_file} file and/or hidden files settings."
Expand Down
6 changes: 5 additions & 1 deletion src/sumbuddy/mapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from sumbuddy.filter import Filter
from sumbuddy.exceptions import EmptyInputDirectoryError, NoFilesAfterFilteringError
from sumbuddy.exceptions import EmptyInputDirectoryError, NoFilesAfterFilteringError, NotADirectoryError

class Mapper:
def __init__(self):
Expand Down Expand Up @@ -39,6 +39,10 @@ def gather_file_paths(self, input_directory, ignore_file=None, include_hidden=Fa
---------
file_paths - List. Files in input_directory that are not ignored.
"""

if not os.path.isdir(input_directory):
raise NotADirectoryError(input_directory)

self.reset_filter(ignore_file=ignore_file, include_hidden=include_hidden)

file_paths = []
Expand Down

0 comments on commit 809e179

Please sign in to comment.