source: sasview/calculatorview/test/utest_gui_sld.py @ 66bfacf

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 66bfacf was 66bfacf, checked in by Gervaise Alina <gervyh@…>, 14 years ago

add a unitest for gui sld calculator

  • Property mode set to 100644
File size: 7.7 KB
Line 
1"""
2test gui for sld calculator
3"""
4
5import unittest
6import wx
7
8H2O_DENSITY = 1.0
9WAVELENGTH = 6.0
10
11class testTextCtrl(unittest.TestCase):
12    """
13    txtctrl should have a pink background when the result are incorrect
14    and white when reset or correct value
15    """
16    def setUp(self):
17        """
18        Create an Sld calculator
19        """
20        self.app = wx.App()
21        from sans.perspectives.calculator.sld_panel import SldWindow
22        self.sld_frame = SldWindow()
23       
24    def testCompoundTextCtrl(self):
25        """
26        Test Compund textCtrl
27        """
28        #add  invalid value for compound
29        self.sld_frame.panel.compound_ctl.SetValue("String not in table")
30        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
31        id = self.sld_frame.panel.button_calculate.GetId()
32        clickEvent = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, id)
33        self.sld_frame.panel.ProcessEvent(clickEvent)
34        bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour()
35        self.assert_(bkg.GetAsString() == 'pink')
36        #compute invariant without entering a value for compound
37        self.sld_frame.panel.compound_ctl.SetValue("")
38        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
39        self.sld_frame.panel.ProcessEvent(clickEvent)
40        bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour()
41        self.assert_(bkg.GetAsString() == 'pink')
42        #compute invariant without entering a value for compound
43        self.sld_frame.panel.compound_ctl.SetValue("H2O")
44        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
45        self.sld_frame.panel.ProcessEvent(clickEvent)
46        bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour()
47        self.assert_(bkg.GetAsString() == 'white')
48       
49    def testDensityTextCtrl(self):
50        """
51        Test Density textCtrl
52       
53        """
54        #add  invalid value for density
55        self.sld_frame.panel.compound_ctl.SetValue("H2O")
56        self.sld_frame.panel.density_ctl.SetValue("invalid density")
57        id = self.sld_frame.panel.button_calculate.GetId()
58        clickEvent = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, id)
59        self.sld_frame.panel.ProcessEvent(clickEvent)
60        bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour()
61        self.assert_(bkg.GetAsString() == 'pink')
62        #compute invariant without entering a value for density
63        self.sld_frame.panel.compound_ctl.SetValue("H2O")
64        self.sld_frame.panel.density_ctl.SetValue("")
65        self.sld_frame.panel.ProcessEvent(clickEvent)
66        bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour()
67        self.assert_(bkg.GetAsString() == 'pink')
68        #compute invariant without entering a value for density
69        self.sld_frame.panel.compound_ctl.SetValue("H2O")
70        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
71        self.sld_frame.panel.ProcessEvent(clickEvent)
72        bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour()
73        self.assert_(bkg.GetAsString() == 'white')
74       
75    def testWavelengthTextCtrl(self):
76        """
77        Test wavelength textCtrl
78       
79        """
80        #add  invalid value for wavelength
81        self.sld_frame.panel.compound_ctl.SetValue("H2O")
82        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
83        self.sld_frame.panel.wavelength_ctl.SetValue("invalid wavelength")
84        id = self.sld_frame.panel.button_calculate.GetId()
85        clickEvent = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, id)
86        self.sld_frame.panel.ProcessEvent(clickEvent)
87        bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour()
88        self.assert_(bkg.GetAsString() == 'pink')
89        #compute invariant without entering a value for wavelegnth
90        self.sld_frame.panel.compound_ctl.SetValue("H2O")
91        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
92        self.sld_frame.panel.wavelength_ctl.SetValue("")
93        self.sld_frame.panel.ProcessEvent(clickEvent)
94        bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour()
95        value = self.sld_frame.panel.wavelength_ctl.GetValue()
96        self.assert_(bkg.GetAsString() == 'white')
97        self.assert_(float(value) == WAVELENGTH)
98        #compute invariant with all correct inputs value
99        self.sld_frame.panel.compound_ctl.SetValue("H2O")
100        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
101        self.sld_frame.panel.wavelength_ctl.SetValue(str(WAVELENGTH/2))
102        self.sld_frame.panel.ProcessEvent(clickEvent)
103        bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour()
104        value = self.sld_frame.panel.wavelength_ctl.GetValue()
105        self.assert_(bkg.GetAsString() == 'white')
106        self.assert_(float(value) == WAVELENGTH/2)
107       
108    def testSomeCombination(self):
109        """
110        Test other error
111        """
112        #only wavelength is invalid
113        self.sld_frame.panel.compound_ctl.SetValue("H2O")
114        self.sld_frame.panel.density_ctl.SetValue(str(H2O_DENSITY))
115        self.sld_frame.panel.wavelength_ctl.SetValue("invalid wavelength")
116        id = self.sld_frame.panel.button_calculate.GetId()
117        clickEvent = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, id)
118        self.sld_frame.panel.ProcessEvent(clickEvent)
119        cp_bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour()
120        self.assert_(cp_bkg.GetAsString() == 'white')
121        ds_bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour()
122        self.assert_(ds_bkg.GetAsString() == 'white')
123        wv_bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour()
124        self.assert_(wv_bkg.GetAsString() == 'pink')
125        #density, wavelength is invalid
126        self.sld_frame.panel.compound_ctl.SetValue("H2O")
127        self.sld_frame.panel.density_ctl.SetValue("invalid density")
128        self.sld_frame.panel.wavelength_ctl.SetValue("invalid wavelength")
129        id = self.sld_frame.panel.button_calculate.GetId()
130        clickEvent = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, id)
131        self.sld_frame.panel.ProcessEvent(clickEvent)
132        cp_bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour()
133        self.assert_(cp_bkg.GetAsString() == 'white')
134        ds_bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour()
135        self.assert_(ds_bkg.GetAsString() == 'pink')
136        wv_bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour()
137        self.assert_(wv_bkg.GetAsString() == 'pink')
138        #density, wavelength is invalid
139        self.sld_frame.panel.compound_ctl.SetValue("invalid compound")
140        self.sld_frame.panel.density_ctl.SetValue("invalid density")
141        self.sld_frame.panel.wavelength_ctl.SetValue("")
142        id = self.sld_frame.panel.button_calculate.GetId()
143        clickEvent = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, id)
144        self.sld_frame.panel.ProcessEvent(clickEvent)
145        cp_bkg = self.sld_frame.panel.compound_ctl.GetBackgroundColour()
146        self.assert_(cp_bkg.GetAsString() == 'pink')
147        ds_bkg = self.sld_frame.panel.density_ctl.GetBackgroundColour()
148        self.assert_(ds_bkg.GetAsString() == 'pink')
149        wv_bkg = self.sld_frame.panel.wavelength_ctl.GetBackgroundColour()
150        self.assert_(wv_bkg.GetAsString() == 'white')
151        value = self.sld_frame.panel.wavelength_ctl.GetValue()
152        self.assert_(float(value) == WAVELENGTH)
153
154       
155       
156    def tearDown(self):
157        """
158        Destroy the sld calculator frame
159        """
160        self.sld_frame.Close()
161        self.app.MainLoop()
162       
163if __name__ == "__main__":
164    unittest.main()
Note: See TracBrowser for help on using the repository browser.