-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2293 from nabobalis/preferred_cmap
Raise error when passing in an incorrect string or object for a preferred colormap for VisualAttributes
- Loading branch information
Showing
3 changed files
with
70 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,5 @@ glue/qt/glue_qt_resources.py | |
.pytest_cache | ||
.tox | ||
.vscode | ||
# vscode plugin | ||
.history |
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,30 @@ | ||
from glue.core.visual import VisualAttributes | ||
from matplotlib.cm import get_cmap | ||
import pytest | ||
|
||
|
||
def test_VA_preferred_cmap(): | ||
# Not a real CMAP array - errors | ||
with pytest.raises(TypeError, match="`preferred_cmap` must be a string or an instance of a matplotlib.colors.Colormap"): | ||
VisualAttributes(preferred_cmap=1) | ||
|
||
# Not a valid string for a CMAP - errors | ||
with pytest.raises(ValueError, match="not_a_cmap is not a valid colormap name."): | ||
VisualAttributes(preferred_cmap="not_a_cmap") | ||
|
||
viridis_cmap = get_cmap("viridis") | ||
|
||
# get_cmap cmap name | ||
va = VisualAttributes(preferred_cmap="viridis") | ||
assert va.preferred_cmap == viridis_cmap | ||
# formal cmap name | ||
va = VisualAttributes(preferred_cmap="Viridis") | ||
assert va.preferred_cmap == viridis_cmap | ||
|
||
# Valid Colormap | ||
va = VisualAttributes(preferred_cmap=viridis_cmap) | ||
assert va.preferred_cmap == viridis_cmap | ||
|
||
# None is allowed - it is the default | ||
va = VisualAttributes(preferred_cmap=None) | ||
assert va.preferred_cmap is None |
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