From 6c0992454433050f7ea569adc4ba5a0a5b2564d3 Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:00:07 -0400 Subject: [PATCH] Add test similar to lcviz (#2747) * Add test similar to lcviz * Two tests need to run --- jdaviz/configs/specviz/tests/test_viewers.py | 44 ++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/jdaviz/configs/specviz/tests/test_viewers.py b/jdaviz/configs/specviz/tests/test_viewers.py index 883ebc86b7..80928d4ad9 100644 --- a/jdaviz/configs/specviz/tests/test_viewers.py +++ b/jdaviz/configs/specviz/tests/test_viewers.py @@ -24,3 +24,47 @@ def test_spectrum_viewer_axis_labels(specviz_helper, input_unit, y_axis_label): label = specviz_helper.app.get_viewer_by_id('specviz-0').figure.axes[1].label assert (y_axis_label in label) + + +class TestResetLimitsTwoTests: + """See https://github.com/spacetelescope/lcviz/pull/93""" + + def test_reset_limits_01(self, specviz_helper, spectrum1d): + """This should run first.""" + specviz_helper.load_data(spectrum1d) + sv = specviz_helper.app.get_viewer("spectrum-viewer") + + orig_xlims = (sv.state.x_min, sv.state.x_max) + orig_ylims = (sv.state.y_min, sv.state.y_max) + # set xmin and ymin to midpoints + new_xmin = (sv.state.x_min + sv.state.x_max) * 0.5 + new_ymin = (sv.state.y_min + sv.state.y_max) * 0.5 + sv.state.x_min = new_xmin + sv.state.y_min = new_ymin + + sv.state._reset_x_limits() + assert sv.state.x_min == orig_xlims[0] + assert sv.state.y_min == new_ymin + + sv.state._reset_y_limits() + assert sv.state.y_min == orig_ylims[0] + + def test_reset_limits_02(self, specviz_helper, spectrum1d_nm): + """This should run second and see if first polutes it.""" + specviz_helper.load_data(spectrum1d_nm) + sv = specviz_helper.app.get_viewer("spectrum-viewer") + + orig_xlims = (sv.state.x_min, sv.state.x_max) + orig_ylims = (sv.state.y_min, sv.state.y_max) + # set xmin and ymin to midpoints + new_xmin = (sv.state.x_min + sv.state.x_max) * 0.5 + new_ymin = (sv.state.y_min + sv.state.y_max) * 0.5 + sv.state.x_min = new_xmin + sv.state.y_min = new_ymin + + sv.state._reset_x_limits() + assert sv.state.x_min == orig_xlims[0] + assert sv.state.y_min == new_ymin + + sv.state._reset_y_limits() + assert sv.state.y_min == orig_ylims[0]