class TestPlotWindow(TestCaseQt): """Base class for tests of PlotWindow.""" def setUp(self): super(TestPlotWindow, self).setUp() self.plot = PlotWindow() self.plot.show() self.qWaitForWindowExposed(self.plot) def tearDown(self): self.plot.setAttribute(qt.Qt.WA_DeleteOnClose) self.plot.close() del self.plot super(TestPlotWindow, self).tearDown() def testActions(self): """Test the actions QToolButtons""" self.plot.setLimits(1, 100, 1, 100) checkList = [ # QAction, Plot state getter (self.plot.xAxisAutoScaleAction, self.plot.getXAxis().isAutoScale), (self.plot.yAxisAutoScaleAction, self.plot.getYAxis().isAutoScale), (self.plot.xAxisLogarithmicAction, self.plot.getXAxis()._isLogarithmic), (self.plot.yAxisLogarithmicAction, self.plot.getYAxis()._isLogarithmic), (self.plot.gridAction, self.plot.getGraphGrid), ] for action, getter in checkList: self.mouseMove(self.plot) initialState = getter() toolButton = getQToolButtonFromAction(action) self.assertIsNot(toolButton, None) self.mouseClick(toolButton, qt.Qt.LeftButton) self.assertNotEqual(getter(), initialState, msg='"%s" state not changed' % action.text()) self.mouseClick(toolButton, qt.Qt.LeftButton) self.assertEqual(getter(), initialState, msg='"%s" state not changed' % action.text()) # Trigger a zoom reset self.mouseMove(self.plot) resetZoomAction = self.plot.resetZoomAction toolButton = getQToolButtonFromAction(resetZoomAction) self.assertIsNot(toolButton, None) self.mouseClick(toolButton, qt.Qt.LeftButton) def testToolAspectRatio(self): self.plot.toolBar() self.plot.keepDataAspectRatioButton.keepDataAspectRatio() self.assertTrue(self.plot.isKeepDataAspectRatio()) self.plot.keepDataAspectRatioButton.dontKeepDataAspectRatio() self.assertFalse(self.plot.isKeepDataAspectRatio()) def testToolYAxisOrigin(self): self.plot.toolBar() self.plot.yAxisInvertedButton.setYAxisUpward() self.assertFalse(self.plot.getYAxis().isInverted()) self.plot.yAxisInvertedButton.setYAxisDownward() self.assertTrue(self.plot.getYAxis().isInverted()) def testColormapAutoscaleCache(self): # Test that the min/max cache is not computed twice old = Colormap._computeAutoscaleRange self._count = 0 def _computeAutoscaleRange(colormap, data): self._count = self._count + 1 return 10, 20 Colormap._computeAutoscaleRange = _computeAutoscaleRange try: colormap = Colormap(name='red') self.plot.setVisible(True) # Add an image data = numpy.arange(8**2).reshape(8, 8) self.plot.addImage(data, legend="foo", colormap=colormap) self.plot.setActiveImage("foo") # Use the colorbar self.plot.getColorBarWidget().setVisible(True) self.qWait(50) # Remove and add again the same item image = self.plot.getImage("foo") self.plot.removeImage("foo") self.plot._add(image) self.qWait(50) finally: Colormap._computeAutoscaleRange = old self.assertEqual(self._count, 1) del self._count