Skip to content

Commit

Permalink
Use PlotWidgetTestCase to ensure widget closing cleanly
Browse files Browse the repository at this point in the history
  • Loading branch information
t20100 committed Jun 18, 2024
1 parent a15bf98 commit 9adf0e8
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions src/silx/gui/plot/test/testPixelIntensityHistoAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,30 @@
import numpy

from silx.utils.testutils import ParametricTestCase
from silx.gui.utils.testutils import TestCaseQt, getQToolButtonFromAction
from silx.gui.utils.testutils import getQToolButtonFromAction
from silx.gui import qt
from silx.gui.plot import Plot2D
from .utils import PlotWidgetTestCase


class TestPixelIntensitiesHisto(TestCaseQt, ParametricTestCase):
class TestPixelIntensitiesHisto(PlotWidgetTestCase, ParametricTestCase):
"""Tests for PixelIntensitiesHistoAction widget."""

def _createPlot(self):
return Plot2D()

def setUp(self):
super(TestPixelIntensitiesHisto, self).setUp()
self.image = numpy.random.rand(10, 10)
self.plotImage = Plot2D()
self.plotImage.getIntensityHistogramAction().setVisible(True)

def tearDown(self):
del self.plotImage
self.qapp.processEvents()
super(TestPixelIntensitiesHisto, self).tearDown()
self.plot.getIntensityHistogramAction().setVisible(True)

def testShowAndHide(self):
"""Simple test that the plot is showing and hiding when activating the
action"""
self.plotImage.addImage(self.image, origin=(0, 0), legend="sino")
self.plotImage.show()
self.plot.addImage(self.image, origin=(0, 0), legend="sino")
self.plot.show()

histoAction = self.plotImage.getIntensityHistogramAction()
histoAction = self.plot.getIntensityHistogramAction()

# test the pixel intensity diagram is showing
button = getQToolButtonFromAction(histoAction)
Expand All @@ -67,7 +65,7 @@ def testShowAndHide(self):
self.assertTrue(histoAction.getHistogramWidget().isVisible())

# test the pixel intensity diagram is hiding
self.plotImage.activateWindow()
self.plot.activateWindow()
self.qapp.processEvents()
self.mouseMove(button)
self.mouseClick(button, qt.Qt.LeftButton)
Expand All @@ -84,15 +82,15 @@ def testImageFormatInput(self):
numpy.float32,
numpy.float64,
]
self.plotImage.addImage(self.image, origin=(0, 0), legend="sino")
self.plotImage.show()
button = getQToolButtonFromAction(self.plotImage.getIntensityHistogramAction())
self.plot.addImage(self.image, origin=(0, 0), legend="sino")
self.plot.show()
button = getQToolButtonFromAction(self.plot.getIntensityHistogramAction())
self.mouseMove(button)
self.mouseClick(button, qt.Qt.LeftButton)
self.qapp.processEvents()
for typeToTest in typesToTest:
with self.subTest(typeToTest=typeToTest):
self.plotImage.addImage(
self.plot.addImage(
self.image.astype(typeToTest), origin=(0, 0), legend="sino"
)

Expand All @@ -101,10 +99,10 @@ def testScatter(self):
xx = numpy.arange(10)
yy = numpy.arange(10)
value = numpy.sin(xx)
self.plotImage.addScatter(xx, yy, value)
self.plotImage.show()
self.plot.addScatter(xx, yy, value)
self.plot.show()

histoAction = self.plotImage.getIntensityHistogramAction()
histoAction = self.plot.getIntensityHistogramAction()

# test the pixel intensity diagram is showing
button = getQToolButtonFromAction(histoAction)
Expand All @@ -123,10 +121,10 @@ def testChangeItem(self):
xx = numpy.arange(10)
yy = numpy.arange(10)
value = numpy.sin(xx)
self.plotImage.addScatter(xx, yy, value)
self.plotImage.show()
self.plot.addScatter(xx, yy, value)
self.plot.show()

histoAction = self.plotImage.getIntensityHistogramAction()
histoAction = self.plot.getIntensityHistogramAction()

# test the pixel intensity diagram is showing
button = getQToolButtonFromAction(histoAction)
Expand All @@ -142,7 +140,7 @@ def testChangeItem(self):
data1 = items[0].getValueData(copy=False)

# Set another item to the plot
self.plotImage.addImage(self.image, origin=(0, 0), legend="sino")
self.plot.addImage(self.image, origin=(0, 0), legend="sino")
self.qapp.processEvents()
data2 = items[0].getValueData(copy=False)

Expand Down

0 comments on commit 9adf0e8

Please sign in to comment.