[811bec1] | 1 | import sys |
---|
| 2 | import unittest |
---|
| 3 | |
---|
| 4 | from PyQt4 import QtGui |
---|
| 5 | from PyQt4 import QtTest |
---|
| 6 | from PyQt4 import QtCore |
---|
| 7 | from mock import MagicMock |
---|
| 8 | |
---|
| 9 | # set up import paths |
---|
| 10 | import sas.qtgui.path_prepare |
---|
| 11 | |
---|
| 12 | # Local |
---|
| 13 | from sas.qtgui.GuiUtils import * |
---|
| 14 | from sas.qtgui.Perspectives.Fitting.FittingWidget import * |
---|
| 15 | #from sas.qtgui.Perspectives.Fitting.FittingWidget import FittingWidget |
---|
| 16 | from sas.sasgui.guiframe.dataFitting import Data1D |
---|
| 17 | |
---|
| 18 | app = QtGui.QApplication(sys.argv) |
---|
| 19 | |
---|
| 20 | class dummy_manager(object): |
---|
| 21 | def communicate(self): |
---|
| 22 | return Communicate() |
---|
| 23 | |
---|
| 24 | class FittingWidgetTest(unittest.TestCase): |
---|
| 25 | """Test the fitting widget GUI""" |
---|
| 26 | |
---|
| 27 | def setUp(self): |
---|
| 28 | """Create the GUI""" |
---|
| 29 | self.widget = FittingWidget(dummy_manager()) |
---|
| 30 | |
---|
| 31 | def tearDown(self): |
---|
| 32 | """Destroy the GUI""" |
---|
| 33 | self.widget.close() |
---|
| 34 | self.widget = None |
---|
| 35 | |
---|
| 36 | def testDefaults(self): |
---|
| 37 | """Test the GUI in its default state""" |
---|
| 38 | self.assertIsInstance(self.widget, QtGui.QWidget) |
---|
| 39 | self.assertEqual(self.widget.windowTitle(), "Fitting") |
---|
| 40 | self.assertEqual(self.widget.sizePolicy().Policy(), QtGui.QSizePolicy.Fixed) |
---|
| 41 | self.assertIsInstance(self.widget.lstParams.model(), QtGui.QStandardItemModel) |
---|
| 42 | self.assertIsInstance(self.widget.lstPoly.model(), QtGui.QStandardItemModel) |
---|
| 43 | self.assertIsInstance(self.widget.lstMagnetic.model(), QtGui.QStandardItemModel) |
---|
| 44 | self.assertFalse(self.widget.cbModel.isEnabled()) |
---|
| 45 | self.assertFalse(self.widget.cbStructureFactor.isEnabled()) |
---|
| 46 | self.assertFalse(self.widget.cmdFit.isEnabled()) |
---|
| 47 | self.assertTrue(self.widget.acceptsData()) |
---|
| 48 | self.assertFalse(self.widget.data_is_loaded) |
---|
| 49 | |
---|
| 50 | def testSelectCategory(self): |
---|
| 51 | """ |
---|
| 52 | Test if model categories have been loaded properly |
---|
| 53 | """ |
---|
| 54 | fittingWindow = self.widget |
---|
| 55 | |
---|
| 56 | #Test loading from json categories |
---|
| 57 | category_list = fittingWindow.master_category_dict.keys() |
---|
| 58 | |
---|
| 59 | for category in category_list: |
---|
| 60 | self.assertNotEqual(fittingWindow.cbCategory.findText(category),-1) |
---|
| 61 | |
---|
| 62 | #Test what is current text in the combobox |
---|
| 63 | self.assertEqual(fittingWindow.cbCategory.currentText(), CATEGORY_DEFAULT) |
---|
| 64 | |
---|
| 65 | def testWidgetWithData(self): |
---|
| 66 | """ |
---|
| 67 | Test the instantiation of the widget with initial data |
---|
| 68 | """ |
---|
| 69 | data = Data1D(x=[1,2], y=[1,2]) |
---|
| 70 | GuiUtils.dataFromItem = MagicMock(return_value=data) |
---|
| 71 | item = QtGui.QStandardItem("test") |
---|
| 72 | |
---|
[7248d75d] | 73 | widget_with_data = FittingWidget(dummy_manager(), data=[item], id=3) |
---|
[811bec1] | 74 | |
---|
| 75 | self.assertEqual(widget_with_data.data, data) |
---|
| 76 | self.assertTrue(widget_with_data.data_is_loaded) |
---|
[7248d75d] | 77 | # self.assertTrue(widget_with_data.cmdFit.isEnabled()) |
---|
[811bec1] | 78 | self.assertFalse(widget_with_data.acceptsData()) |
---|
| 79 | |
---|
| 80 | def notestSelectModel(self): |
---|
| 81 | """ |
---|
| 82 | Test if models have been loaded properly |
---|
| 83 | :return: |
---|
| 84 | """ |
---|
| 85 | fittingWindow = self.widget |
---|
| 86 | |
---|
| 87 | #Test loading from json categories |
---|
| 88 | model_list = fittingWindow.master_category_dict["Cylinder"] |
---|
| 89 | self.assertTrue(['cylinder', True] in model_list) |
---|
| 90 | self.assertTrue(['core_shell_cylinder', True] in model_list) |
---|
| 91 | self.assertTrue(['barbell', True] in model_list) |
---|
| 92 | self.assertTrue(['core_shell_bicelle', True] in model_list) |
---|
| 93 | self.assertTrue(['flexible_cylinder', True] in model_list) |
---|
| 94 | self.assertTrue(['flexible_cylinder_elliptical', True] in model_list) |
---|
| 95 | self.assertTrue(['pearl_necklace', True] in model_list) |
---|
| 96 | self.assertTrue(['capped_cylinder', True] in model_list) |
---|
| 97 | self.assertTrue(['elliptical_cylinder', True] in model_list) |
---|
| 98 | self.assertTrue(['pringle', True] in model_list) |
---|
| 99 | self.assertTrue(['hollow_cylinder', True] in model_list) |
---|
| 100 | self.assertTrue(['core_shell_bicelle_elliptical', True] in model_list) |
---|
| 101 | self.assertTrue(['stacked_disks', True] in model_list) |
---|
| 102 | |
---|
| 103 | #Test for existence in combobox |
---|
| 104 | self.assertNotEqual(fittingWindow.cbModel.findText("cylinder"),-1) |
---|
| 105 | self.assertNotEqual(fittingWindow.cbModel.findText("core_shell_cylinder"),-1) |
---|
| 106 | self.assertNotEqual(fittingWindow.cbModel.findText("barbell"),-1) |
---|
| 107 | self.assertNotEqual(fittingWindow.cbModel.findText("core_shell_bicelle"),-1) |
---|
| 108 | self.assertNotEqual(fittingWindow.cbModel.findText("flexible_cylinder"),-1) |
---|
| 109 | self.assertNotEqual(fittingWindow.cbModel.findText("flexible_cylinder_elliptical"),-1) |
---|
| 110 | self.assertNotEqual(fittingWindow.cbModel.findText("pearl_necklace"),-1) |
---|
| 111 | self.assertNotEqual(fittingWindow.cbModel.findText("capped_cylinder"),-1) |
---|
| 112 | self.assertNotEqual(fittingWindow.cbModel.findText("elliptical_cylinder"),-1) |
---|
| 113 | self.assertNotEqual(fittingWindow.cbModel.findText("pringle"),-1) |
---|
| 114 | self.assertNotEqual(fittingWindow.cbModel.findText("hollow_cylinder"),-1) |
---|
| 115 | self.assertNotEqual(fittingWindow.cbModel.findText("core_shell_bicelle_elliptical"),-1) |
---|
| 116 | self.assertNotEqual(fittingWindow.cbModel.findText("stacked_disks"),-1) |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | def testSelectPolydispersity(self): |
---|
| 120 | """ |
---|
| 121 | Test if models have been loaded properly |
---|
| 122 | :return: |
---|
| 123 | """ |
---|
| 124 | fittingWindow = self.widget |
---|
| 125 | |
---|
| 126 | #Test loading from json categories |
---|
[7248d75d] | 127 | fittingWindow.SASModelToQModel("cylinder") |
---|
[811bec1] | 128 | pd_index = fittingWindow.lstPoly.model().index(0,0) |
---|
| 129 | self.assertEqual(str(pd_index.data().toString()), "Distribution of radius") |
---|
| 130 | pd_index = fittingWindow.lstPoly.model().index(1,0) |
---|
| 131 | self.assertEqual(str(pd_index.data().toString()), "Distribution of length") |
---|
| 132 | |
---|
| 133 | def testSelectStructureFactor(self): |
---|
| 134 | """ |
---|
| 135 | Test if structure factors have been loaded properly |
---|
| 136 | :return: |
---|
| 137 | """ |
---|
| 138 | fittingWindow = self.widget |
---|
| 139 | |
---|
| 140 | #Test for existence in combobox |
---|
| 141 | self.assertNotEqual(fittingWindow.cbStructureFactor.findText("stickyhardsphere"),-1) |
---|
| 142 | self.assertNotEqual(fittingWindow.cbStructureFactor.findText("hayter_msa"),-1) |
---|
| 143 | self.assertNotEqual(fittingWindow.cbStructureFactor.findText("squarewell"),-1) |
---|
| 144 | self.assertNotEqual(fittingWindow.cbStructureFactor.findText("hardsphere"),-1) |
---|
| 145 | |
---|
| 146 | #Test what is current text in the combobox |
---|
| 147 | self.assertTrue(fittingWindow.cbCategory.currentText(), "None") |
---|
| 148 | |
---|
| 149 | def testSignals(self): |
---|
| 150 | """ |
---|
| 151 | Test the widget exmitted signals |
---|
| 152 | """ |
---|
| 153 | pass |
---|
| 154 | |
---|
| 155 | def testSelectCategory(self): |
---|
| 156 | """ |
---|
| 157 | Assure proper behaviour on changing category |
---|
| 158 | """ |
---|
| 159 | pass |
---|
| 160 | |
---|
| 161 | def testSelectModel(self): |
---|
| 162 | """ |
---|
| 163 | Assure proper behaviour on changing model |
---|
| 164 | """ |
---|
| 165 | pass |
---|
| 166 | |
---|
| 167 | def testSelectFactor(self): |
---|
| 168 | """ |
---|
| 169 | Assure proper behaviour on changing structure factor |
---|
| 170 | """ |
---|
| 171 | pass |
---|
| 172 | |
---|
| 173 | def testReadCategoryInfo(self): |
---|
| 174 | """ |
---|
| 175 | Check the category file reader |
---|
| 176 | """ |
---|
| 177 | pass |
---|
| 178 | |
---|
| 179 | def testUpdateParamsFromModel(self): |
---|
| 180 | """ |
---|
| 181 | Checks the sasmodel parameter update from QModel items |
---|
| 182 | """ |
---|
| 183 | pass |
---|
| 184 | |
---|
| 185 | def testComputeDataRange(self): |
---|
| 186 | """ |
---|
| 187 | Tests the data range calculator on Data1D/Data2D |
---|
| 188 | """ |
---|
| 189 | pass |
---|
| 190 | |
---|
| 191 | def testCreateDefault1dData(self): |
---|
| 192 | """ |
---|
| 193 | Tests the default 1D set |
---|
| 194 | """ |
---|
| 195 | pass |
---|
| 196 | |
---|
| 197 | def testCreateDefault2dData(self): |
---|
| 198 | """ |
---|
| 199 | Tests the default 2D set |
---|
| 200 | """ |
---|
| 201 | pass |
---|
| 202 | |
---|
| 203 | def testCreateTheoryIndex(self): |
---|
| 204 | """ |
---|
| 205 | Test the data->QIndex conversion |
---|
| 206 | """ |
---|
| 207 | pass |
---|
| 208 | |
---|
| 209 | def testCalculate1DForModel(self): |
---|
| 210 | """ |
---|
| 211 | Check that the fitting 1D data object is ready |
---|
| 212 | """ |
---|
| 213 | pass |
---|
| 214 | |
---|
| 215 | def testCalculate2DForModel(self): |
---|
| 216 | """ |
---|
| 217 | Check that the fitting 2D data object is ready |
---|
| 218 | """ |
---|
| 219 | pass |
---|
| 220 | |
---|
| 221 | def testComplete1D(self): |
---|
| 222 | """ |
---|
| 223 | Check that a new 1D plot is generated |
---|
| 224 | """ |
---|
| 225 | pass |
---|
| 226 | |
---|
| 227 | def testComplete2D(self): |
---|
| 228 | """ |
---|
| 229 | Check that a new 2D plot is generated |
---|
| 230 | """ |
---|
| 231 | pass |
---|
| 232 | |
---|
| 233 | def testSetPolyModel(self): |
---|
| 234 | """ |
---|
| 235 | Test the polydispersity model setup |
---|
| 236 | """ |
---|
| 237 | pass |
---|
| 238 | |
---|
| 239 | def testSetMagneticModel(self): |
---|
| 240 | """ |
---|
| 241 | Test the magnetic model setup |
---|
| 242 | """ |
---|
| 243 | pass |
---|
| 244 | |
---|
| 245 | def testAddExtraShells(self): |
---|
| 246 | """ |
---|
| 247 | Test how the extra shells are presented |
---|
| 248 | """ |
---|
| 249 | pass |
---|
| 250 | |
---|
| 251 | def testModifyShellsInList(self): |
---|
| 252 | """ |
---|
| 253 | Test the additional rows added by modifying the shells combobox |
---|
| 254 | """ |
---|
| 255 | pass |
---|
| 256 | |
---|
| 257 | |
---|
| 258 | if __name__ == "__main__": |
---|
| 259 | unittest.main() |
---|