Skip to content

Commit

Permalink
Merge pull request #118 from sroet/fix_cmap_test
Browse files Browse the repository at this point in the history
Actually test for the Userwarning on custom cmaps
  • Loading branch information
dwhswenson committed Jul 26, 2021
2 parents 914dfe1 + 0ff331d commit 12b1610
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
6 changes: 0 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@ environment:
PYTHONUNBUFFERED: 1

matrix:
#- PYTHON: "C:\\Miniconda38-x64"
#CONDA_PY: "38"
#ARCH: '64'
- PYTHON: "C:\\Miniconda37-x64"
CONDA_PY: "37"
ARCH: '64'
- PYTHON: "C:\\Miniconda36-x64"
CONDA_PY: "36"
ARCH: '64'

build: false

Expand Down
25 changes: 14 additions & 11 deletions contact_map/tests/test_plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
else:
HAS_MATPLOTLIB = True


@pytest.mark.parametrize("val", [0.5, 0.55, 0.6, 0.65, 0.7])
@pytest.mark.parametrize("map_type", ["name", "cmap"])
def test_ranged_colorbar_cmap(map_type, val):
Expand All @@ -33,39 +34,41 @@ def test_ranged_colorbar_cmap(map_type, val):
assert_allclose(cb.cmap(cb.norm(val)), default_cmap(norm(val)),
atol=atol)


@pytest.mark.parametrize("cmap", ['seismic', 'Blues', 'custom'])
def test_is_cmap_diverging(cmap):
custom = None

if HAS_MATPLOTLIB:
custom = LinearSegmentedColormap(
'testCmap',
segmentdata={
'red': [[0.0, 0.0, 0.0],
[0.5, 1.0, 1.0],
[1.0, 1.0, 1.0]],
'green': [[0.0, 0.0, 0.0],
[0.25, 0.0, 0.0],
[0.75, 1.0, 1.0],
[1.0, 1.0, 1.0]],
'blue': [[0.0, 0.0, 0.0],
[0.5, 0.0, 0.0],
[1.0, 1.0, 1.0]]},
'green': [[0.0, 0.0, 0.0],
[0.25, 0.0, 0.0],
[0.75, 1.0, 1.0],
[1.0, 1.0, 1.0]],
'blue': [[0.0, 0.0, 0.0],
[0.5, 0.0, 0.0],
[1.0, 1.0, 1.0]]},
N=256
)
elif cmap == 'custom':
# no matplotlib; can't do custom
pytest.skip()

cmap, expected = {
color_map, expected = {
'seismic': ('seismic', True),
'Blues': ('Blues', False),
'custom': (custom, False),
}[cmap]
if cmap == 'custom':
with pytest.warns(UserWarning):
assert is_cmap_diverging(cmap) == expected
with pytest.warns(UserWarning, match="Unknown colormap"):
assert is_cmap_diverging(color_map) == expected
else:
assert is_cmap_diverging(cmap) == expected
assert is_cmap_diverging(color_map) == expected


class TestContactRange(object):
Expand Down

0 comments on commit 12b1610

Please sign in to comment.