Skip to content

Commit

Permalink
TST: Stop using roundtrip_object
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim committed Mar 16, 2023
1 parent bd2a7bd commit 3ea7274
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions specutils/io/asdf/tags/tests/test_spectra.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,35 +18,52 @@ 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
# equality comparison (assert_spectralaxis_equal)
# 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()}

0 comments on commit 3ea7274

Please sign in to comment.