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

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 9f25bce was 811bec1, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

Started with unit tests for fitting widget SASVIEW-499

  • Property mode set to 100755
File size: 3.2 KB
RevLine 
[2162fa0]1import sys
2import unittest
[811bec1]3import webbrowser
[2162fa0]4
5from PyQt4 import QtGui
6from PyQt4 import QtTest
7from PyQt4 import QtCore
8from mock import MagicMock
9
[811bec1]10# set up import paths
11import sas.qtgui.path_prepare
12
[2162fa0]13# Local
[811bec1]14import sas.qtgui.GuiUtils as GuiUtils
15from sas.sasgui.guiframe.dataFitting import Data1D
16
17from sas.qtgui.Perspectives.Fitting.FittingPerspective import FittingWindow
[2162fa0]18
19app = QtGui.QApplication(sys.argv)
20
21class FittingPerspectiveTest(unittest.TestCase):
[811bec1]22    '''Test the Fitting Perspective'''
[2162fa0]23    def setUp(self):
[811bec1]24        class dummy_manager(object):
25            def communicator(self):
26                return GuiUtils.Communicate()
27            def communicate(self):
28                return GuiUtils.Communicate()
[2162fa0]29
[811bec1]30        '''Create the perspective'''
31        self.widget = FittingWindow(dummy_manager())
[2162fa0]32
33    def tearDown(self):
[811bec1]34        '''Destroy the perspective'''
[b9c4c1e1]35        self.widget.close()
[2162fa0]36        self.widget = None
37
38    def testDefaults(self):
[811bec1]39        '''Test the GUI in its default state'''
[b9c4c1e1]40        self.assertIsInstance(self.widget, QtGui.QWidget)
[811bec1]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        # Look at the data in tab
94        self.assertEqual(self.widget._model_item, item)
95
96        # First tab should accept data
97        self.assertEqual(len(self.widget.tabs), 1)
98
99        # Add another set of data
100        self.widget.setData([item])
101
102        # Now we should have two tabs
103        self.assertEqual(len(self.widget.tabs), 2)
104
[2162fa0]105
106if __name__ == "__main__":
107    unittest.main()
Note: See TracBrowser for help on using the repository browser.