-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow for additional channels with same name (#185)
* allow for additional channels with same name must have different parent folder name otherwise error is thrown tests for this added * clearer variable names * clarify docstring * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * limit line lengths --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
65388d0
commit 31e2111
Showing
3 changed files
with
116 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -46,6 +46,7 @@ dev = [ | |
"pre-commit", | ||
"pytest-cov", | ||
"pytest-qt", | ||
"pytest-mock", | ||
"pytest", | ||
"setuptools_scm", | ||
"tox", | ||
|
This file contains 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,55 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from brainreg.core.cli import prep_registration | ||
|
||
|
||
def test_prep_registration_different_names(mocker): | ||
"""Check that additional channel names are returned, when unique.""" | ||
args = mocker.Mock() | ||
args.brainreg_directory = Path.home() # This just needs to exist | ||
args.additional_images = [ | ||
Path.home() / "additional_channel_0", | ||
Path.home() / "additional_channel_1", | ||
] | ||
|
||
_, additional_channel_outputs = prep_registration(args) | ||
assert "additional_channel_0" in additional_channel_outputs | ||
assert "additional_channel_1" in additional_channel_outputs | ||
|
||
|
||
def test_additional_channels_same_name_different_parent_name(mocker): | ||
""" | ||
Check that parent folder name is part of keys returned | ||
if additional channel names are not unique. | ||
""" | ||
args = mocker.Mock() | ||
args.brainreg_directory = Path.home() # This just needs to exist | ||
args.additional_images = [ | ||
Path.home() / "folder_0/duplicate_name", | ||
Path.home() / "folder_1/duplicate_name", | ||
] | ||
|
||
_, additional_channel_outputs = prep_registration(args) | ||
assert "folder_1_duplicate_name" in additional_channel_outputs.keys() | ||
assert "folder_1_duplicate_name" in additional_channel_outputs.keys() | ||
|
||
|
||
def test_prep_registration_same_name_same_parent_name(mocker): | ||
"""Check that error is thrown if both | ||
parent and additional channel name are non-unique. | ||
""" | ||
args = mocker.Mock() | ||
args.brainreg_directory = Path.home() # This just needs to exist | ||
args.additional_images = [ | ||
str(Path.home() / "duplicate_name"), | ||
str(Path.home() / "duplicate_name"), | ||
] | ||
|
||
with pytest.raises( | ||
AssertionError, | ||
match=".*ensure additional channels have a unique " | ||
+ "combination of name and parent folder.*", | ||
): | ||
prep_registration(args) |