|
20 | 20 | from ..representation import REPRESENTATION_CLASSES |
21 | 21 | from ...coordinates import (ICRS, FK4, FK5, Galactic, SkyCoord, Angle, |
22 | 22 | SphericalRepresentation, CartesianRepresentation, |
23 | | - UnitSphericalRepresentation, AltAz) |
| 23 | + UnitSphericalRepresentation, AltAz, |
| 24 | + BaseCoordinateFrame, FrameAttribute, |
| 25 | + frame_transform_graph) |
24 | 26 | from ...coordinates import Latitude, Longitude, EarthLocation |
25 | 27 | from ...time import Time |
26 | 28 | from ...utils import minversion |
@@ -1135,3 +1137,40 @@ def test_getitem_representation(): |
1135 | 1137 | sc = SkyCoord([1, 1] * u.deg, [2, 2] * u.deg) |
1136 | 1138 | sc.representation = 'cartesian' |
1137 | 1139 | assert sc[0].representation is CartesianRepresentation |
| 1140 | + |
| 1141 | + |
| 1142 | +def test_frame_attr_changes(): |
| 1143 | + """ |
| 1144 | + This tests the case where a frame is added with a new frame attribute after |
| 1145 | + a SkyCoord has been created. This is necessary because SkyCoords get the |
| 1146 | + attributes set at creation time, but the set of attributes can change as |
| 1147 | + frames are added or removed from the transform graph. This makes sure that |
| 1148 | + everything continues to work consistently. |
| 1149 | + """ |
| 1150 | + sc_before = SkyCoord(1*u.deg, 2*u.deg, frame='icrs') |
| 1151 | + |
| 1152 | + assert 'fakeattr' not in dir(sc_before) |
| 1153 | + |
| 1154 | + class FakeFrame(BaseCoordinateFrame): |
| 1155 | + fakeattr = FrameAttribute() |
| 1156 | + |
| 1157 | + # doesn't matter what this does as long as it just puts the frame in the |
| 1158 | + # transform graph |
| 1159 | + transset = (ICRS, FakeFrame, lambda c,f:c) |
| 1160 | + frame_transform_graph.add_transform(*transset) |
| 1161 | + try: |
| 1162 | + assert 'fakeattr' in dir(sc_before) |
| 1163 | + assert sc_before.fakeattr is None |
| 1164 | + |
| 1165 | + sc_after1 = SkyCoord(1*u.deg, 2*u.deg, frame='icrs') |
| 1166 | + assert 'fakeattr' in dir(sc_after1) |
| 1167 | + assert sc_after1.fakeattr is None |
| 1168 | + |
| 1169 | + sc_after2 = SkyCoord(1*u.deg, 2*u.deg, frame='icrs', fakeattr=1) |
| 1170 | + assert sc_after2.fakeattr == 1 |
| 1171 | + finally: |
| 1172 | + frame_transform_graph.remove_transform(*transset) |
| 1173 | + |
| 1174 | + assert 'fakeattr' not in dir(sc_before) |
| 1175 | + assert 'fakeattr' not in dir(sc_after1) |
| 1176 | + assert 'fakeattr' not in dir(sc_after2) |
0 commit comments