Ignore:
Timestamp:
Dec 14, 2016 2:19:57 AM (5 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:
ab9984e
Parents:
3a0ce4f
Message:

Addded tests for raised exceptions

File:
1 edited

Legend:

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

    r3a0ce4f rdebf5c3  
    3838        self.widget.onHelp() 
    3939 
    40     def testCalculateSlitSize(self): 
    41         """ User entered compound calculations and subsequent reset""" 
    42  
    43         filename = "beam_profile.DAT" 
    44         loader = Loader() 
    45         data = loader.load(filename) 
    46  
    47         self.widget.calculateSlitSize(data) 
    48         # The value "5.5858" was obtained by manual calculation. 
    49         # It turns out our slit length is FWHM/2 
    50         self.assertAlmostEqual(float(self.widget.slit_length_out.text()), 5.5858/2, 3) 
    51  
    52     def testCalculateSlitSize2D(self): 
    53         """ User entered compound calculations and subsequent reset""" 
    54  
    55         #TODO: Test for 2D and check if exception is being raised 
    56         filename = "beam_profile.DAT" 
    57         loader = Loader() 
    58         data = loader.load(filename) 
    59  
    60         self.widget.calculateSlitSize(data) 
    61         # The value "5.5858" was obtained by manual calculation. 
    62         # It turns out our slit length is FWHM/2 
    63         self.assertAlmostEqual(float(self.widget.slit_length_out.text()), 5.5858/2, 3) 
    64  
    65     # def testDataEntryNumbers(self): 
    66     #      """ User entered compound calculations and subsequent reset""" 
    67     # 
    68     #      self.widget.data_file.clear() 
    69     #      self.widget.data_file.insert("beam profile.DAT") 
    70     #      # 
    71     #      # Push Compute with the left mouse button 
    72     #      computeButton = self.widget.computeButton 
    73     #      QTest.mouseClick(computeButton, Qt.LeftButton) 
    74     #      self.assertEqual(self.widget.lengthscale_out.text(), '6.283') 
    75  
    7640    def testBrowseButton(self): 
    7741        browseButton = self.widget.browseButton 
     
    10064        QtGui.QFileDialog.getOpenFileName.assert_called_once() 
    10165 
    102     # def testDataEntryNumbers(self): 
    103     #     """ User entered compound calculations and subsequent reset""" 
    104     # 
    105     #     self.widget.data_file.clear() 
    106     #     self.widget.data_file.insert("beam profile.DAT") 
    107     #     # 
    108     #     # Push Compute with the left mouse button 
    109     #     computeButton = self.widget.computeButton 
    110     #     QTest.mouseClick(computeButton, Qt.LeftButton) 
    111     #     self.assertEqual(self.widget.lengthscale_out.text(), '6.283') 
    112     # 
    113     # 
    114     # def testComplexEntryLetters(self): 
    115     #     """ User entered compound calculations and subsequent reset""" 
    116     # 
    117     #     self.widget.deltaq_in.insert("xyz") 
    118     # 
    119     #     # Push Compute with the left mouse button 
    120     #     computeButton = self.widget.computeButton 
    121     #     QTest.mouseClick(computeButton, Qt.LeftButton) 
    122     #     self.assertEqual(self.widget.lengthscale_out.text(), '') 
     66 
     67    def testCalculateSlitSize(self): 
     68        """ Test slit size calculated value """ 
     69 
     70        filename = "beam_profile.DAT" 
     71        loader = Loader() 
     72        data = loader.load(filename) 
     73 
     74        self.widget.calculateSlitSize(data) 
     75        # The value "5.5858" was obtained by manual calculation. 
     76        # It turns out our slit length is FWHM/2 
     77        self.assertAlmostEqual(float(self.widget.slit_length_out.text()), 5.5858/2, 3) 
     78 
     79    def testWrongInput(self): 
     80        """ Test on wrong input data """ 
     81 
     82        filename = "Dec07031.ASC" 
     83        loader = Loader() 
     84        data = loader.load(filename) 
     85        self.assertRaisesRegexp(Exception, 
     86                                "Slit Length cannot be computed for 2D Data", 
     87                                self.widget.calculateSlitSize, data) 
     88 
     89        filename = "empty_file.txt" 
     90        loader = Loader() 
     91        data = loader.load(filename) 
     92        self.assertRaisesRegexp(RuntimeError, 
     93                                "ERROR: Data hasn't been loaded correctly", 
     94                                self.widget.calculateSlitSize, data) 
     95 
     96        data = None 
     97        self.assertRaisesRegexp(RuntimeError, 
     98                                "ERROR: Data hasn't been loaded correctly", 
     99                                self.widget.calculateSlitSize, data) 
     100 
    123101 
    124102if __name__ == "__main__": 
Note: See TracChangeset for help on using the changeset viewer.