Ignore:
Timestamp:
Nov 9, 2017 8:45:20 AM (6 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
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 09:22:45)
git-committer:
Piotr Rozyczko <rozyczko@…> (11/09/17 08:45:20)
Message:

Converted unit tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Plotting/UnitTesting/Plotter2DTest.py

    r7fb471d r53c771e  
    44import platform 
    55 
    6 from PyQt4 import QtGui 
    7 from PyQt4 import QtCore 
    8 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas 
     6from PyQt5 import QtGui, QtWidgets, QtPrintSupport 
     7from PyQt5 import QtCore 
     8from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas 
    99from unittest.mock import MagicMock 
    1010from mpl_toolkits.mplot3d import Axes3D 
     
    2020import sas.qtgui.Plotting.Plotter2D as Plotter2D 
    2121 
    22 if not QtGui.QApplication.instance(): 
    23     app = QtGui.QApplication(sys.argv) 
     22if not QtWidgets.QApplication.instance(): 
     23    app = QtWidgets.QApplication(sys.argv) 
    2424 
    2525class Plotter2DTest(unittest.TestCase): 
     
    5353    def tearDown(self): 
    5454        '''destroy''' 
     55        self.plotter.figure.clf() 
    5556        self.plotter = None 
    5657 
     
    7374 
    7475        self.assertTrue(FigureCanvas.draw_idle.called) 
     76        self.plotter.figure.clf() 
    7577 
    7678    def testCalculateDepth(self): 
     
    9496        self.plotter.show() 
    9597 
    96         QtGui.QDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted) 
     98        QtWidgets.QDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Accepted) 
    9799 
    98100        # Just this one plot 
     
    100102 
    101103        # Check that exec_ got called 
    102         self.assertTrue(QtGui.QDialog.exec_.called) 
     104        self.assertTrue(QtWidgets.QDialog.exec_.called) 
    103105 
    104106        self.assertEqual(self.plotter.cmap, "jet") 
    105107        self.assertAlmostEqual(self.plotter.vmin, 0.1, 6) 
    106108        self.assertAlmostEqual(self.plotter.vmax, 1e+20, 6) 
     109        self.plotter.figure.clf() 
    107110 
    108111    def testOnToggleScale(self): 
     
    115118 
    116119        self.assertTrue(FigureCanvas.draw_idle.called) 
     120        self.plotter.figure.clf() 
    117121 
    118122    def testOnBoxSum(self): 
     
    135139        self.assertTrue(self.plotter.boxwidget.isVisible()) 
    136140        self.assertIsInstance(self.plotter.boxwidget.model, QtGui.QStandardItemModel) 
     141        self.plotter.figure.clf() 
    137142 
    138143    def testContextMenuQuickPlot(self): 
     
    151156        # Trigger Print Image and make sure the method is called 
    152157        self.assertEqual(actions[1].text(), "Print Image") 
    153         QtGui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Rejected) 
     158        QtPrintSupport.QPrintDialog.exec_ = MagicMock(return_value=QtWidgets.QDialog.Rejected) 
    154159        actions[1].trigger() 
    155         self.assertTrue(QtGui.QPrintDialog.exec_.called) 
     160        self.assertTrue(QtPrintSupport.QPrintDialog.exec_.called) 
    156161 
    157162        # Trigger Copy to Clipboard and make sure the method is called 
     
    176181        def done(): 
    177182            self.clipboard_called = True 
    178         QtCore.QObject.connect(QtGui.qApp.clipboard(), QtCore.SIGNAL("dataChanged()"), done) 
     183        QtCore.QObject.connect(QtWidgets.qApp.clipboard(), QtCore.SIGNAL("dataChanged()"), done) 
    179184        actions[2].trigger() 
    180         QtGui.qApp.processEvents() 
     185        QtWidgets.qApp.processEvents() 
    181186        # Make sure clipboard got updated. 
    182187        self.assertTrue(self.clipboard_called) 
     188        self.plotter.figure.clf() 
    183189 
    184190    def testShowNoPlot(self): 
     
    200206        self.assertFalse(FigureCanvas.draw_idle.called) 
    201207        self.assertFalse(FigureCanvas.draw.called) 
     208        self.plotter.figure.clf() 
    202209 
    203210    def testShow3DPlot(self): 
     
    220227        self.assertTrue(Axes3D.plot_surface.called) 
    221228        self.assertTrue(FigureCanvas.draw.called) 
     229        self.plotter.figure.clf() 
    222230 
    223231    def testShow2DPlot(self): 
     
    238246                              zmax=None) 
    239247        self.assertTrue(FigureCanvas.draw_idle.called) 
     248        self.plotter.figure.clf() 
    240249 
    241250 
Note: See TracChangeset for help on using the changeset viewer.