Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Dec 20, 2022
1 parent da79f65 commit aaf0021
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
32 changes: 32 additions & 0 deletions jdaviz/configs/default/plugins/model_fitting/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,35 @@ def test_subset_masks(cubeviz_helper, spectrum1d_cube_larger):

# Check that both masks are applied correctly
assert np.all(data.mask == (expected_spectral_mask | expected_spatial_mask))


def test_invalid_subset(specviz_helper, spectrum1d):
# 6000-8000
specviz_helper.load_spectrum(spectrum1d, data_label="right_spectrum")

# 5000-7000
sp2 = Spectrum1D(spectral_axis=spectrum1d.spectral_axis - 1000*spectrum1d.spectral_axis.unit,
flux=spectrum1d.flux * 1.25)
specviz_helper.load_spectrum(sp2, data_label="left_spectrum")

# apply subset that overlaps on left_spectrum, but not right_spectrum
# NOTE: using a subset that overlaps the right_spectrum (reference) results in errors when
# retrieving the subset (https://github.com/spacetelescope/jdaviz/issues/1868)
specviz_helper.app.get_viewer('spectrum-viewer').apply_roi(XRangeROI(5000, 6000))

plugin = specviz_helper.plugins['Model Fitting']
plugin.create_model_component('Linear1D')

plugin.dataset = 'right_spectrum'
assert plugin.dataset == 'right_spectrum'
assert plugin.spectral_subset == 'Entire Spectrum'
assert plugin._obj.spectral_subset_valid

plugin.spectral_subset = 'Subset 1'
assert not plugin._obj.spectral_subset_valid

with pytest.raises(ValueError, match='spectral subset is outside data range'):
plugin.calculate_fit()

plugin.dataset = 'left_spectrum'
assert plugin._obj.spectral_subset_valid
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from glue.core.roi import XRangeROI
from glue.core.edit_subset_mode import NewMode
from regions import RectanglePixelRegion, PixCoord
from specutils import Spectrum1D

from jdaviz.configs.specviz.plugins.line_analysis.line_analysis import _coerce_unit
from jdaviz.core.events import LineIdentifyMessage
Expand Down Expand Up @@ -401,3 +402,33 @@ def test_subset_changed(specviz_helper, spectrum1d):

# Values have not yet been validated
np.testing.assert_allclose(float(plugin.results[0]['result']), 2.153181e-13, atol=1e-15)


def test_invalid_subset(specviz_helper, spectrum1d):
# 6000-8000
specviz_helper.load_spectrum(spectrum1d, data_label="right_spectrum")

# 5000-7000
sp2 = Spectrum1D(spectral_axis=spectrum1d.spectral_axis - 1000*spectrum1d.spectral_axis.unit,
flux=spectrum1d.flux * 1.25)
specviz_helper.load_spectrum(sp2, data_label="left_spectrum")

# apply subset that overlaps on left_spectrum, but not right_spectrum
# NOTE: using a subset that overlaps the right_spectrum (reference) results in errors when
# retrieving the subset (https://github.com/spacetelescope/jdaviz/issues/1868)
specviz_helper.app.get_viewer('spectrum-viewer').apply_roi(XRangeROI(5000, 6000))

plugin = specviz_helper.plugins['Line Analysis']
plugin.dataset = 'right_spectrum'
assert plugin.dataset == 'right_spectrum'
assert plugin.spectral_subset == 'Entire Spectrum'
assert plugin._obj.spectral_subset_valid

plugin.spectral_subset = 'Subset 1'
assert not plugin._obj.spectral_subset_valid

with pytest.raises(ValueError, match='spectral subset is outside data range'):
plugin.get_results()

plugin.dataset = 'left_spectrum'
assert plugin._obj.spectral_subset_valid

0 comments on commit aaf0021

Please sign in to comment.