Skip to content

Commit

Permalink
fix: adds check on top level dir before walk (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtyoung84 authored Oct 5, 2024
1 parent 093775d commit d31c144
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/aind_data_upload_utils/check_directories_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ def _dask_task_to_process_directory_list(
logging.debug(
f"Checking {directory}. On {dir_counter} of {total_to_scan}"
)
# Scan top level directory first
self._check_path(directory)
for path, _, files in os.walk(directory):
for name in files:
# Expecting posix paths
Expand Down
23 changes: 23 additions & 0 deletions tests/test_check_directories_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,29 @@ def test_dask_task_to_process_directory_list(
mock_check_path.assert_has_calls(expected_calls, any_order=True)
mock_log_debug.assert_called()

@patch("logging.debug")
def test_dask_task_to_process_directory_list_error(
self, mock_log_debug: MagicMock
):
"""Tests dask_task_to_process_directory_list raises error"""

list_of_directories = [
(RESOURCES_DIR / "example_ephys_data_set").as_posix(),
(RESOURCES_DIR / "no_such_directory_in_tests").as_posix(),
(
SMART_SPIM_DIR / "SmartSPIM" / "Ex_488_Em_525" / "471320"
).as_posix(),
]
with self.assertRaises(FileNotFoundError) as e:
self.example_job._dask_task_to_process_directory_list(
directories=list_of_directories
)
self.assertIn(
"is neither a directory, file, nor valid symlink",
e.exception.args[0],
)
self.assertEqual(3, mock_log_debug.call_count)

@patch("dask.bag.map_partitions")
def test_check_for_broken_sym_links(self, mock_map_partitions: MagicMock):
"""Tests _check_for_broken_sym_links"""
Expand Down

0 comments on commit d31c144

Please sign in to comment.