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

Add test for ShapeFactory plotting method used in the docs. #128

Merged
merged 2 commits into from
May 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/shapes/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,26 @@ def test_generate_shape_error(self, shape_factory):
"""Test the generate_shape() method on a non-existent shape."""
with pytest.raises(ValueError, match='No such shape'):
_ = shape_factory.generate_shape('does not exist')

@pytest.mark.parametrize('subset', [4, 5, 8, 10, None])
def test_plot_available_shapes(self, shape_factory, monkeypatch, subset):
"""Test the plot_available_shapes() method."""
if subset:
monkeypatch.setattr(
shape_factory,
'AVAILABLE_SHAPES',
shape_factory.AVAILABLE_SHAPES[:subset],
)

axs = shape_factory.plot_available_shapes()
if subset is None or subset > 5:
assert len(axs) > 1
else:
assert len(axs) == axs.size

populated_axs = [ax for ax in axs.flatten() if ax.get_figure()]
assert len(populated_axs) == len(shape_factory.AVAILABLE_SHAPES)
assert all([ax.get_xlabel() == ax.get_ylabel() == '' for ax in populated_axs])
assert set(ax.get_title() for ax in populated_axs) == set(
shape_factory.AVAILABLE_SHAPES
)