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

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

More code review changes

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