From 8fa75cd165f8d5910a72281c184801c07a5a2f5d Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Fri, 12 Jul 2024 13:48:50 +0100 Subject: [PATCH 1/4] Fix custom viewer for case where Matplotlib limits are initially set to inf --- glue_qt/viewers/custom/custom_viewer.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/glue_qt/viewers/custom/custom_viewer.py b/glue_qt/viewers/custom/custom_viewer.py index 7ed9f963..ec61f389 100644 --- a/glue_qt/viewers/custom/custom_viewer.py +++ b/glue_qt/viewers/custom/custom_viewer.py @@ -765,10 +765,14 @@ def add_data(self, data): super(CustomMatplotlibDataViewer, self).add_data(data) if (self.state.x_min == 0 and self.state.x_max == 1 and self.state.y_min == 0 and self.state.y_max == 1): with ignore_callback(self.state, "x_min", "x_max", "y_min", "y_max"): - self.state.x_min = self.axes.dataLim.xmin - self.state.x_max = self.axes.dataLim.xmax - self.state.y_min = self.axes.dataLim.ymin - self.state.y_max = self.axes.dataLim.ymax + if not np.isinf(self.axes.dataLim.xmin): + self.state.x_min = self.axes.dataLim.xmin + if not np.isinf(self.axes.dataLim.xmax): + self.state.x_max = self.axes.dataLim.xmax + if not np.isinf(self.axes.dataLim.ymin): + self.state.y_min = self.axes.dataLim.ymin + if not np.isinf(self.axes.dataLim.ymax): + self.state.y_max = self.axes.dataLim.ymax self.limits_to_mpl() return True From fc97440efb030137e9a3dd176b207deef946c6ce Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Fri, 12 Jul 2024 13:50:02 +0100 Subject: [PATCH 2/4] Fix mock asserts --- glue_qt/app/tests/test_application.py | 8 +++++--- glue_qt/utils/tests/test_decorators.py | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/glue_qt/app/tests/test_application.py b/glue_qt/app/tests/test_application.py index b981e566..6d76ede7 100644 --- a/glue_qt/app/tests/test_application.py +++ b/glue_qt/app/tests/test_application.py @@ -172,10 +172,12 @@ def test_new_data_defaults(self): d1 = Data(x=np.array([1, 2, 3])) self.app.choose_new_data_viewer(data=d1) + assert pc.call_count == 1 args, kwargs = pc.call_args assert kwargs['default'] is ScatterViewer self.app.choose_new_data_viewer(data=d2) + assert pc.call_count == 2 args, kwargs = pc.call_args assert kwargs['default'] is ImageViewer @@ -195,7 +197,7 @@ def test_drop_load_data(self): e.mimeData.return_value = m self.app.dropEvent(e) - assert load_data.called_once_with('test.fits') + load_data.assert_called_once_with(['test.fits']) assert load_session.call_count == 0 load_data.reset_mock() @@ -204,7 +206,7 @@ def test_drop_load_data(self): m.setUrls([QtCore.QUrl('test1.fits'), QtCore.QUrl('test2.fits')]) e.mimeData.return_value = m self.app.dropEvent(e) - assert load_data.called_once_with(['test1.fits', 'test2.fits']) + load_data.assert_called_once_with(['test1.fits', 'test2.fits']) assert load_session.call_count == 0 load_data.reset_mock() @@ -214,7 +216,7 @@ def test_drop_load_data(self): e.mimeData.return_value = m self.app.dropEvent(e) assert load_data.call_count == 0 - assert load_session.called_once_with(['test.glu']) + load_session.assert_called_once_with('test.glu') load_data.reset_mock() diff --git a/glue_qt/utils/tests/test_decorators.py b/glue_qt/utils/tests/test_decorators.py index 1a3a2d1f..861b9dd8 100644 --- a/glue_qt/utils/tests/test_decorators.py +++ b/glue_qt/utils/tests/test_decorators.py @@ -71,7 +71,7 @@ def decorated_working_function(): with patch('qtpy.QtWidgets.QMessageBox') as mb: decorated_failing_function() assert mb.call_args[0][2] == 'An error occurred\nDialog failure' - assert exit.called_once_with(1) + exit.assert_called_once_with(1) with patch('sys.exit') as exit: with patch('qtpy.QtWidgets.QMessageBox') as mb: @@ -86,7 +86,7 @@ def decorated_working_function(): with die_on_error('An error occurred'): failing_function() assert mb.call_args[0][2] == 'An error occurred\nDialog failure' - assert exit.called_once_with(1) + exit.assert_called_once_with(1) with patch('sys.exit') as exit: with patch('qtpy.QtWidgets.QMessageBox') as mb: From 0bc05794d5a509f9c44808e42ddc634400b8d87e Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Fri, 12 Jul 2024 14:03:35 +0100 Subject: [PATCH 3/4] Remove test moved to glue-core --- .../viewers/image/tests/test_data_viewer.py | 42 ------------------- 1 file changed, 42 deletions(-) diff --git a/glue_qt/viewers/image/tests/test_data_viewer.py b/glue_qt/viewers/image/tests/test_data_viewer.py index cebd10d7..75997195 100644 --- a/glue_qt/viewers/image/tests/test_data_viewer.py +++ b/glue_qt/viewers/image/tests/test_data_viewer.py @@ -935,45 +935,3 @@ def test_session_rgb_back_compat(self, protocol): assert layer_state.color == 'b' ga.close() - - -def test_indexed_data(capsys): - - # Make sure that the image viewer works properly with IndexedData objects - - data_4d = Data(label='hypercube_wcs', - x=np.random.random((3, 5, 4, 3)), - coords=WCS(naxis=4)) - - data_2d = IndexedData(data_4d, (2, None, 3, None)) - - application = GlueApplication() - - session = application.session - - hub = session.hub - - data_collection = session.data_collection - data_collection.append(data_4d) - data_collection.append(data_2d) - - viewer = application.new_data_viewer(ImageViewer) - viewer.add_data(data_2d) - - assert viewer.state.x_att is data_2d.pixel_component_ids[1] - assert viewer.state.y_att is data_2d.pixel_component_ids[0] - assert viewer.state.x_att_world is data_2d.world_component_ids[1] - assert viewer.state.y_att_world is data_2d.world_component_ids[0] - - process_events() - - application.close() - - # Some exceptions used to happen during callbacks, and these show up - # in stderr but don't interrupt the code, so we make sure here that - # nothing was printed to stdout nor stderr. - - out, err = capsys.readouterr() - - assert out.strip() == "" - assert err.strip() == "" From ea5f82d398e445b50debd5ba8c1047d761c864bc Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Mon, 15 Jul 2024 14:40:18 +0100 Subject: [PATCH 4/4] Remove unused import --- glue_qt/viewers/image/tests/test_data_viewer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/glue_qt/viewers/image/tests/test_data_viewer.py b/glue_qt/viewers/image/tests/test_data_viewer.py index 75997195..42a2a2d9 100644 --- a/glue_qt/viewers/image/tests/test_data_viewer.py +++ b/glue_qt/viewers/image/tests/test_data_viewer.py @@ -27,7 +27,6 @@ from glue.core.link_helpers import LinkSame from glue_qt.app import GlueApplication from glue.core.fixed_resolution_buffer import ARRAY_CACHE, PIXEL_CACHE -from glue.core.data_derived import IndexedData from glue_qt.tests.helpers import requires_pyqt from ..data_viewer import ImageViewer