Skip to content

Commit

Permalink
add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loftusa committed Apr 12, 2021
1 parent 3489094 commit 7570404
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 4 additions & 3 deletions graspologic/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@ def binary_heatmap(
----------
X : nx.Graph or np.ndarray object
Unweighted graph or numpy matrix to plot.
colors : list-like or np.ndarray
A list of exactly two colors to use for the heatmap.
colorbar_ticklabels : list-like
Binary labels to use in the colorbar.
Expand All @@ -383,7 +383,8 @@ def binary_heatmap(
raise ValueError(
"cmap is not allowed in a binary heatmap. To change colors, use the `colors` parameter."
)
if not (isinstance(colorbar_ticklabels, (list, tuple)) and len(colorbar_ticklabels == 2)):
if not (
isinstance(colorbar_ticklabels, (list, tuple)) and len(colorbar_ticklabels) == 2):
raise ValueError("colorbar_ticklabels must be list-like and length 2.")

cmap = mpl.colors.ListedColormap(colors)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,22 @@ def test_heatmap_output(plot_fun):
fig = heatmap(X, cmap="gist_rainbow")


def test_binary_heatmap_params():
X = er_np(10, 0.5)

with pytest.raises(ValueError):
binary_heatmap(X, colors=["white"])

with pytest.raises(ValueError):
binary_heatmap(X, colors=["white", "white", "black"])

with pytest.raises(ValueError):
binary_heatmap(X, colorbar_ticklabels="1")

with pytest.raises(ValueError):
binary_heatmap(X, colorbar_ticklabels=["one", "two", "wrong"])


def test_gridplot_inputs():
X = [er_np(10, 0.5)]
labels = ["ER(10, 0.5)"]
Expand Down

0 comments on commit 7570404

Please sign in to comment.