source: sasview/src/sas/qtgui/Perspectives/Fitting/UnitTesting/ConstraintWidgetTest.py @ f3e5956

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since f3e5956 was 80468f6, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Fixed a few unit test files

  • Property mode set to 100644
File size: 4.3 KB
Line 
1import sys
2import unittest
3import numpy as np
4
5from unittest.mock import MagicMock
6
7from PyQt5 import QtGui, QtCore, QtWidgets
8from PyQt5.QtTest import QTest
9
10# set up import paths
11import path_prepare
12
13import sas.qtgui.Utilities.ObjectLibrary as ObjectLibrary
14import sas.qtgui.Utilities.GuiUtils as GuiUtils
15from sas.qtgui.Plotting.PlotterData import Data1D
16
17# Local
18from sas.qtgui.Perspectives.Fitting.ConstraintWidget import ConstraintWidget
19from sas.qtgui.Perspectives.Fitting.Constraint import Constraint
20from sas.qtgui.Perspectives.Fitting.FittingPerspective import FittingWindow
21
22if not QtWidgets.QApplication.instance():
23    app = QtWidgets.QApplication(sys.argv)
24
25class ConstraintWidgetTest(unittest.TestCase):
26    '''Test the ConstraintWidget dialog'''
27    def setUp(self):
28        '''Create ConstraintWidget dialog'''
29        class dummy_manager(object):
30            def communicator(self):
31                return GuiUtils.Communicate()
32            communicate = GuiUtils.Communicate()
33
34        '''Create the perspective'''
35        self.perspective = FittingWindow(dummy_manager())
36        ConstraintWidget.updateSignalsFromTab = MagicMock()
37
38        self.widget = ConstraintWidget(parent=self.perspective)
39
40        # Example constraint object
41        self.constraint1 = Constraint(parent=None, param="test", value="7.0", min="0.0", max="inf", func="M1:sld")
42        self.constraint2 = Constraint(parent=None, param="poop", value="7.0", min="0.0", max="inf", func="7.0")
43
44    def tearDown(self):
45        '''Destroy the GUI'''
46        self.widget.close()
47        self.widget = None
48
49    def testDefaults(self):
50        '''Test the GUI in its default state'''
51        self.assertIsInstance(self.widget, QtWidgets.QWidget)
52        # Default title
53        self.assertEqual(self.widget.windowTitle(), "Constrained and Simultaneous Fit")
54        # Dicts
55        self.assertIsInstance(self.widget.available_constraints, dict)
56        self.assertIsInstance(self.widget.available_tabs, dict)
57        # TableWidgets
58        self.assertEqual(self.widget.tblTabList.columnCount(), 4)
59        self.assertEqual(self.widget.tblConstraints.columnCount(), 1)
60        # Data accept
61        self.assertFalse(self.widget.acceptsData())
62        # By default, the constraint table is disabled
63        self.assertFalse(self.widget.tblConstraints.isEnabled())
64
65    def testOnFitTypeChange(self):
66        ''' test the single/batch fit switch '''
67        self.widget.initializeFitList = MagicMock()
68        # Assure current type is Single
69        self.assertEqual(self.widget.currentType, "FitPage")
70        # click on "batch"
71        QTest.mouseClick(self.widget.btnBatch, QtCore.Qt.LeftButton)
72        QtWidgets.QApplication.processEvents()
73        # See what the current type is now
74        self.assertEqual(self.widget.currentType, "BatchPage")
75        # See if the list is getting initialized
76        self.assertTrue(self.widget.initializeFitList.called)
77        # Go back to single fit
78        QTest.mouseClick(self.widget.btnSingle, QtCore.Qt.LeftButton)
79        QtWidgets.QApplication.processEvents()
80        # See what the current type is now
81        self.assertEqual(self.widget.currentType, "FitPage")
82
83    def testGetTabsForFit(self):
84        ''' Test the fitting tab list '''
85        self.assertEqual(self.widget.getTabsForFit(),[])
86        # Add some tabs
87        pass
88
89    def testIsTabImportable(self):
90        ''' tab checks for consistency '''
91        test_tab = QtCore.QObject()
92        test_tab.data = self.constraint1
93        ObjectLibrary.getObject = MagicMock(return_value=test_tab)
94
95        self.assertFalse(self.widget.isTabImportable(None))
96        self.assertFalse(self.widget.isTabImportable("BatchTab1"))
97        self.assertFalse(self.widget.isTabImportable("BatchTab"))
98
99    def testOnTabCellEdit(self):
100        ''' test what happens on monicker edit '''
101        # Mock the datafromitem() call from FittingWidget
102        data = Data1D(x=[1,2], y=[1,2])
103        GuiUtils.dataFromItem = MagicMock(return_value=data)
104        item = QtGui.QStandardItem("test")
105        self.perspective.addFit([item])
106
107    def testUpdateFitLine(self):
108        ''' See if the fit table row can be updated '''
109        pass
110
111    def testUpdateFitList(self):
112        ''' see if the fit table can be updated '''
113        pass
114
115    def testUpdateConstraintList(self):
116        ''' see if the constraint table can be updated '''
117        pass
118
119
Note: See TracBrowser for help on using the repository browser.