source: sasview/src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingPerspectiveTest.py @ b9c4c1e1

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since b9c4c1e1 was b9c4c1e1, checked in by wojciech, 3 years ago

Unit tests added for selecting models, categories and structure factors

  • Property mode set to 100644
File size: 5.1 KB
Line 
1import sys
2import unittest
3
4from PyQt4 import QtGui
5from PyQt4 import QtTest
6from PyQt4 import QtCore
7from mock import MagicMock
8
9# Local
10from FittingPerspective import FittingWindow
11
12app = QtGui.QApplication(sys.argv)
13
14class FittingPerspectiveTest(unittest.TestCase):
15    """Test the Main Window GUI"""
16    def setUp(self):
17        """Create the GUI"""
18
19        self.widget = FittingWindow(None)
20
21    def tearDown(self):
22        """Destroy the GUI"""
23        self.widget.close()
24        self.widget = None
25
26    def testDefaults(self):
27        """Test the GUI in its default state"""
28        self.assertIsInstance(self.widget, QtGui.QWidget)
29        self.assertEqual(self.widget.windowTitle(), "Fitting")
30        self.assertEqual(self.widget.sizePolicy().Policy(), QtGui.QSizePolicy.Fixed)
31
32    def testSelectCategory(self):
33        """
34        Test if categories have been load properly
35        :return:
36        """
37        fittingWindow =  FittingWindow(None)
38
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)
48
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
116if __name__ == "__main__":
117    unittest.main()
Note: See TracBrowser for help on using the repository browser.