Changeset c4e5400 in sasview for src/sas/qtgui/UnitTesting/PlotterBaseTest.py
- Timestamp:
- Dec 12, 2016 5:21:03 AM (8 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 27313b7
- Parents:
- 3b7b218
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/UnitTesting/PlotterBaseTest.py
r3b7b218 rc4e5400 1 1 import sys 2 2 import unittest 3 from mock import MagicMock3 from mock import patch, MagicMock 4 4 5 5 from PyQt4 import QtGui … … 15 15 #import sas.qtgui.GuiUtils as GuiUtils 16 16 from sas.qtgui.GuiUtils import * 17 import sas.qtgui.PlotHelper as PlotHelper 17 18 18 19 # Tested module … … 30 31 def perspective(self): 31 32 return MyPerspective() 32 33 #PlotterBase.PlotterBase.updatePlotHelper = MagicMock()34 #self.plotter = PlotterBase.PlotterBase(None, manager=dummy_manager())35 33 36 34 PlotterBase.PlotterBase.contextMenuQuickPlot = MagicMock() … … 64 62 def testContextMenu(self): 65 63 ''' Test the default context menu ''' 66 pass 67 68 def testContextMenuQuickPlot(self): 69 ''' Test the default quick context menu ''' 70 pass 64 with self.assertRaises(NotImplementedError): 65 self.plotter.contextMenu() 71 66 72 67 def testClean(self): 73 68 ''' test the graph cleanup ''' 74 pass 69 self.plotter.figure.delaxes = MagicMock() 70 self.plotter.clean() 71 self.assertTrue(self.plotter.figure.delaxes.called) 75 72 76 73 def testPlot(self): … … 79 76 self.plotter.plot() 80 77 81 def testOnCloseEvent(self):78 def notestOnCloseEvent(self): 82 79 ''' test the plotter close behaviour ''' 83 pass 80 PlotHelper.deletePlot = MagicMock() 81 self.plotter.closeEvent(None) 82 self.assertTrue(PlotHelper.deletePlot.called) 84 83 85 84 def testOnImageSave(self): 86 85 ''' test the workspace save ''' 87 pass 86 self.plotter.toolbar.save_figure = MagicMock() 87 self.plotter.onImageSave() 88 self.assertTrue(self.plotter.toolbar.save_figure.called) 88 89 89 90 def testOnImagePrint(self): 90 91 ''' test the workspace print ''' 91 pass 92 QtGui.QPainter.end = MagicMock() 93 QtGui.QLabel.render = MagicMock() 92 94 93 def tesOonClipboardCopy(self): 94 ''' test the workspace copy ''' 95 pass 95 # First, let's cancel printing 96 QtGui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Rejected) 97 self.plotter.onImagePrint() 98 self.assertFalse(QtGui.QPainter.end.called) 99 self.assertFalse(QtGui.QLabel.render.called) 100 101 # Let's print now 102 QtGui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted) 103 self.plotter.onImagePrint() 104 self.assertTrue(QtGui.QPainter.end.called) 105 self.assertTrue(QtGui.QLabel.render.called) 106 107 def testOnClipboardCopy(self): 108 ''' test the workspace screen copy ''' 109 QtGui.QClipboard.setPixmap = MagicMock() 110 self.plotter.onClipboardCopy() 111 self.assertTrue(QtGui.QClipboard.setPixmap.called) 96 112 97 113 def testOnGridToggle(self): 98 114 ''' test toggling the grid lines ''' 99 pass 115 # Check the toggle 116 orig_toggle = self.plotter.grid_on 117 118 FigureCanvas.draw_idle = MagicMock() 119 self.plotter.onGridToggle() 120 121 self.assertTrue(FigureCanvas.draw_idle.called) 122 self.assertTrue(self.plotter.grid_on != orig_toggle) 123 124 def testDefaultContextMenu(self): 125 """ Test the right click default menu """ 126 127 self.plotter.defaultContextMenu() 128 129 actions = self.plotter.contextMenu.actions() 130 self.assertEqual(len(actions), 4) 131 132 # Trigger Save Image and make sure the method is called 133 self.assertEqual(actions[0].text(), "Save Image") 134 self.plotter.toolbar.save_figure = MagicMock() 135 actions[0].trigger() 136 self.assertTrue(self.plotter.toolbar.save_figure.called) 137 138 # Trigger Print Image and make sure the method is called 139 self.assertEqual(actions[1].text(), "Print Image") 140 QtGui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Rejected) 141 actions[1].trigger() 142 self.assertTrue(QtGui.QPrintDialog.exec_.called) 143 144 # Trigger Copy to Clipboard and make sure the method is called 145 self.assertEqual(actions[2].text(), "Copy to Clipboard") 146 147 # Spy on cliboard's dataChanged() signal 148 self.clipboard_called = False 149 def done(): 150 self.clipboard_called = True 151 QtCore.QObject.connect(app.clipboard(), QtCore.SIGNAL("dataChanged()"), done) 152 actions[2].trigger() 153 QtGui.qApp.processEvents() 154 # Make sure clipboard got updated. 155 self.assertTrue(self.clipboard_called) 100 156 101 157
Note: See TracChangeset
for help on using the changeset viewer.