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

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since b8dccb8 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
RevLine 
[da9a0722]1import sys
2import unittest
3import numpy as np
4
5from unittest.mock import MagicMock
6
7from PyQt5 import QtGui, QtCore, QtWidgets
[a90c9c5]8from PyQt5.QtTest import QTest
[da9a0722]9
10# set up import paths
11import path_prepare
12
13import sas.qtgui.Utilities.ObjectLibrary as ObjectLibrary
[a90c9c5]14import sas.qtgui.Utilities.GuiUtils as GuiUtils
15from sas.qtgui.Plotting.PlotterData import Data1D
[da9a0722]16
17# Local
18from sas.qtgui.Perspectives.Fitting.ConstraintWidget import ConstraintWidget
[14ec91c5]19from sas.qtgui.Perspectives.Fitting.Constraint import Constraint
[a90c9c5]20from sas.qtgui.Perspectives.Fitting.FittingPerspective import FittingWindow
[da9a0722]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'''
[a90c9c5]29        class dummy_manager(object):
30            def communicator(self):
31                return GuiUtils.Communicate()
[80468f6]32            communicate = GuiUtils.Communicate()
[da9a0722]33
[a90c9c5]34        '''Create the perspective'''
35        self.perspective = FittingWindow(dummy_manager())
[80468f6]36        ConstraintWidget.updateSignalsFromTab = MagicMock()
[a90c9c5]37
38        self.widget = ConstraintWidget(parent=self.perspective)
[da9a0722]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)
[a90c9c5]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)
[3b3b40b]72        QtWidgets.QApplication.processEvents()
[a90c9c5]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)
[3b3b40b]79        QtWidgets.QApplication.processEvents()
[a90c9c5]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
[da9a0722]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))
[a90c9c5]96        self.assertFalse(self.widget.isTabImportable("BatchTab1"))
[da9a0722]97        self.assertFalse(self.widget.isTabImportable("BatchTab"))
98
[a90c9c5]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])
[da9a0722]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.