| 75 | |
| 76 | @_isolated_tk_test(success_count=6) # len(bad_boxes) |
| 77 | def test_blit(): |
| 78 | import matplotlib.pyplot as plt |
| 79 | import numpy as np |
| 80 | import matplotlib.backends.backend_tkagg # noqa |
| 81 | from matplotlib.backends import _backend_tk, _tkagg |
| 82 | |
| 83 | fig, ax = plt.subplots() |
| 84 | photoimage = fig.canvas._tkphoto |
| 85 | data = np.ones((4, 4, 4), dtype=np.uint8) |
| 86 | # Test out of bounds blitting. |
| 87 | bad_boxes = ((-1, 2, 0, 2), |
| 88 | (2, 0, 0, 2), |
| 89 | (1, 6, 0, 2), |
| 90 | (0, 2, -1, 2), |
| 91 | (0, 2, 2, 0), |
| 92 | (0, 2, 1, 6)) |
| 93 | for bad_box in bad_boxes: |
| 94 | try: |
| 95 | _tkagg.blit( |
| 96 | photoimage.tk.interpaddr(), str(photoimage), data, |
| 97 | _tkagg.TK_PHOTO_COMPOSITE_OVERLAY, (0, 1, 2, 3), bad_box) |
| 98 | except ValueError: |
| 99 | print("success") |
| 100 | |
| 101 | # Test blitting to a destroyed canvas. |
| 102 | plt.close(fig) |
| 103 | _backend_tk.blit(photoimage, data, (0, 1, 2, 3)) |
| 104 | |
| 105 | |
| 106 | @_isolated_tk_test(success_count=1) |