Ignore:
Timestamp:
Feb 22, 2017 5:51:53 AM (8 years ago)
Author:
wojciech
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:
84be77e
Parents:
0efe791
Message:

Unit tests added for selecting models, categories and structure factors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingPerspectiveTest.py

    r2162fa0 rb9c4c1e1  
    2121    def tearDown(self): 
    2222        """Destroy the GUI""" 
     23        self.widget.close() 
    2324        self.widget = None 
    2425 
    2526    def testDefaults(self): 
    2627        """Test the GUI in its default state""" 
    27         self.assertIsInstance(self.widget, QtGui.QMainWindow) 
    28         self.assertIsInstance(self.widget.centralWidget(), QtGui.QWorkspace) 
     28        self.assertIsInstance(self.widget, QtGui.QWidget) 
     29        self.assertEqual(self.widget.windowTitle(), "Fitting") 
     30        self.assertEqual(self.widget.sizePolicy().Policy(), QtGui.QSizePolicy.Fixed) 
    2931 
    30     def testExit(self): 
     32    def testSelectCategory(self): 
    3133        """ 
    32         Test that the custom exit method is called on shutdown 
     34        Test if categories have been load properly 
     35        :return: 
    3336        """ 
    34         # Must mask sys.exit, otherwise the whole testing process stops. 
    35         sys.exit = MagicMock() 
    36         QtGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.Yes) 
     37        fittingWindow =  FittingWindow(None) 
    3738 
    38         # Open, then close the main window 
    39         tmp_main = FittingWindow(None) 
    40         tmp_main.close() 
     39        #Test loading from json categories 
     40        category_list = fittingWindow.master_category_dict.keys() 
     41        self.assertTrue("Cylinder" in category_list) 
     42        self.assertTrue("Ellipsoid" in category_list) 
     43        self.assertTrue("Lamellae" in category_list) 
     44        self.assertTrue("Paracrystal" in category_list) 
     45        self.assertTrue("Parallelepiped" in category_list) 
     46        self.assertTrue("Shape Independent" in category_list) 
     47        self.assertTrue("Sphere" in category_list) 
    4148 
    42         # See that the MessageBox method got called 
    43         self.assertTrue(QtGui.QMessageBox.question.called) 
    44         
     49        #Test for existence in combobox 
     50        self.assertNotEqual(fittingWindow.cbCategory.findText("Cylinder"),-1) 
     51        self.assertNotEqual(fittingWindow.cbCategory.findText("Ellipsoid"),-1) 
     52        self.assertNotEqual(fittingWindow.cbCategory.findText("Lamellae"),-1) 
     53        self.assertNotEqual(fittingWindow.cbCategory.findText("Paracrystal"),-1) 
     54        self.assertNotEqual(fittingWindow.cbCategory.findText("Parallelepiped"),-1) 
     55        self.assertNotEqual(fittingWindow.cbCategory.findText("Shape Independent"),-1) 
     56        self.assertNotEqual(fittingWindow.cbCategory.findText("Sphere"),-1) 
     57 
     58        #Test what is current text in the combobox 
     59        self.assertTrue(fittingWindow.cbCategory.currentText(), "Cylinder") 
     60 
     61    def testSelectModel(self): 
     62        """ 
     63        Test if models have been loaded properly 
     64        :return: 
     65        """ 
     66        fittingWindow =  FittingWindow(None) 
     67 
     68        #Test loading from json categories 
     69        model_list = fittingWindow.master_category_dict["Cylinder"] 
     70        self.assertTrue(['cylinder', True] in model_list) 
     71        self.assertTrue(['core_shell_cylinder', True] in model_list) 
     72        self.assertTrue(['barbell', True] in model_list) 
     73        self.assertTrue(['core_shell_bicelle', True] in model_list) 
     74        self.assertTrue(['flexible_cylinder', True] in model_list) 
     75        self.assertTrue(['flexible_cylinder_elliptical', True] in model_list) 
     76        self.assertTrue(['pearl_necklace', True] in model_list) 
     77        self.assertTrue(['capped_cylinder', True] in model_list) 
     78        self.assertTrue(['elliptical_cylinder', True] in model_list) 
     79        self.assertTrue(['pringle', True] in model_list) 
     80        self.assertTrue(['hollow_cylinder', True] in model_list) 
     81        self.assertTrue(['core_shell_bicelle_elliptical', True] in model_list) 
     82        self.assertTrue(['stacked_disks', True] in model_list) 
     83 
     84        #Test for existence in combobox 
     85        self.assertNotEqual(fittingWindow.cbModel.findText("cylinder"),-1) 
     86        self.assertNotEqual(fittingWindow.cbModel.findText("core_shell_cylinder"),-1) 
     87        self.assertNotEqual(fittingWindow.cbModel.findText("barbell"),-1) 
     88        self.assertNotEqual(fittingWindow.cbModel.findText("core_shell_bicelle"),-1) 
     89        self.assertNotEqual(fittingWindow.cbModel.findText("flexible_cylinder"),-1) 
     90        self.assertNotEqual(fittingWindow.cbModel.findText("flexible_cylinder_elliptical"),-1) 
     91        self.assertNotEqual(fittingWindow.cbModel.findText("pearl_necklace"),-1) 
     92        self.assertNotEqual(fittingWindow.cbModel.findText("capped_cylinder"),-1) 
     93        self.assertNotEqual(fittingWindow.cbModel.findText("elliptical_cylinder"),-1) 
     94        self.assertNotEqual(fittingWindow.cbModel.findText("pringle"),-1) 
     95        self.assertNotEqual(fittingWindow.cbModel.findText("hollow_cylinder"),-1) 
     96        self.assertNotEqual(fittingWindow.cbModel.findText("core_shell_bicelle_elliptical"),-1) 
     97        self.assertNotEqual(fittingWindow.cbModel.findText("stacked_disks"),-1) 
     98 
     99 
     100    def testSelectStructureFactor(self): 
     101        """ 
     102        Test if structure factors have been loaded properly 
     103        :return: 
     104        """ 
     105        fittingWindow =  FittingWindow(None) 
     106 
     107        #Test for existence in combobox 
     108        self.assertNotEqual(fittingWindow.cbStructureFactor.findText("stickyhardsphere"),-1) 
     109        self.assertNotEqual(fittingWindow.cbStructureFactor.findText("hayter_msa"),-1) 
     110        self.assertNotEqual(fittingWindow.cbStructureFactor.findText("squarewell"),-1) 
     111        self.assertNotEqual(fittingWindow.cbStructureFactor.findText("hardsphere"),-1) 
     112 
     113        #Test what is current text in the combobox 
     114        self.assertTrue(fittingWindow.cbCategory.currentText(), "None") 
     115 
    45116if __name__ == "__main__": 
    46117    unittest.main() 
Note: See TracChangeset for help on using the changeset viewer.