Skip to content

Commit ced5227

Browse files
committed
Fix tests
1 parent 47c8e0c commit ced5227

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

asdf_astropy/converters/wcs/tests/test_highlevelwcswrapper.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from astropy.wcs.wcsapi.wrappers.sliced_wcs import SlicedLowLevelWCS
77
from pytest_lazy_fixtures import lf
88

9-
from asdf_astropy.testing.helpers import assert_wcs_equal
9+
from asdf_astropy.testing.helpers import assert_gwcs_equal, assert_wcs_equal
1010

1111

1212
@pytest.fixture
@@ -26,9 +26,22 @@ def test_hllwcs_serialization(hl_wcs, tmp_path):
2626
af["hl_wcs"] = hl_wcs
2727
af.write_to(file_path)
2828

29+
ll_wcs = hl_wcs._low_level_wcs
2930
with asdf.open(file_path) as af:
3031
loaded_hl_wcs = af["hl_wcs"]
31-
if isinstance(loaded_hl_wcs, WCS):
32-
assert_wcs_equal(hl_wcs._low_level_wcs, loaded_hl_wcs._low_level_wcs)
33-
elif isinstance(loaded_hl_wcs, gwcs.WCS):
34-
assert loaded_hl_wcs == hl_wcs
32+
loaded_ll_wcs = loaded_hl_wcs._low_level_wcs
33+
34+
# Unwrap the SlicedLowLevelWCS
35+
if isinstance(loaded_ll_wcs, SlicedLowLevelWCS):
36+
assert isinstance(ll_wcs, SlicedLowLevelWCS)
37+
assert loaded_ll_wcs._slices_array == ll_wcs._slices_array
38+
loaded_ll_wcs = loaded_ll_wcs._wcs
39+
ll_wcs = ll_wcs._wcs
40+
41+
if isinstance(loaded_ll_wcs, WCS):
42+
assert_wcs_equal(ll_wcs, loaded_ll_wcs)
43+
elif isinstance(loaded_ll_wcs, gwcs.WCS):
44+
assert_gwcs_equal(loaded_ll_wcs, ll_wcs)
45+
else:
46+
msg = f"Loaded an unexpected type: {type(loaded_ll_wcs)}"
47+
raise TypeError(msg)

asdf_astropy/testing/helpers.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,34 @@ def assert_wcs_roundtrip(wcs, tmp_path, version=None):
271271

272272
with asdf.open(path) as af:
273273
assert_wcs_equal(wcs, af["wcs"])
274+
275+
276+
def _assert_gwcs_frame_equal(a, b):
277+
__tracebackhide__ = True
278+
279+
import gwcs.coordinate_frames as cf
280+
281+
assert type(a) is type(b)
282+
283+
if a is None:
284+
return None
285+
286+
if not isinstance(a, cf.CoordinateFrame):
287+
return a == b
288+
289+
assert a.name == b.name # nosec
290+
if not isinstance(a, cf.EmptyFrame):
291+
assert a.axes_order == b.axes_order # nosec
292+
assert a.axes_names == b.axes_names # nosec
293+
assert a.unit == b.unit # nosec
294+
assert a.reference_frame == b.reference_frame # nosec
295+
return None
296+
297+
298+
def assert_gwcs_equal(a, b):
299+
assert a.name == b.name # nosec
300+
assert a.pixel_shape == b.pixel_shape
301+
assert len(a.available_frames) == len(b.available_frames) # nosec
302+
for a_step, b_step in zip(a.pipeline, b.pipeline, strict=False):
303+
_assert_gwcs_frame_equal(a_step.frame, b_step.frame)
304+
assert_model_equal(a_step.transform, b_step.transform)

0 commit comments

Comments
 (0)