Changeset 53c771e in sasview for src/sas/qtgui/Plotting/UnitTesting
- Timestamp:
- Nov 9, 2017 6:45:20 AM (7 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:
- dd150ef
- Parents:
- d6b8a1d
- git-author:
- Piotr Rozyczko <rozyczko@…> (11/08/17 07:22:45)
- git-committer:
- Piotr Rozyczko <rozyczko@…> (11/09/17 06:45:20)
- Location:
- src/sas/qtgui/Plotting/UnitTesting
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Plotting/UnitTesting/AddTextTest.py
r7fb471d r53c771e 3 3 from unittest.mock import MagicMock 4 4 5 from PyQt 4 import QtGui5 from PyQt5 import QtGui, QtWidgets 6 6 7 7 # set up import paths … … 11 11 from sas.qtgui.Plotting.AddText import AddText 12 12 13 if not Qt Gui.QApplication.instance():14 app = Qt Gui.QApplication(sys.argv)13 if not QtWidgets.QApplication.instance(): 14 app = QtWidgets.QApplication(sys.argv) 15 15 16 16 class AddTextTest(unittest.TestCase): … … 27 27 def testDefaults(self): 28 28 '''Test the GUI in its default state''' 29 self.assertIsInstance(self.widget, Qt Gui.QDialog)29 self.assertIsInstance(self.widget, QtWidgets.QDialog) 30 30 self.assertIsInstance(self.widget._font, QtGui.QFont) 31 31 self.assertEqual(self.widget._color, "black") … … 34 34 '''Test the QFontDialog output''' 35 35 font_1 = QtGui.QFont("Helvetica", 15) 36 Qt Gui.QFontDialog.getFont = MagicMock(return_value=(font_1, True))36 QtWidgets.QFontDialog.getFont = MagicMock(return_value=(font_1, True)) 37 37 # Call the method 38 38 self.widget.onFontChange(None) … … 42 42 # See that rejecting the dialog doesn't modify the font 43 43 font_2 = QtGui.QFont("Arial", 9) 44 Qt Gui.QFontDialog.getFont = MagicMock(return_value=(font_2, False))44 QtWidgets.QFontDialog.getFont = MagicMock(return_value=(font_2, False)) 45 45 # Call the method 46 46 self.widget.onFontChange(None) … … 51 51 ''' Test the QColorDialog output''' 52 52 new_color = QtGui.QColor("red") 53 Qt Gui.QColorDialog.getColor = MagicMock(return_value=new_color)53 QtWidgets.QColorDialog.getColor = MagicMock(return_value=new_color) 54 54 # Call the method 55 55 self.widget.onColorChange(None) -
src/sas/qtgui/Plotting/UnitTesting/BoxSumTest.py
r7fb471d r53c771e 3 3 from unittest.mock import MagicMock 4 4 5 from PyQt 4 import QtGui6 from PyQt 4import QtCore5 from PyQt5 import QtGui,QtWidgets 6 from PyQt5 import QtCore 7 7 8 8 # set up import paths … … 12 12 from sas.qtgui.Plotting.BoxSum import BoxSum 13 13 14 if not Qt Gui.QApplication.instance():15 app = Qt Gui.QApplication(sys.argv)14 if not QtWidgets.QApplication.instance(): 15 app = QtWidgets.QApplication(sys.argv) 16 16 17 17 class BoxSumTest(unittest.TestCase): … … 33 33 def testDefaults(self): 34 34 '''Test the GUI in its default state''' 35 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(0), Qt Gui.QLineEdit)36 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(1), Qt Gui.QLineEdit)37 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(2), Qt Gui.QLineEdit)38 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(3), Qt Gui.QLineEdit)39 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(4), Qt Gui.QLabel)40 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(5), Qt Gui.QLabel)41 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(6), Qt Gui.QLabel)42 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(7), Qt Gui.QLabel)43 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(8), Qt Gui.QLabel)35 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(0), QtWidgets.QLineEdit) 36 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(1), QtWidgets.QLineEdit) 37 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(2), QtWidgets.QLineEdit) 38 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(3), QtWidgets.QLineEdit) 39 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(4), QtWidgets.QLabel) 40 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(5), QtWidgets.QLabel) 41 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(6), QtWidgets.QLabel) 42 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(7), QtWidgets.QLabel) 43 self.assertIsInstance(self.widget.mapper.mappedWidgetAt(8), QtWidgets.QLabel) 44 44 45 45 -
src/sas/qtgui/Plotting/UnitTesting/ColorMapTest.py
r7fb471d r53c771e 3 3 import numpy 4 4 5 from PyQt 4 import QtGui5 from PyQt5 import QtGui, QtWidgets 6 6 from unittest.mock import MagicMock 7 7 import matplotlib as mpl … … 18 18 from sas.qtgui.Plotting.ColorMap import ColorMap 19 19 20 if not Qt Gui.QApplication.instance():21 app = Qt Gui.QApplication(sys.argv)20 if not QtWidgets.QApplication.instance(): 21 app = QtWidgets.QApplication(sys.argv) 22 22 23 23 class ColorMapTest(unittest.TestCase): … … 48 48 def testDefaults(self): 49 49 '''Test the GUI in its default state''' 50 self.assertIsInstance(self.widget, Qt Gui.QDialog)50 self.assertIsInstance(self.widget, QtWidgets.QDialog) 51 51 52 52 self.assertEqual(self.widget._cmap_orig, "jet") 53 self.assertEqual(len(self.widget.all_maps), 1 44)54 self.assertEqual(len(self.widget.maps), 72)55 self.assertEqual(len(self.widget.rmaps), 72)53 self.assertEqual(len(self.widget.all_maps), 160) 54 self.assertEqual(len(self.widget.maps), 80) 55 self.assertEqual(len(self.widget.rmaps), 80) 56 56 57 57 self.assertEqual(self.widget.lblWidth.text(), "0") … … 60 60 self.assertEqual(self.widget.lblStopRadius.text(), "-1") 61 61 self.assertFalse(self.widget.chkReverse.isChecked()) 62 self.assertEqual(self.widget.cbColorMap.count(), 72)63 self.assertEqual(self.widget.cbColorMap.currentIndex(), 6 0)62 self.assertEqual(self.widget.cbColorMap.count(), 80) 63 self.assertEqual(self.widget.cbColorMap.currentIndex(), 64) 64 64 65 65 # validators … … 70 70 self.assertEqual(self.widget.txtMinAmplitude.text(), "0") 71 71 self.assertEqual(self.widget.txtMaxAmplitude.text(), "100") 72 self.assertIsInstance(self.widget.slider, Qt Gui.QSlider)72 self.assertIsInstance(self.widget.slider, QtWidgets.QSlider) 73 73 74 74 def testOnReset(self): … … 111 111 112 112 # Check the combobox 113 self.assertEqual(self.widget.cbColorMap.currentIndex(), 5 5)113 self.assertEqual(self.widget.cbColorMap.currentIndex(), 59) 114 114 self.assertFalse(self.widget.chkReverse.isChecked()) 115 115 … … 118 118 self.widget.initMapCombobox() 119 119 # Check the combobox 120 self.assertEqual(self.widget.cbColorMap.currentIndex(), 56)120 self.assertEqual(self.widget.cbColorMap.currentIndex(), 60) 121 121 self.assertTrue(self.widget.chkReverse.isChecked()) 122 122 -
src/sas/qtgui/Plotting/UnitTesting/LinearFitTest.py
r7fb471d r53c771e 3 3 import numpy 4 4 5 from PyQt 4 import QtGui5 from PyQt5 import QtGui, QtWidgets 6 6 from unittest.mock import MagicMock 7 8 from UnitTesting.TestUtils import QtSignalSpy 7 9 8 10 # set up import paths … … 15 17 from sas.qtgui.Plotting.LinearFit import LinearFit 16 18 17 if not Qt Gui.QApplication.instance():18 app = Qt Gui.QApplication(sys.argv)19 if not QtWidgets.QApplication.instance(): 20 app = QtWidgets.QApplication(sys.argv) 19 21 20 22 class LinearFitTest(unittest.TestCase): … … 36 38 def testDefaults(self): 37 39 '''Test the GUI in its default state''' 38 self.assertIsInstance(self.widget, Qt Gui.QDialog)40 self.assertIsInstance(self.widget, QtWidgets.QDialog) 39 41 self.assertEqual(self.widget.windowTitle(), "Linear Fit") 40 42 self.assertEqual(self.widget.txtA.text(), "1") … … 48 50 '''Test the fitting wrapper ''' 49 51 # Catch the update signal 50 self.widget.parent.emit = MagicMock() 52 #self.widget.updatePlot.emit = MagicMock() 53 #self.widget.updatePlot.emit = MagicMock() 54 spy_update = QtSignalSpy(self.widget, self.widget.updatePlot) 51 55 52 56 # Set some initial values … … 57 61 # Run the fitting 58 62 self.widget.fit(None) 59 return_values = self.widget.parent.emit.call_args[0][1] 63 64 # Expected one spy instance 65 self.assertEqual(spy_update.count(), 1) 66 67 return_values = spy_update.called()[0]['args'][0] 60 68 # Compare 61 69 self.assertCountEqual(return_values[0], [1.0, 3.0]) … … 66 74 self.widget.x_is_log = True 67 75 self.widget.fit(None) 68 return_values = self.widget.parent.emit.call_args[0][1] 76 self.assertEqual(spy_update.count(), 2) 77 return_values = spy_update.called()[1]['args'][0] 69 78 # Compare 70 79 self.assertCountEqual(return_values[0], [1.0, 3.0]) -
src/sas/qtgui/Plotting/UnitTesting/PlotPropertiesTest.py
r7fb471d r53c771e 3 3 from unittest.mock import MagicMock 4 4 5 from PyQt 4 import QtGui5 from PyQt5 import QtGui, QtWidgets 6 6 7 7 # set up import paths … … 11 11 from sas.qtgui.Plotting.PlotProperties import PlotProperties 12 12 13 if not Qt Gui.QApplication.instance():14 app = Qt Gui.QApplication(sys.argv)13 if not QtWidgets.QApplication.instance(): 14 app = QtWidgets.QApplication(sys.argv) 15 15 16 16 class PlotPropertiesTest(unittest.TestCase): … … 32 32 def testDefaults(self): 33 33 '''Test the GUI in its default state''' 34 self.assertIsInstance(self.widget, Qt Gui.QDialog)34 self.assertIsInstance(self.widget, QtWidgets.QDialog) 35 35 self.assertEqual(self.widget.windowTitle(), "Modify Plot Properties") 36 36 … … 56 56 '''Test the response to color change event''' 57 57 # Accept the new color 58 Qt Gui.QColorDialog.getColor = MagicMock(return_value=QtGui.QColor(255, 0, 255))58 QtWidgets.QColorDialog.getColor = MagicMock(return_value=QtGui.QColor(255, 0, 255)) 59 59 60 60 self.widget.onColorChange() … … 72 72 # Cancel the dialog now 73 73 bad_color = QtGui.QColor() # constructs an invalid color 74 Qt Gui.QColorDialog.getColor = MagicMock(return_value=bad_color)74 QtWidgets.QColorDialog.getColor = MagicMock(return_value=bad_color) 75 75 self.widget.onColorChange() 76 76 -
src/sas/qtgui/Plotting/UnitTesting/Plotter2DTest.py
r7fb471d r53c771e 4 4 import platform 5 5 6 from PyQt 4 import QtGui7 from PyQt 4import QtCore8 from matplotlib.backends.backend_qt 4agg import FigureCanvasQTAgg as FigureCanvas6 from PyQt5 import QtGui, QtWidgets, QtPrintSupport 7 from PyQt5 import QtCore 8 from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas 9 9 from unittest.mock import MagicMock 10 10 from mpl_toolkits.mplot3d import Axes3D … … 20 20 import sas.qtgui.Plotting.Plotter2D as Plotter2D 21 21 22 if not Qt Gui.QApplication.instance():23 app = Qt Gui.QApplication(sys.argv)22 if not QtWidgets.QApplication.instance(): 23 app = QtWidgets.QApplication(sys.argv) 24 24 25 25 class Plotter2DTest(unittest.TestCase): … … 53 53 def tearDown(self): 54 54 '''destroy''' 55 self.plotter.figure.clf() 55 56 self.plotter = None 56 57 … … 73 74 74 75 self.assertTrue(FigureCanvas.draw_idle.called) 76 self.plotter.figure.clf() 75 77 76 78 def testCalculateDepth(self): … … 94 96 self.plotter.show() 95 97 96 Qt Gui.QDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted)98 QtWidgets.QDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Accepted) 97 99 98 100 # Just this one plot … … 100 102 101 103 # Check that exec_ got called 102 self.assertTrue(Qt Gui.QDialog.exec_.called)104 self.assertTrue(QtWidgets.QDialog.exec_.called) 103 105 104 106 self.assertEqual(self.plotter.cmap, "jet") 105 107 self.assertAlmostEqual(self.plotter.vmin, 0.1, 6) 106 108 self.assertAlmostEqual(self.plotter.vmax, 1e+20, 6) 109 self.plotter.figure.clf() 107 110 108 111 def testOnToggleScale(self): … … 115 118 116 119 self.assertTrue(FigureCanvas.draw_idle.called) 120 self.plotter.figure.clf() 117 121 118 122 def testOnBoxSum(self): … … 135 139 self.assertTrue(self.plotter.boxwidget.isVisible()) 136 140 self.assertIsInstance(self.plotter.boxwidget.model, QtGui.QStandardItemModel) 141 self.plotter.figure.clf() 137 142 138 143 def testContextMenuQuickPlot(self): … … 151 156 # Trigger Print Image and make sure the method is called 152 157 self.assertEqual(actions[1].text(), "Print Image") 153 Qt Gui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Rejected)158 QtPrintSupport.QPrintDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Rejected) 154 159 actions[1].trigger() 155 self.assertTrue(Qt Gui.QPrintDialog.exec_.called)160 self.assertTrue(QtPrintSupport.QPrintDialog.exec_.called) 156 161 157 162 # Trigger Copy to Clipboard and make sure the method is called … … 176 181 def done(): 177 182 self.clipboard_called = True 178 QtCore.QObject.connect(Qt Gui.qApp.clipboard(), QtCore.SIGNAL("dataChanged()"), done)183 QtCore.QObject.connect(QtWidgets.qApp.clipboard(), QtCore.SIGNAL("dataChanged()"), done) 179 184 actions[2].trigger() 180 Qt Gui.qApp.processEvents()185 QtWidgets.qApp.processEvents() 181 186 # Make sure clipboard got updated. 182 187 self.assertTrue(self.clipboard_called) 188 self.plotter.figure.clf() 183 189 184 190 def testShowNoPlot(self): … … 200 206 self.assertFalse(FigureCanvas.draw_idle.called) 201 207 self.assertFalse(FigureCanvas.draw.called) 208 self.plotter.figure.clf() 202 209 203 210 def testShow3DPlot(self): … … 220 227 self.assertTrue(Axes3D.plot_surface.called) 221 228 self.assertTrue(FigureCanvas.draw.called) 229 self.plotter.figure.clf() 222 230 223 231 def testShow2DPlot(self): … … 238 246 zmax=None) 239 247 self.assertTrue(FigureCanvas.draw_idle.called) 248 self.plotter.figure.clf() 240 249 241 250 -
src/sas/qtgui/Plotting/UnitTesting/PlotterBaseTest.py
r7fb471d r53c771e 4 4 from unittest.mock import MagicMock 5 5 6 from PyQt 4 import QtGui6 from PyQt5 import QtGui, QtWidgets, QtPrintSupport 7 7 import matplotlib.pyplot as plt 8 from matplotlib.backends.backend_qt 4agg import FigureCanvasQTAgg as FigureCanvas9 from matplotlib.backends.backend_qt 4agg import NavigationToolbar2QT as NavigationToolbar8 from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas 9 from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar 10 10 11 11 ####### TEMP … … 21 21 import sas.qtgui.Plotting.PlotterBase as PlotterBase 22 22 23 if not Qt Gui.QApplication.instance():24 app = Qt Gui.QApplication(sys.argv)23 if not QtWidgets.QApplication.instance(): 24 app = QtWidgets.QApplication(sys.argv) 25 25 26 26 class PlotterBaseTest(unittest.TestCase): … … 45 45 def testDefaults(self): 46 46 """ default method variables values """ 47 self.assertIsInstance(self.plotter, Qt Gui.QWidget)47 self.assertIsInstance(self.plotter, QtWidgets.QWidget) 48 48 self.assertIsInstance(self.plotter.canvas, FigureCanvas) 49 49 self.assertIsInstance(self.plotter.toolbar, NavigationToolbar) … … 91 91 self.assertTrue(self.plotter.toolbar.save_figure.called) 92 92 93 def testOnImagePrint(self):93 def notestOnImagePrint(self): 94 94 ''' test the workspace print ''' 95 95 QtGui.QPainter.end = MagicMock() 96 Qt Gui.QLabel.render = MagicMock()96 QtWidgets.QLabel.render = MagicMock() 97 97 98 98 # First, let's cancel printing 99 Qt Gui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Rejected)99 QtPrintSupport.QPrintDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Rejected) 100 100 self.plotter.onImagePrint() 101 101 self.assertFalse(QtGui.QPainter.end.called) 102 self.assertFalse(Qt Gui.QLabel.render.called)102 self.assertFalse(QtWidgets.QLabel.render.called) 103 103 104 104 # Let's print now 105 Qt Gui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted)105 QtPrintSupport.QPrintDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Accepted) 106 106 self.plotter.onImagePrint() 107 107 self.assertTrue(QtGui.QPainter.end.called) 108 self.assertTrue(Qt Gui.QLabel.render.called)108 self.assertTrue(QtWidgets.QLabel.render.called) 109 109 110 def testOnClipboardCopy(self):110 def notestOnClipboardCopy(self): 111 111 ''' test the workspace screen copy ''' 112 112 QtGui.QClipboard.setPixmap = MagicMock() … … 141 141 # Trigger Print Image and make sure the method is called 142 142 self.assertEqual(actions[1].text(), "Print Image") 143 Qt Gui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Rejected)143 QtPrintSupport.QPrintDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Rejected) 144 144 actions[1].trigger() 145 self.assertTrue(Qt Gui.QPrintDialog.exec_.called)145 self.assertTrue(QtPrintSupport.QPrintDialog.exec_.called) 146 146 147 147 # Trigger Copy to Clipboard and make sure the method is called … … 154 154 def done(): 155 155 self.clipboard_called = True 156 QtCore.QObject.connect(Qt Gui.qApp.clipboard(), QtCore.SIGNAL("dataChanged()"), done)156 QtCore.QObject.connect(QtWidgets.qApp.clipboard(), QtCore.SIGNAL("dataChanged()"), done) 157 157 actions[2].trigger() 158 Qt Gui.qApp.processEvents()158 QtWidgets.qApp.processEvents() 159 159 # Make sure clipboard got updated. 160 160 self.assertTrue(self.clipboard_called) … … 163 163 """ Test changing the plot title""" 164 164 # Mock the modal dialog's response 165 Qt Gui.QDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted)165 QtWidgets.QDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Accepted) 166 166 self.plotter.show() 167 167 # Assure the original title is none -
src/sas/qtgui/Plotting/UnitTesting/PlotterTest.py
r7fb471d r53c771e 3 3 import platform 4 4 5 from PyQt 4 import QtGui6 from PyQt 4import QtCore7 from matplotlib.backends.backend_qt 4agg import FigureCanvasQTAgg as FigureCanvas5 from PyQt5 import QtGui, QtWidgets, QtPrintSupport 6 from PyQt5 import QtCore 7 from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas 8 8 from unittest.mock import MagicMock 9 9 from unittest.mock import patch … … 21 21 import sas.qtgui.Plotting.Plotter as Plotter 22 22 23 if not Qt Gui.QApplication.instance():24 app = Qt Gui.QApplication(sys.argv)23 if not QtWidgets.QApplication.instance(): 24 app = QtWidgets.QApplication(sys.argv) 25 25 26 26 … … 57 57 self.plotter.data = self.data 58 58 self.plotter.show() 59 FigureCanvas.draw = MagicMock()59 FigureCanvas.draw_idle = MagicMock() 60 60 61 61 self.plotter.plot(hide_error=False) 62 62 63 63 self.assertEqual(self.plotter.ax.get_xscale(), 'log') 64 self.assertTrue(FigureCanvas.draw.called) 64 self.assertTrue(FigureCanvas.draw_idle.called) 65 66 self.plotter.figure.clf() 65 67 66 68 def testPlotWithoutErrors(self): … … 68 70 self.plotter.data = self.data 69 71 self.plotter.show() 70 FigureCanvas.draw = MagicMock()72 FigureCanvas.draw_idle = MagicMock() 71 73 72 74 self.plotter.plot(hide_error=True) 73 75 74 76 self.assertEqual(self.plotter.ax.get_yscale(), 'log') 75 self.assertTrue(FigureCanvas.draw.called) 77 self.assertTrue(FigureCanvas.draw_idle.called) 78 self.plotter.figure.clf() 76 79 77 80 def testPlotWithSesans(self): … … 110 113 # Trigger Print Image and make sure the method is called 111 114 self.assertEqual(actions[1].text(), "Print Image") 112 Qt Gui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Rejected)115 QtPrintSupport.QPrintDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Rejected) 113 116 actions[1].trigger() 114 self.assertTrue(Qt Gui.QPrintDialog.exec_.called)117 self.assertTrue(QtPrintSupport.QPrintDialog.exec_.called) 115 118 116 119 # Trigger Copy to Clipboard and make sure the method is called … … 125 128 # Trigger Change Scale and make sure the method is called 126 129 self.assertEqual(actions[6].text(), "Change Scale") 127 self.plotter.properties.exec_ = MagicMock(return_value=Qt Gui.QDialog.Rejected)130 self.plotter.properties.exec_ = MagicMock(return_value=QtWidgets.QDialog.Rejected) 128 131 actions[6].trigger() 129 132 self.assertTrue(self.plotter.properties.exec_.called) … … 135 138 def done(): 136 139 self.clipboard_called = True 137 QtCore.QObject.connect(Qt Gui.qApp.clipboard(), QtCore.SIGNAL("dataChanged()"), done)140 QtCore.QObject.connect(QtWidgets.qApp.clipboard(), QtCore.SIGNAL("dataChanged()"), done) 138 141 actions[2].trigger() 139 Qt Gui.qApp.processEvents()142 QtWidgets.qApp.processEvents() 140 143 # Make sure clipboard got updated. 141 144 self.assertTrue(self.clipboard_called) … … 157 160 self.assertEqual(len(self.plotter.plot_dict), 1) 158 161 self.assertEqual(len(self.plotter.ax.collections), 1) 162 self.plotter.figure.clf() 159 163 160 164 def testAddText(self): … … 174 178 self.plotter.addText.color = MagicMock(return_value = test_color) 175 179 # Return OK from the dialog 176 self.plotter.addText.exec_ = MagicMock(return_value = Qt Gui.QDialog.Accepted)180 self.plotter.addText.exec_ = MagicMock(return_value = QtWidgets.QDialog.Accepted) 177 181 # Add text to graph 178 182 self.plotter.onAddText() … … 184 188 self.assertEqual(self.plotter.textList[0].get_fontproperties().get_family()[0], 'Arial') 185 189 self.assertEqual(self.plotter.textList[0].get_fontproperties().get_size(), 16) 190 self.plotter.figure.clf() 186 191 187 192 def testOnRemoveText(self): … … 193 198 self.plotter.addText.textEdit.setText(test_text) 194 199 # Return OK from the dialog 195 self.plotter.addText.exec_ = MagicMock(return_value = Qt Gui.QDialog.Accepted)200 self.plotter.addText.exec_ = MagicMock(return_value = QtWidgets.QDialog.Accepted) 196 201 # Add text to graph 197 202 self.plotter.onAddText() … … 209 214 self.plotter.onRemoveText() 210 215 self.assertEqual(self.plotter.textList, []) 216 self.plotter.figure.clf() 211 217 212 218 def testOnSetGraphRange(self): … … 216 222 self.plotter.plot(self.data) 217 223 self.plotter.show() 218 self.plotter.setRange.exec_ = MagicMock(return_value = Qt Gui.QDialog.Accepted)224 self.plotter.setRange.exec_ = MagicMock(return_value = QtWidgets.QDialog.Accepted) 219 225 self.plotter.setRange.xrange = MagicMock(return_value = new_x) 220 226 self.plotter.setRange.yrange = MagicMock(return_value = new_y) … … 225 231 self.assertEqual(self.plotter.ax.get_xlim(), new_x) 226 232 self.assertEqual(self.plotter.ax.get_ylim(), new_y) 233 self.plotter.figure.clf() 227 234 228 235 def testOnResetGraphRange(self): … … 236 243 237 244 # mock setRange methods 238 self.plotter.setRange.exec_ = MagicMock(return_value = Qt Gui.QDialog.Accepted)245 self.plotter.setRange.exec_ = MagicMock(return_value = QtWidgets.QDialog.Accepted) 239 246 self.plotter.setRange.xrange = MagicMock(return_value = new_x) 240 247 self.plotter.setRange.yrange = MagicMock(return_value = new_y) … … 249 256 self.assertNotEqual(self.plotter.ax.get_xlim(), new_x) 250 257 self.assertNotEqual(self.plotter.ax.get_ylim(), new_y) 258 self.plotter.figure.clf() 251 259 252 260 def testOnLinearFit(self): … … 254 262 self.plotter.plot(self.data) 255 263 self.plotter.show() 256 Qt Gui.QDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted)264 QtWidgets.QDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Accepted) 257 265 258 266 # Just this one plot … … 261 269 262 270 # Check that exec_ got called 263 self.assertTrue(QtGui.QDialog.exec_.called) 271 self.assertTrue(QtWidgets.QDialog.exec_.called) 272 self.plotter.figure.clf() 264 273 265 274 def testOnRemovePlot(self): … … 296 305 # Assure the plotter window is closed 297 306 self.assertFalse(self.plotter.isVisible()) 298 307 self.plotter.figure.clf() 299 308 300 309 def testRemovePlot(self): … … 327 336 # The hide_error flag should also remain 328 337 self.assertTrue(self.plotter.plot_dict[2].hide_error) 338 self.plotter.figure.clf() 329 339 330 340 def testOnToggleHideError(self): … … 357 367 # The hide_error flag should toggle 358 368 self.assertEqual(self.plotter.plot_dict[2].hide_error, not error_status) 369 self.plotter.figure.clf() 359 370 360 371 def testOnFitDisplay(self): … … 373 384 self.plotter.plot.assert_called_with(data=self.plotter.fit_result, 374 385 hide_error=True, marker='-') 386 self.plotter.figure.clf() 375 387 376 388 def testReplacePlot(self): … … 410 422 # The hide_error flag should be as set 411 423 self.assertEqual(self.plotter.plot_dict[2].hide_error, error_status) 424 self.plotter.figure.clf() 412 425 413 426 def notestOnModifyPlot(self): … … 429 442 with patch('sas.qtgui.Plotting.PlotProperties.PlotProperties') as mock: 430 443 instance = mock.return_value 431 Qt Gui.QDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted)444 QtWidgets.QDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Accepted) 432 445 instance.symbol.return_value = 7 433 446 434 447 self.plotter.onModifyPlot(2) 448 self.plotter.figure.clf() 435 449 436 450 -
src/sas/qtgui/Plotting/UnitTesting/ScalePropertiesTest.py
r464cd07 r53c771e 2 2 import unittest 3 3 4 from PyQt 4 import QtGui4 from PyQt5 import QtGui, QtWidgets 5 5 6 6 # set up import paths … … 10 10 from sas.qtgui.Plotting.ScaleProperties import ScaleProperties 11 11 12 if not Qt Gui.QApplication.instance():13 app = Qt Gui.QApplication(sys.argv)12 if not QtWidgets.QApplication.instance(): 13 app = QtWidgets.QApplication(sys.argv) 14 14 15 15 class ScalePropertiesTest(unittest.TestCase): … … 27 27 def testDefaults(self): 28 28 '''Test the GUI in its default state''' 29 self.assertIsInstance(self.widget, Qt Gui.QDialog)29 self.assertIsInstance(self.widget, QtWidgets.QDialog) 30 30 self.assertEqual(self.widget.windowTitle(), "Scale Properties") 31 31 self.assertEqual(self.widget.cbX.count(), 6) -
src/sas/qtgui/Plotting/UnitTesting/SetGraphRangeTest.py
r464cd07 r53c771e 2 2 import unittest 3 3 4 from PyQt 4 import QtGui4 from PyQt5 import QtGui, QtWidgets 5 5 6 6 # set up import paths … … 10 10 from sas.qtgui.Plotting.SetGraphRange import SetGraphRange 11 11 12 if not Qt Gui.QApplication.instance():13 app = Qt Gui.QApplication(sys.argv)12 if not QtWidgets.QApplication.instance(): 13 app = QtWidgets.QApplication(sys.argv) 14 14 15 15 class SetGraphRangeTest(unittest.TestCase): … … 27 27 def testDefaults(self): 28 28 '''Test the GUI in its default state''' 29 self.assertIsInstance(self.widget, Qt Gui.QDialog)29 self.assertIsInstance(self.widget, QtWidgets.QDialog) 30 30 self.assertEqual(self.widget.windowTitle(), "Set Graph Range") 31 self.assertIsInstance(self.widget.txtXmin, Qt Gui.QLineEdit)31 self.assertIsInstance(self.widget.txtXmin, QtWidgets.QLineEdit) 32 32 self.assertIsInstance(self.widget.txtXmin.validator(), QtGui.QDoubleValidator) 33 33 -
src/sas/qtgui/Plotting/UnitTesting/SlicerModelTest.py
r7fb471d r53c771e 3 3 from unittest.mock import MagicMock 4 4 5 from PyQt 4 import QtGui6 from PyQt 4import QtCore5 from PyQt5 import QtGui, QtWidgets 6 from PyQt5 import QtCore 7 7 8 8 # set up import paths … … 12 12 from sas.qtgui.Plotting.SlicerModel import SlicerModel 13 13 14 if not Qt Gui.QApplication.instance():15 app = Qt Gui.QApplication(sys.argv)14 if not QtWidgets.QApplication.instance(): 15 app = QtWidgets.QApplication(sys.argv) 16 16 17 17 class SlicerModelTest(unittest.TestCase): -
src/sas/qtgui/Plotting/UnitTesting/SlicerParametersTest.py
r4992ff2 r53c771e 3 3 from unittest.mock import MagicMock 4 4 5 from PyQt 4 import QtGui6 from PyQt 4import QtCore7 from PyQt 4import QtTest8 from PyQt 4import QtWebKit5 from PyQt5 import QtGui, QtWidgets 6 from PyQt5 import QtCore 7 from PyQt5 import QtTest 8 from PyQt5 import QtWebKit 9 9 10 10 # set up import paths … … 16 16 from sas.qtgui.Plotting.SlicerParameters import SlicerParameters 17 17 18 if not Qt Gui.QApplication.instance():19 app = Qt Gui.QApplication(sys.argv)18 if not QtWidgets.QApplication.instance(): 19 app = QtWidgets.QApplication(sys.argv) 20 20 21 21 class SlicerParametersTest(unittest.TestCase): … … 38 38 #self.widget.mapper 39 39 self.assertIsInstance(self.widget.proxy, QtCore.QIdentityProxyModel) 40 self.assertIsInstance(self.widget.lstParams.itemDelegate(), Qt Gui.QStyledItemDelegate)40 self.assertIsInstance(self.widget.lstParams.itemDelegate(), QtWidgets.QStyledItemDelegate) 41 41 self.assertTrue(self.widget.lstParams.model().columnReadOnly(0)) 42 42 self.assertFalse(self.widget.lstParams.model().columnReadOnly(1)) … … 62 62 spy_close = QtSignalSpy(self.widget, self.widget.close_signal) 63 63 # Click on the "Close" button 64 QtTest.QTest.mouseClick(self.widget.buttonBox.button(Qt Gui.QDialogButtonBox.Close), QtCore.Qt.LeftButton)64 QtTest.QTest.mouseClick(self.widget.buttonBox.button(QtWidgets.QDialogButtonBox.Close), QtCore.Qt.LeftButton) 65 65 # Check the signal 66 66 self.assertEqual(spy_close.count(), 1) … … 68 68 self.assertFalse(self.widget.isVisible()) 69 69 70 def testOnHelp(self):70 def notestOnHelp(self): 71 71 ''' Assure clicking on help returns QtWeb view on requested page''' 72 72 self.widget.show() -
src/sas/qtgui/Plotting/UnitTesting/WindowTitleTest.py
r464cd07 r53c771e 2 2 import unittest 3 3 4 from PyQt 4 import QtGui4 from PyQt5 import QtGui, QtWidgets 5 5 6 6 # set up import paths … … 10 10 from sas.qtgui.Plotting.WindowTitle import WindowTitle 11 11 12 if not Qt Gui.QApplication.instance():13 app = Qt Gui.QApplication(sys.argv)12 if not QtWidgets.QApplication.instance(): 13 app = QtWidgets.QApplication(sys.argv) 14 14 15 15 class WindowTitleTest(unittest.TestCase): … … 27 27 '''Test the GUI in its default state''' 28 28 self.widget.show() 29 self.assertIsInstance(self.widget, Qt Gui.QDialog)29 self.assertIsInstance(self.widget, QtWidgets.QDialog) 30 30 self.assertEqual(self.widget.windowTitle(), "Modify Window Title") 31 31 … … 33 33 '''Modify the title''' 34 34 self.widget.show() 35 Qt Gui.qApp.processEvents()35 QtWidgets.qApp.processEvents() 36 36 # make sure we have the pre-set title 37 37 self.assertEqual(self.widget.txtTitle.text(), "some title") … … 39 39 self.widget.txtTitle.clear() 40 40 self.widget.txtTitle.setText("5 elephants") 41 Qt Gui.qApp.processEvents()41 QtWidgets.qApp.processEvents() 42 42 # Retrieve value 43 43 new_title = self.widget.title()
Note: See TracChangeset
for help on using the changeset viewer.