Changeset 257bd57 in sasview for src/sas/qtgui/UnitTesting


Ignore:
Timestamp:
Dec 21, 2016 3:46:29 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:
aadf0af1
Parents:
d3ca363
Message:

unit tests for graph range and add text

File:
1 edited

Legend:

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

    rd3ca363 r257bd57  
    66from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas 
    77from mock import MagicMock 
     8from mock import patch 
    89 
    910####### TEMP 
     
    2324    def setUp(self): 
    2425        '''create''' 
     26 
    2527        self.plotter = Plotter.Plotter(None, quickplot=True) 
    2628        self.data = Data1D(x=[1.0, 2.0, 3.0], 
     
    110112    def testXYTransform(self): 
    111113        """ Assure the unit/legend transformation is correct""" 
    112         self.plotter.data = self.data 
     114        self.plotter.plot(self.data) 
    113115 
    114116        self.plotter.xyTransform(xLabel="x", yLabel="y") 
     
    156158    def testAddText(self): 
    157159        """ Checks the functionality of adding text to graph """ 
    158         pass 
     160 
     161        self.plotter.plot(self.data) 
     162        self.plotter.x_click = 100.0 
     163        self.plotter.y_click = 100.0 
     164        # modify the text edit control 
     165        test_text = "Smoke in cabin" 
     166        test_font = QtGui.QFont("Arial", 16, QtGui.QFont.Bold) 
     167        test_color = "#00FF00" 
     168        self.plotter.addText.textEdit.setText(test_text) 
     169 
     170        # Return the requested font parameters 
     171        self.plotter.addText.font = MagicMock(return_value = test_font) 
     172        self.plotter.addText.color = MagicMock(return_value = test_color) 
     173        # Return OK from the dialog 
     174        self.plotter.addText.exec_ = MagicMock(return_value = QtGui.QDialog.Accepted) 
     175        # Add text to graph 
     176        self.plotter.onAddText() 
     177        self.plotter.show() 
     178        # Check if the text was added properly 
     179        self.assertEqual(len(self.plotter.textList), 1) 
     180        self.assertEqual(self.plotter.textList[0].get_text(), test_text) 
     181        self.assertEqual(self.plotter.textList[0].get_color(), test_color) 
     182        self.assertEqual(self.plotter.textList[0].get_fontproperties().get_family()[0], 'Arial') 
     183        self.assertEqual(self.plotter.textList[0].get_fontproperties().get_size(), 16) 
    159184 
    160185    def testOnRemoveText(self): 
    161186        """ Cheks if annotations can be removed from the graph """ 
    162         pass 
     187 
     188        # Add some text 
     189        self.plotter.plot(self.data) 
     190        test_text = "Safety instructions" 
     191        self.plotter.addText.textEdit.setText(test_text) 
     192        # Return OK from the dialog 
     193        self.plotter.addText.exec_ = MagicMock(return_value = QtGui.QDialog.Accepted) 
     194        # Add text to graph 
     195        self.plotter.onAddText() 
     196        self.plotter.show() 
     197        # Check if the text was added properly 
     198        self.assertEqual(len(self.plotter.textList), 1) 
     199 
     200        # Now, remove the text 
     201        self.plotter.onRemoveText() 
     202 
     203        # And assure no text is displayed 
     204        self.assertEqual(self.plotter.textList, []) 
     205 
     206        # Attempt removal on empty and check 
     207        self.plotter.onRemoveText() 
     208        self.assertEqual(self.plotter.textList, []) 
    163209 
    164210    def testOnSetGraphRange(self): 
    165211        """ Cheks if the graph can be resized for range """ 
    166         pass 
     212        new_x = (1,2) 
     213        new_y = (10,11) 
     214        self.plotter.plot(self.data) 
     215        self.plotter.show() 
     216        self.plotter.setRange.exec_ = MagicMock(return_value = QtGui.QDialog.Accepted) 
     217        self.plotter.setRange.xrange = MagicMock(return_value = new_x) 
     218        self.plotter.setRange.yrange = MagicMock(return_value = new_y) 
     219 
     220        # Call the tested method 
     221        self.plotter.onSetGraphRange() 
     222        # See that ranges changed accordingly 
     223        self.assertEqual(self.plotter.ax.get_xlim(), new_x) 
     224        self.assertEqual(self.plotter.ax.get_ylim(), new_y) 
    167225 
    168226    def testOnResetGraphRange(self): 
    169227        """ Cheks if the graph can be reset after resizing for range """ 
    170         pass 
     228        # New values 
     229        new_x = (1,2) 
     230        new_y = (10,11) 
     231        # define the plot 
     232        self.plotter.plot(self.data) 
     233        self.plotter.show() 
     234 
     235        # mock setRange methods 
     236        self.plotter.setRange.exec_ = MagicMock(return_value = QtGui.QDialog.Accepted) 
     237        self.plotter.setRange.xrange = MagicMock(return_value = new_x) 
     238        self.plotter.setRange.yrange = MagicMock(return_value = new_y) 
     239 
     240        # Change the axes range 
     241        self.plotter.onSetGraphRange() 
     242 
     243        # Now, reset the range back 
     244        self.plotter.onResetGraphRange() 
     245 
     246        # See that ranges are changed 
     247        self.assertNotEqual(self.plotter.ax.get_xlim(), new_x) 
     248        self.assertNotEqual(self.plotter.ax.get_ylim(), new_y) 
    171249 
    172250if __name__ == "__main__": 
Note: See TracChangeset for help on using the changeset viewer.