Changeset 64f1e93 in sasview for src/sas/qtgui/UnitTesting


Ignore:
Timestamp:
Dec 7, 2016 5:47:22 AM (7 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:
416fa8f
Parents:
55d89f8
Message:

2D plots: more unit tests + minor cleanup

Location:
src/sas/qtgui/UnitTesting
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/UnitTesting/GuiManagerTest.py

    r31c5b58 r64f1e93  
    119119        Test that the custom exit method is called on shutdown 
    120120        """ 
     121        self.manager._workspace.show() 
     122 
    121123        # Must mask sys.exit, otherwise the whole testing process stops. 
    122124        sys.exit = MagicMock() 
  • src/sas/qtgui/UnitTesting/Plotter2DTest.py

    r55d89f8 r64f1e93  
    66from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas 
    77from mock import MagicMock 
     8from mpl_toolkits.mplot3d import Axes3D 
    89 
    910####### TEMP 
     
    5455        self.plotter.data = self.data 
    5556        self.plotter.show() 
    56         FigureCanvas.draw = MagicMock() 
     57        FigureCanvas.draw_idle = MagicMock() 
    5758 
    5859        self.plotter.plot() 
    5960 
    60         #self.assertTrue(FigureCanvas.draw.called) 
     61        self.assertTrue(FigureCanvas.draw_idle.called) 
     62 
     63    def testOnToggleScale(self): 
     64        """ Respond to the event by replotting """ 
     65        self.plotter.data = self.data 
     66        self.plotter.show() 
     67        FigureCanvas.draw_idle = MagicMock() 
     68 
     69        self.plotter.onToggleScale(None) 
     70 
     71        self.assertTrue(FigureCanvas.draw_idle.called) 
    6172 
    6273    def testContextMenuQuickPlot(self): 
     
    99110        # Trigger Change Scale and make sure the method is called 
    100111        self.assertEqual(actions[6].text(), "Toggle Linear/Log Scale") 
     112        FigureCanvas.draw_idle = MagicMock() 
     113        actions[6].trigger() 
     114        self.assertTrue(FigureCanvas.draw_idle.called) 
     115 
     116    def testShowNoPlot(self): 
     117        """ Test the plot rendering and generation """ 
     118 
     119        FigureCanvas.draw_idle = MagicMock() 
    101120        FigureCanvas.draw = MagicMock() 
    102         actions[6].trigger() 
    103         #self.assertTrue(FigureCanvas.draw.called) 
     121 
     122        # Test early return on no data 
     123        self.plotter.showPlot(data=None, 
     124                              qx_data=self.data.qx_data, 
     125                              qy_data=self.data.qy_data, 
     126                              xmin=self.data.xmin, 
     127                              xmax=self.data.xmax, 
     128                              ymin=self.data.ymin, ymax=self.data.ymax, 
     129                              cmap=None, zmin=None, 
     130                              zmax=None) 
     131 
     132        self.assertFalse(FigureCanvas.draw_idle.called) 
     133        self.assertFalse(FigureCanvas.draw.called) 
     134 
     135    def testShow3DPlot(self): 
     136        """ Test the 3Dplot rendering and generation """ 
     137        # Test 3D printout 
     138        FigureCanvas.draw = MagicMock() 
     139        Axes3D.plot_surface = MagicMock() 
     140        self.plotter.figure.colorbar = MagicMock() 
     141 
     142        self.plotter.dimension = 3 
     143        self.plotter.data = self.data 
     144        self.plotter.showPlot(data=self.plotter.data.data, 
     145                              qx_data=self.data.qx_data, 
     146                              qy_data=self.data.qy_data, 
     147                              xmin=self.data.xmin, 
     148                              xmax=self.data.xmax, 
     149                              ymin=self.data.ymin, ymax=self.data.ymax, 
     150                              cmap=None, zmin=None, 
     151                              zmax=None) 
     152        self.assertTrue(Axes3D.plot_surface.called) 
     153        self.assertTrue(FigureCanvas.draw.called) 
     154 
     155    def testShow2DPlot(self): 
     156        """ Test the 2Dplot rendering and generation """ 
     157        # Test 2D printout 
     158        FigureCanvas.draw_idle = MagicMock() 
     159        self.plotter.figure.colorbar = MagicMock() 
     160 
     161        self.plotter.dimension = 2 
     162        self.plotter.data = self.data 
     163        self.plotter.showPlot(data=self.plotter.data.data, 
     164                              qx_data=self.data.qx_data, 
     165                              qy_data=self.data.qy_data, 
     166                              xmin=self.data.xmin, 
     167                              xmax=self.data.xmax, 
     168                              ymin=self.data.ymin, ymax=self.data.ymax, 
     169                              cmap=None, zmin=None, 
     170                              zmax=None) 
     171        self.assertTrue(FigureCanvas.draw_idle.called) 
    104172 
    105173 
  • src/sas/qtgui/UnitTesting/PlotterTest.py

    r6d05e1d r64f1e93  
    100100        self.plotter.data = self.data 
    101101 
    102         self.plotter.xyTransform(xLabel="ln(x)", yLabel="ln(y)") 
    103         self.assertEqual(self.plotter.ax.get_xlabel(), "$\\ln{()}()$") 
     102        self.plotter.xyTransform(xLabel="x", yLabel="y") 
     103        self.assertEqual(self.plotter.ax.get_xlabel(), "$()$") 
     104        self.assertEqual(self.plotter.ax.get_ylabel(), "$()$") 
     105 
     106        self.plotter.xyTransform(xLabel="x^(2)", yLabel="1/y") 
     107        self.assertEqual(self.plotter.ax.get_xlabel(), "$^{2}(()^{2})$") 
     108        self.assertEqual(self.plotter.ax.get_ylabel(), "$1/(()^{-1})$") 
     109 
     110        self.plotter.xyTransform(xLabel="x^(4)", yLabel="ln(y)") 
     111        self.assertEqual(self.plotter.ax.get_xlabel(), "$^{4}(()^{4})$") 
    104112        self.assertEqual(self.plotter.ax.get_ylabel(), "$\\ln{()}()$") 
    105113 
    106         self.plotter.xyTransform(xLabel="ln(x)", yLabel="ln(y)") 
     114        self.plotter.xyTransform(xLabel="ln(x)", yLabel="y^(2)") 
    107115        self.assertEqual(self.plotter.ax.get_xlabel(), "$\\ln{()}()$") 
    108         self.assertEqual(self.plotter.ax.get_ylabel(), "$\\ln{()}()$") 
     116        self.assertEqual(self.plotter.ax.get_ylabel(), "$^{2}(()^{2})$") 
    109117 
    110         self.plotter.xyTransform(xLabel="x^(2)", yLabel="1/sqrt(y)") 
    111         self.assertEqual(self.plotter.ax.get_xlabel(), "$^{2}(()^{2})$") 
     118        self.plotter.xyTransform(xLabel="log10(x)", yLabel="y*x^(2)") 
     119        self.assertEqual(self.plotter.ax.get_xlabel(), "$()$") 
     120        self.assertEqual(self.plotter.ax.get_ylabel(), "$ \\ \\ ^{2}(()^{2})$") 
     121 
     122        self.plotter.xyTransform(xLabel="log10(x^(4))", yLabel="y*x^(4)") 
     123        self.assertEqual(self.plotter.ax.get_xlabel(), "$^{4}(()^{4})$") 
     124        self.assertEqual(self.plotter.ax.get_ylabel(), "$ \\ \\ ^{4}(()^{16})$") 
     125 
     126        self.plotter.xyTransform(xLabel="x", yLabel="1/sqrt(y)") 
    112127        self.assertEqual(self.plotter.ax.get_ylabel(), "$1/\\sqrt{}(()^{-0.5})$") 
     128 
     129        self.plotter.xyTransform(xLabel="x", yLabel="log10(y)") 
     130        self.assertEqual(self.plotter.ax.get_ylabel(), "$()$") 
     131 
     132        self.plotter.xyTransform(xLabel="x", yLabel="ln(y*x)") 
     133        self.assertEqual(self.plotter.ax.get_ylabel(), "$\\ln{( \\ \\ )}()$") 
     134 
     135        self.plotter.xyTransform(xLabel="x", yLabel="ln(y*x^(2))") 
     136        self.assertEqual(self.plotter.ax.get_ylabel(), "$\\ln ( \\ \\ ^{2})(()^{2})$") 
     137 
     138        self.plotter.xyTransform(xLabel="x", yLabel="ln(y*x^(4))") 
     139        self.assertEqual(self.plotter.ax.get_ylabel(), "$\\ln ( \\ \\ ^{4})(()^{4})$") 
     140 
     141        self.plotter.xyTransform(xLabel="x", yLabel="log10(y*x^(4))") 
     142        self.assertEqual(self.plotter.ax.get_ylabel(), "$ \\ \\ ^{4}(()^{4})$") 
    113143 
    114144if __name__ == "__main__": 
Note: See TracChangeset for help on using the changeset viewer.