|
9 | 9 | import matplotlib.pyplot as plt
|
10 | 10 | import matplotlib.patches as mpatches
|
11 | 11 | import matplotlib.transforms as mtransforms
|
12 |
| -from matplotlib.transforms import Affine2D, Bbox, TransformedBbox |
| 12 | +from matplotlib.transforms import Affine2D, Bbox, TransformedBbox, _ScaledRotation |
13 | 13 | from matplotlib.path import Path
|
14 | 14 | from matplotlib.testing.decorators import image_comparison, check_figures_equal
|
| 15 | +from unittest.mock import MagicMock |
15 | 16 |
|
16 | 17 |
|
17 | 18 | class TestAffine2D:
|
@@ -1104,3 +1105,27 @@ def test_interval_contains_open():
|
1104 | 1105 | assert not mtransforms.interval_contains_open((0, 1), -1)
|
1105 | 1106 | assert not mtransforms.interval_contains_open((0, 1), 2)
|
1106 | 1107 | assert mtransforms.interval_contains_open((1, 0), 0.5)
|
| 1108 | + |
| 1109 | + |
| 1110 | +def test_scaledrotation_initialization(): |
| 1111 | + """Test that the ScaledRotation object is initialized correctly.""" |
| 1112 | + theta = 1.0 # Arbitrary theta value for testing |
| 1113 | + trans_shift = MagicMock() # Mock the trans_shift transformation |
| 1114 | + scaled_rot = _ScaledRotation(theta, trans_shift) |
| 1115 | + assert scaled_rot._theta == theta |
| 1116 | + assert scaled_rot._trans_shift == trans_shift |
| 1117 | + assert scaled_rot._mtx is None |
| 1118 | + |
| 1119 | + |
| 1120 | +def test_scaledrotation_get_matrix_invalid(): |
| 1121 | + """Test get_matrix when the matrix is invalid and needs recalculation.""" |
| 1122 | + theta = np.pi / 2 |
| 1123 | + trans_shift = MagicMock(transform=MagicMock(return_value=[[theta, 0]])) |
| 1124 | + scaled_rot = _ScaledRotation(theta, trans_shift) |
| 1125 | + scaled_rot._invalid = True |
| 1126 | + matrix = scaled_rot.get_matrix() |
| 1127 | + trans_shift.transform.assert_called_once_with([[theta, 0]]) |
| 1128 | + expected_rotation = np.array([[0, -1], |
| 1129 | + [1, 0]]) |
| 1130 | + assert matrix is not None |
| 1131 | + assert_allclose(matrix[:2, :2], expected_rotation, atol=1e-15) |
0 commit comments