Skip to content

Commit

Permalink
Merge pull request #128 from stefmolin/factory-plot-test
Browse files Browse the repository at this point in the history
Add test for ShapeFactory plotting method used in the docs.
  • Loading branch information
stefmolin authored May 15, 2023
2 parents 3cb8c90 + f08c850 commit 9940da6
Showing 1 changed file with 23 additions and 0 deletions.
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
)

0 comments on commit 9940da6

Please sign in to comment.