-
Notifications
You must be signed in to change notification settings - Fork 13
fix(cli): Fix crash in templateflow get when matching one file #140
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
951404e
test(cli): Verify get and ls behavior for 1 and multiple files
effigies b4d1f56
fix(cli): Fix crash in templateflow get when matching one file
effigies 3911108
test: Check stdout, not combined stdout/stderr
effigies e48c4cf
test: Make fixture for CliRunner
effigies 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,69 @@ | ||
| from pathlib import Path | ||
|
|
||
| import click.testing | ||
| import pytest | ||
|
|
||
| from .. import cli | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def runner(): | ||
| return click.testing.CliRunner() | ||
|
|
||
|
|
||
| def test_ls_one(runner): | ||
| result = runner.invoke(cli.main, ['ls', 'MNI152Lin', '--res', '1', '-s', 'T1w']) | ||
|
|
||
| # One result | ||
| lines = result.stdout.strip().splitlines() | ||
| assert len(lines) == 1 | ||
|
|
||
| assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T1w.nii.gz' in lines[0] | ||
|
|
||
| path = Path(lines[0]) | ||
|
|
||
| assert path.exists() | ||
|
|
||
|
|
||
| def test_ls_multi(runner): | ||
| result = runner.invoke(cli.main, ['ls', 'MNI152Lin', '--res', '1', '-s', 'T1w', '-s', 'T2w']) | ||
|
|
||
| # Two results | ||
| lines = result.stdout.strip().splitlines() | ||
| assert len(lines) == 2 | ||
|
|
||
| assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T1w.nii.gz' in lines[0] | ||
| assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T2w.nii.gz' in lines[1] | ||
|
|
||
| paths = [Path(line) for line in lines] | ||
|
|
||
| assert all(path.exists() for path in paths) | ||
|
|
||
|
|
||
| def test_get_one(runner): | ||
| result = runner.invoke(cli.main, ['get', 'MNI152Lin', '--res', '1', '-s', 'T1w']) | ||
|
|
||
| # One result, possible download status before | ||
| lines = result.stdout.strip().splitlines()[-2:] | ||
|
|
||
| assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T1w.nii.gz' in lines[0] | ||
|
|
||
| path = Path(lines[0]) | ||
|
|
||
| stat_res = path.stat() | ||
| assert stat_res.st_size == 10669511 | ||
|
|
||
|
|
||
| def test_get_multi(runner): | ||
| result = runner.invoke(cli.main, ['get', 'MNI152Lin', '--res', '1', '-s', 'T1w', '-s', 'T2w']) | ||
|
|
||
| # Two result, possible download status before | ||
| lines = result.stdout.strip().splitlines()[-3:] | ||
|
|
||
| assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T1w.nii.gz' in lines[0] | ||
| assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T2w.nii.gz' in lines[1] | ||
|
|
||
| paths = [Path(line) for line in lines] | ||
|
|
||
| stats = [path.stat() for path in paths] | ||
| assert [stat_res.st_size for stat_res in stats] == [10669511, 10096230] |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps past the reach of this PR - but it would be nice to print out a more helpful message with empty lists, i.e.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One currently useful feature is that the output is filenames. Helpful messages on stderr are fine, but I wouldn't want to change the utility of stdout to bash scripts.
Fine for another PR, but I don't want to scope creep this one.