test_backend_tk.py 934 B

12345678910111213141516171819202122232425262728
  1. import pytest
  2. import numpy as np
  3. from matplotlib import pyplot as plt
  4. @pytest.mark.backend('TkAgg', skip_on_importerror=True)
  5. def test_blit():
  6. from matplotlib.backends import _tkagg
  7. def evil_blit(photoimage, aggimage, offsets, bboxptr):
  8. data = np.asarray(aggimage)
  9. height, width = data.shape[:2]
  10. dataptr = (height, width, data.ctypes.data)
  11. _tkagg.blit(
  12. photoimage.tk.interpaddr(), str(photoimage), dataptr, offsets,
  13. bboxptr)
  14. fig, ax = plt.subplots()
  15. for bad_boxes in ((-1, 2, 0, 2),
  16. (2, 0, 0, 2),
  17. (1, 6, 0, 2),
  18. (0, 2, -1, 2),
  19. (0, 2, 2, 0),
  20. (0, 2, 1, 6)):
  21. with pytest.raises(ValueError):
  22. evil_blit(fig.canvas._tkphoto,
  23. np.ones((4, 4, 4)),
  24. (0, 1, 2, 3),
  25. bad_boxes)