test_gridspec.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import matplotlib.gridspec as gridspec
  2. import matplotlib.pyplot as plt
  3. import pytest
  4. def test_equal():
  5. gs = gridspec.GridSpec(2, 1)
  6. assert gs[0, 0] == gs[0, 0]
  7. assert gs[:, 0] == gs[:, 0]
  8. def test_width_ratios():
  9. """
  10. Addresses issue #5835.
  11. See at https://github.com/matplotlib/matplotlib/issues/5835.
  12. """
  13. with pytest.raises(ValueError):
  14. gridspec.GridSpec(1, 1, width_ratios=[2, 1, 3])
  15. def test_height_ratios():
  16. """
  17. Addresses issue #5835.
  18. See at https://github.com/matplotlib/matplotlib/issues/5835.
  19. """
  20. with pytest.raises(ValueError):
  21. gridspec.GridSpec(1, 1, height_ratios=[2, 1, 3])
  22. def test_repr():
  23. ss = gridspec.GridSpec(3, 3)[2, 1:3]
  24. assert repr(ss) == "GridSpec(3, 3)[2:3, 1:3]"
  25. ss = gridspec.GridSpec(2, 2,
  26. height_ratios=(3, 1),
  27. width_ratios=(1, 3))
  28. assert repr(ss) == \
  29. "GridSpec(2, 2, height_ratios=(3, 1), width_ratios=(1, 3))"
  30. def test_subplotspec_args():
  31. fig, axs = plt.subplots(1, 2)
  32. # should work:
  33. gs = gridspec.GridSpecFromSubplotSpec(2, 1,
  34. subplot_spec=axs[0].get_subplotspec())
  35. assert gs.get_topmost_subplotspec() == axs[0].get_subplotspec()
  36. with pytest.raises(TypeError, match="subplot_spec must be type SubplotSpec"):
  37. gs = gridspec.GridSpecFromSubplotSpec(2, 1, subplot_spec=axs[0])
  38. with pytest.raises(TypeError, match="subplot_spec must be type SubplotSpec"):
  39. gs = gridspec.GridSpecFromSubplotSpec(2, 1, subplot_spec=axs)