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] force ordered output of _sanitize_reorder to match regex in test #3751

Merged
merged 4 commits into from
Jun 13, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion nilearn/plotting/matrix_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,15 @@
"""Help for plot_matrix."""
VALID_REORDER_ARGS = {True, False, 'single', 'complete', 'average'}
if reorder not in VALID_REORDER_ARGS:
param_to_print = []

Check warning on line 103 in nilearn/plotting/matrix_plotting.py

View check run for this annotation

Codecov / codecov/patch

nilearn/plotting/matrix_plotting.py#L103

Added line #L103 was not covered by tests
for item in VALID_REORDER_ARGS:
if isinstance(item, str):
param_to_print.append(f'"{item}"')

Check warning on line 106 in nilearn/plotting/matrix_plotting.py

View check run for this annotation

Codecov / codecov/patch

nilearn/plotting/matrix_plotting.py#L106

Added line #L106 was not covered by tests
else:
param_to_print.append(str(item))

Check warning on line 108 in nilearn/plotting/matrix_plotting.py

View check run for this annotation

Codecov / codecov/patch

nilearn/plotting/matrix_plotting.py#L108

Added line #L108 was not covered by tests
raise ValueError(
f"Parameter reorder needs to be one of {VALID_REORDER_ARGS}.")
f"Parameter reorder needs to be one of:\n{', '.join(param_to_print)}."
)
reorder = 'average' if reorder is True else reorder
return reorder

Expand Down
10 changes: 8 additions & 2 deletions nilearn/plotting/tests/test_matrix_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,15 @@ def test_sanitize_reorder(reorder):
@pytest.mark.parametrize("reorder", [None, "foo", 2])
def test_sanitize_reorder_error(reorder):
from ..matrix_plotting import _sanitize_reorder
param_to_print = []
for item in VALID_REORDER_VALUES:
if isinstance(item, str):
param_to_print.append(f'"{item}"')
else:
param_to_print.append(str(item))
with pytest.raises(ValueError,
match=("Parameter reorder needs to be "
f"one of {VALID_REORDER_VALUES}")):
match=("Parameter reorder needs to be one of:\n"
f"{', '.join(param_to_print)}.")):
_sanitize_reorder(reorder)


Expand Down