Ignore:
Timestamp:
Nov 22, 2017 7:49:06 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:
cb4d219
Parents:
0580c77
Message:

Add "delete" to the data explorer context menu

File:
1 edited

Legend:

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

    • Property mode changed from 100755 to 100644
    r53c771e rc6fb57c  
    2626import sas.qtgui.Plotting.PlotHelper as PlotHelper 
    2727 
    28 if not QApplication.instance(): 
    29     app = QApplication(sys.argv) 
     28#if not QApplication.instance(): 
     29app = QApplication(sys.argv) 
    3030 
    3131class DataExplorerTest(unittest.TestCase): 
     
    684684        self.form.treeView.customContextMenuRequested.emit(rect) 
    685685 
    686         # app.exec_() # debug 
    687  
    688686        # See that the menu has been shown 
    689687        self.form.context_menu.exec_.assert_called_once() 
     
    805803        pass 
    806804 
     805    def notestDeleteItem(self): 
     806        """ 
     807        Delete selected item from data explorer 
     808        """ 
     809 
     810        # Mock the confirmation dialog with return=No 
     811        QMessageBox.question = MagicMock(return_value=QMessageBox.No) 
     812 
     813        # Populate the model 
     814        filename = ["cyl_400_20.txt", "cyl_400_20.txt", "cyl_400_20.txt"] 
     815        self.form.readData(filename) 
     816 
     817        # Assure the model contains three items 
     818        self.assertEqual(self.form.model.rowCount(), 3) 
     819 
     820        # Add an item to first file item 
     821        item1 = QtGui.QStandardItem("test") 
     822        item1.setCheckable(True) 
     823        self.form.model.item(0).appendRow(item1) 
     824 
     825        # Check the new item is in 
     826 
     827        self.assertTrue(self.form.model.item(0).hasChildren()) 
     828 
     829        #select_item = self.form.model.item(0).child(3) 
     830        select_item = self.form.model.item(0) 
     831        select_index = self.form.model.indexFromItem(select_item) 
     832 
     833        # Open up items 
     834        self.form.current_view.expandAll() 
     835 
     836        # Select the newly created item 
     837        self.form.current_view.selectionModel().select(select_index, QtCore.QItemSelectionModel.Rows) 
     838 
     839        # Attempt at deleting 
     840        self.form.deleteItem() 
     841 
     842        # Test the warning dialog called once 
     843        self.assertTrue(QMessageBox.question.called) 
     844 
     845        # Assure the model still contains the items 
     846        self.assertEqual(self.form.model.rowCount(), 3) 
     847 
     848        # Now, mock the confirmation dialog with return=Yes 
     849        QMessageBox.question = MagicMock(return_value=QMessageBox.Yes) 
     850 
     851        # Select the newly created item 
     852        self.form.current_view.selectionModel().select(select_index, QtCore.QItemSelectionModel.Rows) 
     853        # delete it. now for good 
     854        self.form.deleteItem() 
     855 
     856        # Test the warning dialog called once 
     857        self.assertTrue(QMessageBox.question.called) 
     858 
     859        # Assure the model contains no items 
     860        self.assertEqual(self.form.model.rowCount(), 3) 
     861 
    807862 
    808863if __name__ == "__main__": 
Note: See TracChangeset for help on using the changeset viewer.