[da9a0722] | 1 | import sys |
---|
| 2 | import unittest |
---|
| 3 | import numpy as np |
---|
| 4 | |
---|
| 5 | from unittest.mock import MagicMock |
---|
| 6 | |
---|
| 7 | from PyQt5 import QtGui, QtCore, QtWidgets |
---|
[a90c9c5] | 8 | from PyQt5.QtTest import QTest |
---|
[da9a0722] | 9 | |
---|
| 10 | # set up import paths |
---|
| 11 | import path_prepare |
---|
| 12 | |
---|
| 13 | import sas.qtgui.Utilities.ObjectLibrary as ObjectLibrary |
---|
[a90c9c5] | 14 | import sas.qtgui.Utilities.GuiUtils as GuiUtils |
---|
| 15 | from sas.qtgui.Plotting.PlotterData import Data1D |
---|
[da9a0722] | 16 | |
---|
| 17 | # Local |
---|
| 18 | from sas.qtgui.Perspectives.Fitting.ConstraintWidget import ConstraintWidget |
---|
[14ec91c5] | 19 | from sas.qtgui.Perspectives.Fitting.Constraint import Constraint |
---|
[a90c9c5] | 20 | from sas.qtgui.Perspectives.Fitting.FittingPerspective import FittingWindow |
---|
[da9a0722] | 21 | |
---|
| 22 | if not QtWidgets.QApplication.instance(): |
---|
| 23 | app = QtWidgets.QApplication(sys.argv) |
---|
| 24 | |
---|
| 25 | class 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 | |
---|