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

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 d7ff531 was 2155824, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

Updated/fixed unit tests after recent functionality changes

  • Property mode set to 100755
File size: 3.3 KB
Line 
1import sys
2import unittest
3import webbrowser
4
5from PyQt4 import QtGui
6from PyQt4 import QtTest
7from PyQt4 import QtCore
8from mock import MagicMock
9
10# set up import paths
11import sas.qtgui.path_prepare
12
13# Local
14import sas.qtgui.GuiUtils as GuiUtils
15from sas.sasgui.guiframe.dataFitting import Data1D
16
17from sas.qtgui.Perspectives.Fitting.FittingPerspective import FittingWindow
18
19app = QtGui.QApplication(sys.argv)
20
21class FittingPerspectiveTest(unittest.TestCase):
22    '''Test the Fitting Perspective'''
23    def setUp(self):
24        class dummy_manager(object):
25            def communicator(self):
26                return GuiUtils.Communicate()
27            def communicate(self):
28                return GuiUtils.Communicate()
29
30        '''Create the perspective'''
31        self.widget = FittingWindow(dummy_manager())
32
33    def tearDown(self):
34        '''Destroy the perspective'''
35        self.widget.close()
36        self.widget = None
37
38    def testDefaults(self):
39        '''Test the GUI in its default state'''
40        self.assertIsInstance(self.widget, QtGui.QWidget)
41        self.assertIn("Fit panel", self.widget.windowTitle())
42        self.assertEqual(self.widget.optimizer, "DREAM")
43        self.assertEqual(len(self.widget.tabs), 1)
44        self.assertEqual(self.widget.maxIndex, 1)
45        self.assertEqual(self.widget.tabName(), "FitPage1")
46
47    def testAddTab(self):
48        '''Add a tab and test it'''
49
50        # Add an empty tab
51        self.widget.addFit(None)
52        self.assertEqual(len(self.widget.tabs), 2)
53        self.assertEqual(self.widget.tabName(), "FitPage2")
54        self.assertEqual(self.widget.maxIndex, 2)
55
56    def testCloseTab(self):
57        '''Delete a tab and test'''
58        # Add an empty tab
59        self.widget.addFit(None)
60
61        # Remove the original tab
62        self.widget.tabCloses(1)
63        self.assertEqual(len(self.widget.tabs), 1)
64        self.assertEqual(self.widget.maxIndex, 2)
65        self.assertEqual(self.widget.tabName(), "FitPage2")
66
67        # Attemtp to remove the last tab
68        self.widget.tabCloses(1)
69        # The tab should still be there
70        self.assertEqual(len(self.widget.tabs), 1)
71        self.assertEqual(self.widget.maxIndex, 2)
72        self.assertEqual(self.widget.tabName(), "FitPage2")
73
74    def testAllowBatch(self):
75        '''Assure the perspective allows multiple datasets'''
76        self.assertTrue(self.widget.allowBatch())
77
78    def testSetData(self):
79        ''' Assure that setting data is correct'''
80        with self.assertRaises(AssertionError):
81            self.widget.setData(None)
82
83        with self.assertRaises(AttributeError):
84            self.widget.setData("BOOP")
85
86        # Mock the datafromitem() call from FittingWidget
87        data = Data1D(x=[1,2], y=[1,2])
88        GuiUtils.dataFromItem = MagicMock(return_value=data)
89
90        item = QtGui.QStandardItem("test")
91        self.widget.setData([item])
92
93        # First tab should accept data
94        self.assertEqual(len(self.widget.tabs), 1)
95
96        # Add another set of data
97        self.widget.setData([item])
98
99        # Now we should have two tabs
100        self.assertEqual(len(self.widget.tabs), 2)
101
102        # Add two more items in a list
103        self.widget.setData([item, item])
104
105        # Check for 4 tabs
106        self.assertEqual(len(self.widget.tabs), 4)
107
108
109if __name__ == "__main__":
110    unittest.main()
Note: See TracBrowser for help on using the repository browser.