Skip to content

Commit

Permalink
Merge pull request #21 from astrofrog/fix-tests
Browse files Browse the repository at this point in the history
Fix test suite
  • Loading branch information
astrofrog authored Jul 15, 2024
2 parents ce02bbd + ea5f82d commit e259682
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 52 deletions.
8 changes: 5 additions & 3 deletions glue_qt/app/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions glue_qt/utils/tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
12 changes: 8 additions & 4 deletions glue_qt/viewers/custom/custom_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
43 changes: 0 additions & 43 deletions glue_qt/viewers/image/tests/test_data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -935,45 +934,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() == ""

0 comments on commit e259682

Please sign in to comment.