Skip to content

Commit

Permalink
change asdf.tests.helpers to asdf.testing.helpers
Browse files Browse the repository at this point in the history
asdf.tests.helpers will be deprecated:
astropy/asdf-astropy#168

The uses in specutils are limited to assert_roundtrip_tree

A similar roundtrip_object exists in asdf.testing.helpers
which serializes then deserializes an object (without asserting
equality). This commit replaces the uses of assert_roundtrip_tree
with roundtrip_object and uses the equality comparison built into
the custom asdf types implemented in this module to check for
equality. These equality comparisons are the same checks that
were used internally by assert_roundtrip_tree.
  • Loading branch information
braingram committed Feb 23, 2023
1 parent ca3153f commit a3513e7
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions specutils/io/asdf/tags/tests/test_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
from astropy.coordinates import FK5 # noqa: E402
from astropy.nddata import StdDevUncertainty # noqa: E402

from asdf.tests.helpers import assert_roundtrip_tree # noqa: E402
from asdf.testing.helpers import roundtrip_object # noqa: E402
import asdf # noqa: E402

from specutils import Spectrum1D, SpectrumList, SpectralAxis # noqa: E402
from specutils.io.asdf.tags.spectra import Spectrum1DType, SpectrumListType


def create_spectrum1d(xmin, xmax, uncertainty=None):
Expand All @@ -26,27 +27,26 @@ def create_spectrum1d(xmin, xmax, uncertainty=None):
def test_asdf_spectrum1d(tmpdir):

spectrum = create_spectrum1d(5100, 5300)
Spectrum1DType.assert_equal(spectrum, roundtrip_object(spectrum))

tree = dict(spectrum=spectrum)
assert_roundtrip_tree(tree, tmpdir)


@pytest.mark.filterwarnings('ignore:ASDF functionality for astropy is being moved out')
def test_asdf_spectrum1d_uncertainty(tmpdir):

spectrum = create_spectrum1d(5100, 5300, uncertainty=True)
Spectrum1DType.assert_equal(spectrum, roundtrip_object(spectrum))

tree = dict(spectrum=spectrum)
assert_roundtrip_tree(tree, tmpdir)


@pytest.mark.xfail
def test_asdf_spectralaxis(tmpdir):

wavelengths = np.arange(5100, 5300) * 0.1 * u.nm
spectral_axis = SpectralAxis(wavelengths, bin_specification="edges")
tree = dict(spectral_axis=spectral_axis)
assert_roundtrip_tree(tree, tmpdir)
# there is no implemented asdf type for SpectralAxis and no defined
# equality comparison (assert_equal)
assert roundtrip_object(spectral_axis) == spectrum_axis


@pytest.mark.filterwarnings('ignore:ASDF functionality for astropy is being moved out')
Expand All @@ -58,9 +58,8 @@ def test_asdf_spectrumlist(tmpdir):
create_spectrum1d(0, 100),
create_spectrum1d(1, 5)
])
SpectrumListType.assert_equal(spectra, roundtrip_object(spectra))

tree = dict(spectra=spectra)
assert_roundtrip_tree(tree, tmpdir)


@pytest.mark.filterwarnings("error::UserWarning")
Expand Down

0 comments on commit a3513e7

Please sign in to comment.