-
Notifications
You must be signed in to change notification settings - Fork 39
Partially revert lsjson #571
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bc9cb9d
Revert lsjson for local filesystem searches.
JoeZiminski c393173
working on tests.
JoeZiminski ae94419
Still working on test.
JoeZiminski 0a83429
Document tests.
JoeZiminski 6d7f92b
Fix tests.
JoeZiminski d7472a9
Try sorting outputs to fix tests.
JoeZiminski 35b5534
Sort all outputs for complete cross-platform equivalence.
JoeZiminski c42dd41
Fix tests on linux.
JoeZiminski 8bcec21
Minor changes to docstrings.
JoeZiminski cbd4fee
Apply feedback from review.
JoeZiminski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from datashuttle.utils.folders import ( | ||
| search_central_via_connection, | ||
| search_local_filesystem, | ||
| ) | ||
|
|
||
| from .. import test_utils | ||
| from ..base import BaseTest | ||
|
|
||
| # ----------------------------------------------------------------------------- | ||
| # Inconsistent sub or ses value lengths | ||
| # ----------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| class TestSubSesSearches(BaseTest): | ||
| @pytest.mark.parametrize("return_full_path", [True, False]) | ||
| def test_local_vs_central_search_methods( | ||
| self, project, monkeypatch, return_full_path | ||
| ): | ||
| """ | ||
| Test the `search_local_filesystem` and `search_central_via_connection` | ||
| functions. These functions should have the same outputs but `search_local_filesystem` | ||
| is used for local filesystem for speed. Here we check the outputs of these | ||
| functions match. | ||
|
|
||
| These functions are individually tested in many places, primarily in | ||
| transfer tests. Local filesystem transfer tests are very extensive, | ||
| because they are quicker, while central connection tests are less | ||
| thorough. We test the outputs of these two functions directly | ||
| under a range of test cases to ensure they are matched under many conditions. | ||
|
|
||
| """ | ||
| central_path = project.get_central_path() | ||
|
|
||
| # Create a project of folders and files | ||
| # fmt: off | ||
| paths_to_make = [] | ||
| for i in range(1, 4): | ||
| paths_to_make.append(Path(f"rawdata/sub-00{i}/ses-001/behav")) | ||
| paths_to_make.append(Path(f"rawdata/sub-00{i}/ses-002_date-20250402/behav")) | ||
| paths_to_make.append(Path(f"rawdata/sub-00{i}/ses-002_date-20250402/anat")) | ||
|
|
||
| paths_to_make.append(Path("rawdata/sub-003_condition-test/ses-001_hello-world/ephys")) | ||
| paths_to_make.append(Path("rawdata/sub-004_condition-test/ses-002_hello-world/funcimg")) | ||
|
|
||
| for path_ in paths_to_make: | ||
| (central_path / path_).mkdir(parents=True) | ||
| test_utils.write_file(central_path / path_ / f"{path_.name}_file.md", contents="hello_world",) | ||
| test_utils.write_file(central_path / path_.parent / f"{path_.name}.md", contents="hello_world",) | ||
| test_utils.write_file(central_path / path_.parent.parent / f"{path_.parent.name}.md", contents="hello_world",) | ||
| test_utils.write_file(central_path / path_.parent.parent.parent / f"{path_.parent.parent.name}.md", contents="hello_world",) | ||
| # fmt: on | ||
|
|
||
| # Monkeycatch `get_rclone_config_name` to return `local` and set `local` | ||
| # as a rclone config entry associated with the local filesystem. By this | ||
| # method we can hijack `search_central_via_connection` to run locally | ||
| # (though it is set up in practice to run via ssh, gdrive or aws). | ||
| monkeypatch.setattr( | ||
| project.cfg, | ||
| "get_rclone_config_name", | ||
| lambda connection_method: "local", | ||
| ) | ||
|
|
||
| subprocess.run( | ||
| "rclone config create local local nounc true", shell=True | ||
| ) | ||
|
JoeZiminski marked this conversation as resolved.
Outdated
|
||
|
|
||
| # Perform a range of checks across folders and files | ||
| # and check the outputs of both approaches match. | ||
| # fmt: off | ||
| for search_path, search_str in ( | ||
| (central_path / "rawdata", "*"), | ||
| (central_path / "rawdata", "sub-*"), | ||
| (central_path / "rawdata" / "sub-003_condition-test", "ses-*"), | ||
| (central_path / "rawdata/sub-001/ses-002_date-20250402", "behav"), | ||
| (central_path / "rawdata/sub-001/ses-002_date-20250402/behav", "behav_file.md",), | ||
| (central_path / "rawdata/sub-001/ses-002_date-20250402/behav", "*",), | ||
| (central_path / "rawdata/sub-002", "*"), | ||
| (central_path / "rawdata/sub-002/ses-002_date-20250402", "*"), | ||
| (central_path / "rawdata", "sub-003*"), | ||
| ): | ||
| # fmt: on | ||
|
|
||
| central_method_folders, central_method_files = ( | ||
| search_central_via_connection( | ||
| project.cfg, | ||
| search_path, | ||
| search_str, | ||
| return_full_path=return_full_path, | ||
| ) | ||
| ) | ||
| local_method_folders, local_method_files = search_local_filesystem( | ||
| search_path, search_str, return_full_path=return_full_path | ||
| ) | ||
|
|
||
| assert central_method_folders == local_method_folders, ( | ||
| f"Failed folders, search_str: {search_str}, search_path: {search_path}" | ||
| ) | ||
| assert central_method_files == local_method_files, ( | ||
| f"Failed files, search_str: {search_str}, search_path: {search_path}" | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.