Changeset 257bd57 in sasview


Ignore:
Timestamp:
Dec 21, 2016 5: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

Location:
src/sas/qtgui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/GuiManager.py

    rabc5e70 r257bd57  
    4646    def __init__(self, mainWindow=None, reactor=None, parent=None): 
    4747        """ 
     48        Initialize the manager as a child of MainWindow. 
    4849        """ 
    4950        self._workspace = mainWindow 
     
    185186 
    186187    def communicator(self): 
    187         """ 
    188         """ 
     188        """ Accessor for the communicator """ 
    189189        return self.communicate 
    190190 
    191191    def reactor(self): 
    192         """ 
    193         """ 
     192        """ Accessor for the reactor """ 
    194193        return self._reactor 
    195194 
    196195    def setReactor(self, reactor): 
    197         """ 
    198         """ 
     196        """ Reactor setter """ 
    199197        self._reactor = reactor 
    200198 
    201199    def perspective(self): 
    202         """ 
    203         """ 
     200        """ Accessor for the perspective """ 
    204201        return self._current_perspective 
    205202 
  • src/sas/qtgui/Plotter.py

    rd3ca363 r257bd57  
    1818        super(PlotterWidget, self).__init__(parent, manager=manager, quickplot=quickplot) 
    1919        self.parent = parent 
     20        self.addText = AddText(self) 
    2021 
    2122    @property 
     
    8485        ax.set_yscale(self.yscale) 
    8586 
     87        # define the ranges 
     88        self.setRange = SetGraphRange(parent=self, 
     89            x_range=self.ax.get_xlim(), y_range=self.ax.get_ylim()) 
     90 
    8691        # refresh canvas 
    8792        self.canvas.draw() 
     
    155160        Show a dialog allowing adding custom text to the chart 
    156161        """ 
    157         self.addText = AddText(self) 
    158162        if self.addText.exec_() == QtGui.QDialog.Accepted: 
    159163            # Retrieve the new text, its font and color 
     
    208212        """ 
    209213        # min and max of data 
    210         x_range = self.ax.get_xlim() 
    211         y_range = self.ax.get_ylim() 
    212         self.setRange = SetGraphRange(parent=self, 
    213             x_range=x_range, y_range=y_range) 
    214214        if self.setRange.exec_() == QtGui.QDialog.Accepted: 
    215215            x_range = self.setRange.xrange() 
  • 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.