Changeset 28a84e9 in sasview for src/sas/qtgui/UnitTesting


Ignore:
Timestamp:
Jul 30, 2016 4:22:07 PM (8 years ago)
Author:
Piotr Rozyczko <piotr.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:
39551a68
Parents:
4b71e91
Message:

More context menu functionality in Data Explorer

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

Legend:

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

    r8cb6cd6 r28a84e9  
    619619            self.form.updateModelFromPerspective(bad_item) 
    620620 
     621    def testContextMenu(self): 
     622        """ 
     623        See if the context menu is present 
     624        """ 
     625        # get Data1D 
     626        p_file=["cyl_400_20.txt"] 
     627        # Read in the file 
     628        output, message = self.form.readData(p_file) 
     629        self.form.loadComplete((output, message)) 
     630 
     631        # Pick up the treeview index corresponding to that file 
     632        index = self.form.treeView.indexAt(QtCore.QPoint(5,5)) 
     633        self.form.show() 
     634 
     635        # Find out the center pointof the treeView row 
     636        rect = self.form.treeView.visualRect(index).center() 
     637 
     638        self.form.context_menu.exec_ = MagicMock() 
     639 
     640        # Move the mouse pointer to the first row 
     641        QTest.mouseMove(self.form.treeView.viewport(), pos=rect) 
     642 
     643        # This doesn't invoke the action/signal. Investigate why? 
     644        # QTest.mouseClick(self.form.treeView.viewport(), Qt.RightButton, pos=rect) 
     645 
     646        # Instead, send the signal directly 
     647        self.form.treeView.customContextMenuRequested.emit(rect) 
     648 
     649        # app.exec_() # debug 
     650 
     651        # See that the menu has been shown 
     652        self.form.context_menu.exec_.assert_called_once() 
     653 
     654    def testShowDataInfo(self): 
     655        """ 
     656        Test of the showDataInfo method 
     657        """ 
     658        # get Data1D 
     659        p_file=["cyl_400_20.txt"] 
     660        # Read in the file 
     661        output, message = self.form.readData(p_file) 
     662        self.form.loadComplete((output, message)) 
     663 
     664        # select the data 
     665        self.form.treeView.selectAll() 
     666 
     667        # Call the tested method 
     668        self.form.showDataInfo() 
     669 
     670        # Test the properties 
     671        self.assertTrue(self.form.txt_widget.isReadOnly()) 
     672        self.assertEqual(self.form.txt_widget.windowTitle(), "Data Info: cyl_400_20.txt") 
     673        self.assertIn("Waveln_max", self.form.txt_widget.toPlainText()) 
     674 
     675        # Slider moved all the way up 
     676        self.assertEqual(self.form.txt_widget.verticalScrollBar().sliderPosition(), 0) 
     677 
     678    def testSaveDataAs(self): 
     679        """ 
     680        Test the Save As context menu action 
     681        """ 
     682        # get Data1D 
     683        p_file=["cyl_400_20.txt"] 
     684        # Read in the file 
     685        output, message = self.form.readData(p_file) 
     686        self.form.loadComplete((output, message)) 
     687 
     688        # select the data 
     689        self.form.treeView.selectAll() 
     690 
     691        QFileDialog.getSaveFileName = MagicMock() 
     692 
     693        # Call the tested method 
     694        self.form.saveDataAs() 
     695        QFileDialog.getSaveFileName.assert_called_with( 
     696                                caption="Save As", 
     697                                directory='cyl_400_20_out.txt', 
     698                                filter='Text files (*.txt);;CanSAS 1D files(*.xml)', 
     699                                parent=None) 
     700        QFileDialog.getSaveFileName.assert_called_once() 
     701 
     702        # get Data2D 
     703        p_file=["Dec07031.ASC"] 
     704        # Read in the file 
     705        output, message = self.form.readData(p_file) 
     706        self.form.loadComplete((output, message)) 
     707 
     708        # select the data 
     709        index = self.form.model.index(1, 0) 
     710        selmodel = self.form.treeView.selectionModel() 
     711        selmodel.setCurrentIndex(index, QItemSelectionModel.NoUpdate) 
     712        selmodel.select(index, QItemSelectionModel.Select|QItemSelectionModel.Rows) 
     713 
     714        QFileDialog.getSaveFileName = MagicMock() 
     715 
     716        # Call the tested method 
     717        self.form.saveDataAs() 
     718        QFileDialog.getSaveFileName.assert_called_with( 
     719                                caption="Save As", 
     720                                directory='Dec07031_out.dat', 
     721                                filter='IGOR/DAT 2D file in Q_map (*.dat)', 
     722                                parent=None) 
     723        QFileDialog.getSaveFileName.assert_called_once() 
     724 
     725 
    621726if __name__ == "__main__": 
    622727    unittest.main() 
  • src/sas/qtgui/UnitTesting/GuiUtilsTest.py

    re540cd2 r28a84e9  
    1313# Tested module 
    1414from GuiUtils import * 
     15 
     16class FakeData(object): 
     17    '''Data1D/2D object for testing''' 
     18    def __init__(self): 
     19        self.x = [] 
     20        self.y = [] 
    1521 
    1622class GuiUtilsTest(unittest.TestCase): 
     
    189195            openLink(bad_url3) 
    190196 
     197    def testRetrieveData1d(self): 
     198        """ 
     199        """ 
     200        self.assertRaises(retrieveData1d("BOOP")) 
     201 
     202        # data = FakeData()         
     203        pass 
     204 
     205    def testRetrieveData2d(self): 
     206        """ 
     207        """ 
     208        pass 
     209 
     210    def testOnTXTSave(self): 
     211        """ 
     212        """ 
     213        pass 
     214 
     215    def testSaveData1D(self): 
     216        """ 
     217        """ 
     218        pass 
     219 
     220    def testSaveData2D(self): 
     221        """ 
     222        """ 
     223        pass 
     224 
    191225if __name__ == "__main__": 
    192226    unittest.main() 
Note: See TracChangeset for help on using the changeset viewer.