|
21 | 21 | from ..representation import REPRESENTATION_CLASSES |
22 | 22 | from ...coordinates import (ICRS, FK4, FK5, Galactic, SkyCoord, Angle, |
23 | 23 | SphericalRepresentation, CartesianRepresentation, |
24 | | - UnitSphericalRepresentation, AltAz) |
| 24 | + UnitSphericalRepresentation, AltAz, |
| 25 | + BaseCoordinateFrame, FrameAttribute, |
| 26 | + frame_transform_graph) |
25 | 27 | from ...coordinates import Latitude, EarthLocation |
26 | 28 | from ...time import Time |
27 | 29 | from ...utils import minversion |
@@ -1214,3 +1216,39 @@ def test_spherical_offsets(): |
1214 | 1216 | dra, ddec = i00.spherical_offsets_to(i1deg) |
1215 | 1217 | assert_allclose(dra, 1*u.deg) |
1216 | 1218 | assert_allclose(ddec, 1*u.deg) |
| 1219 | + |
| 1220 | +def test_frame_attr_changes(): |
| 1221 | + """ |
| 1222 | + This tests the case where a frame is added with a new frame attribute after |
| 1223 | + a SkyCoord has been created. This is necessary because SkyCoords get the |
| 1224 | + attributes set at creation time, but the set of attributes can change as |
| 1225 | + frames are added or removed from the transform graph. This makes sure that |
| 1226 | + everything continues to work consistently. |
| 1227 | + """ |
| 1228 | + sc_before = SkyCoord(1*u.deg, 2*u.deg, frame='icrs') |
| 1229 | + |
| 1230 | + assert 'fakeattr' not in dir(sc_before) |
| 1231 | + |
| 1232 | + class FakeFrame(BaseCoordinateFrame): |
| 1233 | + fakeattr = FrameAttribute() |
| 1234 | + |
| 1235 | + # doesn't matter what this does as long as it just puts the frame in the |
| 1236 | + # transform graph |
| 1237 | + transset = (ICRS, FakeFrame, lambda c,f:c) |
| 1238 | + frame_transform_graph.add_transform(*transset) |
| 1239 | + try: |
| 1240 | + assert 'fakeattr' in dir(sc_before) |
| 1241 | + assert sc_before.fakeattr is None |
| 1242 | + |
| 1243 | + sc_after1 = SkyCoord(1*u.deg, 2*u.deg, frame='icrs') |
| 1244 | + assert 'fakeattr' in dir(sc_after1) |
| 1245 | + assert sc_after1.fakeattr is None |
| 1246 | + |
| 1247 | + sc_after2 = SkyCoord(1*u.deg, 2*u.deg, frame='icrs', fakeattr=1) |
| 1248 | + assert sc_after2.fakeattr == 1 |
| 1249 | + finally: |
| 1250 | + frame_transform_graph.remove_transform(*transset) |
| 1251 | + |
| 1252 | + assert 'fakeattr' not in dir(sc_before) |
| 1253 | + assert 'fakeattr' not in dir(sc_after1) |
| 1254 | + assert 'fakeattr' not in dir(sc_after2) |
0 commit comments