diff --git a/specutils/io/asdf/tags/tests/test_spectra.py b/specutils/io/asdf/tags/tests/test_spectra.py index 30d754dc0..23d80d0b7 100644 --- a/specutils/io/asdf/tags/tests/test_spectra.py +++ b/specutils/io/asdf/tags/tests/test_spectra.py @@ -1,7 +1,6 @@ import asdf import numpy as np import pytest -from asdf.testing.helpers import roundtrip_object from astropy import units as u from astropy.coordinates import FK5 from astropy.nddata import StdDevUncertainty @@ -19,13 +18,20 @@ def create_spectrum1d(xmin, xmax, uncertainty=None): @pytest.mark.parametrize('uncertainty', [False, True]) -def test_asdf_spectrum1d(uncertainty): +def test_asdf_spectrum1d(tmp_path, uncertainty): + file_path = tmp_path / "test.asdf" spectrum = create_spectrum1d(5100, 5300, uncertainty=uncertainty) - assert_spectrum1d_equal(spectrum, roundtrip_object(spectrum)) + with asdf.AsdfFile() as af: + af["spectrum"] = spectrum + af.write_to(file_path) + + with asdf.open(file_path) as af: + assert_spectrum1d_equal(af["spectrum"], spectrum) @pytest.mark.xfail -def test_asdf_spectralaxis(): +def test_asdf_spectralaxis(tmp_path): + file_path = tmp_path / "test.asdf" wavelengths = np.arange(5100, 5300) * u.AA spectral_axis = SpectralAxis(wavelengths, bin_specification="edges") # There is no implemented asdf type for SpectralAxis and no defined @@ -33,21 +39,31 @@ def test_asdf_spectralaxis(): # per the comment https://github.com/astropy/specutils/pull/645#issuecomment-614271632 ; # the issue is that SpectralAxis roundtrips as SpectralCoord # so the types differ. - rt = roundtrip_object(spectral_axis) - assert type(rt) == type(spectral_axis) + with asdf.AsdfFile() as af: + af["spectral_axis"] = spectral_axis + af.write_to(file_path) + + with asdf.open(file_path) as af: + assert type(af["spectral_axis"]) == type(spectral_axis) -def test_asdf_spectrumlist(): +def test_asdf_spectrumlist(tmp_path): + file_path = tmp_path / "test.asdf" spectra = SpectrumList([ create_spectrum1d(5100, 5300), create_spectrum1d(5000, 5500), create_spectrum1d(0, 100), create_spectrum1d(1, 5) ]) - assert_spectrumlist_equal(spectra, roundtrip_object(spectra)) + with asdf.AsdfFile() as af: + af["spectrum_list"] = spectra + af.write_to(file_path) + + with asdf.open(file_path) as af: + assert_spectrumlist_equal(af["spectrum_list"], spectra) def test_asdf_url_mapper(): """Make sure specutils ASDF extension url_mapping does not interfere with astropy schemas.""" - af = asdf.AsdfFile() - af.tree = {'frame': FK5()} + with asdf.AsdfFile() as af: + af.tree = {'frame': FK5()}