Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adds check on top level dir before walk #14

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading