Skip to content

Commit 8187cbd

Browse files
committed
extend cmaps length test
Co-authored-by: @neutrinoceros
1 parent 88b5178 commit 8187cbd

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

cmasher/tests/test_utils.py

+24-5
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,24 @@ def test_combine_cmaps(self, cmaps, nodes):
9797

9898
assert combined_cmap.N == 256
9999

100-
# Test if combining a single colormap raises an error
101-
def test_single_cmap(self):
102-
with pytest.raises(ValueError, match="Cannot combine a single colormap."):
103-
combine_cmaps(cmaps=["Blues"])
100+
# Test if combining less than 2 colormaps triggers an error
101+
@pytest.mark.parametrize(
102+
"cmaps",
103+
[
104+
pytest.param([], id="no_cmap"),
105+
pytest.param(
106+
[
107+
"Blues",
108+
],
109+
id="single_cmap",
110+
),
111+
],
112+
)
113+
def test_single_cmap(self, cmaps):
114+
with pytest.raises(
115+
ValueError, match="Expected at least two colormaps to combine."
116+
):
117+
combine_cmaps(cmaps)
104118

105119
# Test if invalid colormap types raise an error
106120
@pytest.mark.parametrize(
@@ -115,7 +129,12 @@ def test_invalid_cmap_types(self, invalid_cmap):
115129
combine_cmaps(cmaps=["Blues", invalid_cmap])
116130

117131
# Test if invalid nodes types raise an error
118-
@pytest.mark.parametrize("invalid_nodes", [0.5,],)
132+
@pytest.mark.parametrize(
133+
"invalid_nodes",
134+
[
135+
0.5,
136+
],
137+
)
119138
def test_invalid_nodes_types(self, invalid_nodes):
120139
with pytest.raises(
121140
TypeError,

cmasher/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ def combine_cmaps(
296296
297297
"""
298298
# Check colormap datatype and convert to list[Colormap]
299-
if len(cmaps) == 1:
300-
raise ValueError("Cannot combine a single colormap.")
299+
if len(cmaps) <= 1:
300+
raise ValueError("Expected at least two colormaps to combine.")
301301
for cm in cmaps:
302302
if not isinstance(cm, (Colormap, str)):
303303
raise TypeError(f"Unsupported colormap type: {type(cm)}.")

0 commit comments

Comments
 (0)