Skip to content

Commit

Permalink
Distinguish error message for empty list vs None. (#367)
Browse files Browse the repository at this point in the history
* Distinguish error message for empty list vs None.

* Add to test coverage.
  • Loading branch information
delucchi-cmu authored Aug 5, 2024
1 parent 28af48b commit 2221438
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/hipscat_import/catalog/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ def _check_arguments(self):
if self.catalog_type not in ("source", "object"):
raise ValueError("catalog_type should be one of `source` or `object`")

if (not self.input_path and not self.input_file_list) or (self.input_path and self.input_file_list):
raise ValueError("exactly one of input_path or input_file_list is required")
if self.file_reader is None:
raise ValueError("file_reader is required")
if isinstance(self.file_reader, str):
Expand Down
10 changes: 9 additions & 1 deletion src/hipscat_import/runtime_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,21 @@ def find_input_paths(
"""
input_paths = []
if input_path:
if input_file_list:
raise ValueError("exactly one of input_path or input_file_list is required")

if not file_io.does_file_or_directory_exist(input_path, storage_options=storage_options):
raise FileNotFoundError("input_path not found on local storage")
input_paths = file_io.find_files_matching_path(
input_path, file_matcher, include_protocol=True, storage_options=storage_options
)
elif input_file_list:
elif not input_file_list is None:
# It's common for users to accidentally pass in an empty list. Give them a friendly error.
if len(input_file_list) == 0:
raise ValueError("input_file_list is empty")
input_paths = input_file_list
else:
raise ValueError("exactly one of input_path or input_file_list is required")
if len(input_paths) == 0:
raise FileNotFoundError("No input files found")
return input_paths
27 changes: 27 additions & 0 deletions tests/hipscat_import/catalog/test_argument_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ def test_empty_required(small_sky_parts_dir, tmp_path):
output_path=tmp_path,
)

with pytest.raises(ValueError, match="input_file_list is required"):
ImportArguments(
output_artifact_name="catalog",
file_reader="csv",
input_file_list=None,
output_path=tmp_path,
)

with pytest.raises(ValueError, match="input_file_list is empty"):
ImportArguments(
output_artifact_name="catalog",
file_reader="csv",
input_file_list=[],
output_path=tmp_path,
)


def test_invalid_paths(blank_data_dir, tmp_path):
"""Required arguments are provided, but paths aren't found."""
Expand All @@ -55,6 +71,17 @@ def test_invalid_paths(blank_data_dir, tmp_path):
output_path=tmp_path,
)

# Too many paths!
with pytest.raises(ValueError, match="exactly one of"):
ImportArguments(
output_artifact_name="catalog",
input_path=blank_data_dir,
input_file_list=[blank_data_dir],
file_reader="csv",
output_path=tmp_path,
progress_bar=False,
)


def test_missing_paths(tmp_path):
## Input path has no files
Expand Down

0 comments on commit 2221438

Please sign in to comment.