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

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

Removed qtgui dependency on sasgui and wx SASVIEW-590

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