Changeset 00b7ddf0 in sasview for src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py
- Timestamp:
- Sep 4, 2018 5:51:03 AM (6 years ago)
- Branches:
- ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 700b03b
- Parents:
- ef3494b3
- git-author:
- Torin Cooper-Bennun <torin.cooper-bennun@…> (07/25/18 12:01:03)
- git-committer:
- Torin Cooper-Bennun <torin.cooper-bennun@…> (09/04/18 05:51:03)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py
r6dbff18 r00b7ddf0 255 255 256 256 # We have 4 more rows now 257 self.assertEqual(self.widget._model_model.rowCount(), rowcount+ 4)257 self.assertEqual(self.widget._model_model.rowCount(), rowcount+5) 258 258 259 259 # Switch models … … 275 275 self.widget.cbStructureFactor.setCurrentIndex(last_index-1) 276 276 # Do we have all the rows? 277 self.assertEqual(self.widget._model_model.rowCount(), 4)277 self.assertEqual(self.widget._model_model.rowCount(), 5) 278 278 279 279 # Are the command buttons properly enabled? … … 496 496 Test opening of the load file dialog for 'array' polydisp. function 497 497 """ 498 499 # open a non-existent file 498 500 filename = os.path.join("UnitTesting", "testdata_noexist.txt") 501 with self.assertRaises(OSError, msg="testdata_noexist.txt should be a non-existent file"): 502 os.stat(filename) 499 503 QtWidgets.QFileDialog.getOpenFileName = MagicMock(return_value=(filename,'')) 500 504 self.widget.show() … … 512 516 513 517 # good file 518 # TODO: this depends on the working directory being src/sas/qtgui, 519 # TODO: which isn't convenient if you want to run this test suite 520 # TODO: individually 514 521 filename = os.path.join("UnitTesting", "testdata.txt") 522 try: 523 os.stat(filename) 524 except OSError: 525 self.assertTrue(False, "testdata.txt does not exist") 515 526 QtWidgets.QFileDialog.getOpenFileName = MagicMock(return_value=(filename,'')) 516 527 … … 1012 1023 1013 1024 # Check the model 1014 self.assertEqual(self.widget._model_model.rowCount(), 6)1025 self.assertEqual(self.widget._model_model.rowCount(), 7) 1015 1026 self.assertEqual(self.widget._model_model.columnCount(), 5) 1016 1027 … … 1128 1139 # two rows selected 1129 1140 index1 = self.widget.lstParams.model().index(1, 0, QtCore.QModelIndex()) 1130 index2 = self.widget.lstParams.model().index( 2, 0, QtCore.QModelIndex())1141 index2 = self.widget.lstParams.model().index(3, 0, QtCore.QModelIndex()) 1131 1142 selection_model = self.widget.lstParams.selectionModel() 1132 1143 selection_model.select(index1, selection_model.Select | selection_model.Rows) … … 1164 1175 # several random parameters 1165 1176 self.assertEqual(self.widget.getRowFromName('scale'), 0) 1166 self.assertEqual(self.widget.getRowFromName('length'), 5)1177 self.assertEqual(self.widget.getRowFromName('length'), 6) 1167 1178 1168 1179 def testGetParamNames(self): … … 1201 1212 # Create a constraint object 1202 1213 const = Constraint(parent=None, value=7.0) 1203 row = 21214 row = 3 1204 1215 1205 1216 spy = QtSignalSpy(self.widget, self.widget.constraintAddedSignal) … … 1220 1231 # assign complex constraint now 1221 1232 const = Constraint(parent=None, param='radius', func='5*sld') 1222 row = 41233 row = 5 1223 1234 # call the method tested 1224 1235 self.widget.addConstraintToRow(constraint=const, row=row) … … 1279 1290 self.widget.cbModel.setCurrentIndex(model_index) 1280 1291 1292 row1 = 1 1293 row2 = 5 1294 1295 param1 = "background" 1296 param2 = "radius" 1297 1298 #default_value1 = "0.001" 1299 default_value2 = "20" 1300 1281 1301 # select two rows 1282 row1 = 11283 row2 = 41284 1302 index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 1285 1303 index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) … … 1298 1316 1299 1317 # delete one of the constraints 1300 self.widget.deleteConstraintOnParameter(param= 'background')1318 self.widget.deleteConstraintOnParameter(param=param1) 1301 1319 1302 1320 # see that the other constraint is still present 1303 cons = self.widget.getConstraintForRow( 4) # 4 = radius1304 self.assertEqual(cons.param, "radius")1305 self.assertEqual(cons.value, "20")1321 cons = self.widget.getConstraintForRow(row2) 1322 self.assertEqual(cons.param, param2) 1323 self.assertEqual(cons.value, default_value2) 1306 1324 1307 1325 # kill the other constraint … … 1309 1327 1310 1328 # see that the other constraint is still present 1311 self.assertEqual(self.widget.getConstraintsForModel(), [( 'radius', None)])1329 self.assertEqual(self.widget.getConstraintsForModel(), [(param2, None)]) 1312 1330 1313 1331 def testGetConstraintForRow(self): … … 1329 1347 self.widget.cbModel.setCurrentIndex(model_index) 1330 1348 1349 row1 = 1 1350 row2 = 5 1351 1331 1352 # select two rows 1332 row1 = 11333 row2 = 41334 1353 index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 1335 1354 index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) … … 1341 1360 self.widget.addSimpleConstraint() 1342 1361 1343 con_list = [False, True, False, False, True, False]1362 con_list = [False, True, False, False, False, True, False] 1344 1363 new_list = [] 1345 1364 for row in range(self.widget._model_model.rowCount()): … … 1359 1378 self.widget.cbModel.setCurrentIndex(model_index) 1360 1379 1380 row1 = 1 1381 row2 = 5 1382 1361 1383 # select two rows 1362 row1 = 11363 row2 = 41364 1384 index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 1365 1385 index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) … … 1375 1395 constraint_objects[0].active = False 1376 1396 1377 con_list = [False, False, False, False, True, False]1397 con_list = [False, False, False, False, False, True, False] 1378 1398 new_list = [] 1379 1399 for row in range(self.widget._model_model.rowCount()): … … 1396 1416 self.assertEqual(self.widget.getConstraintsForModel(),[]) 1397 1417 1418 row1 = 1 1419 row2 = 5 1420 1421 param1 = "background" 1422 param2 = "radius" 1423 1424 default_value1 = "0.001" 1425 default_value2 = "20" 1426 1398 1427 # select two rows 1399 row1 = 11400 row2 = 41401 1428 index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 1402 1429 index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) … … 1410 1437 # simple constraints 1411 1438 # self.assertEqual(self.widget.getConstraintsForModel(), [('background', '0.001'), ('radius', '20')]) 1412 cons = self.widget.getConstraintForRow( 1) # 1 - background1413 self.assertEqual(cons.param, "background")1414 self.assertEqual(cons.value, "0.001")1415 cons = self.widget.getConstraintForRow( 4) # 4 = radius1416 self.assertEqual(cons.param, "radius")1417 self.assertEqual(cons.value, "20")1439 cons = self.widget.getConstraintForRow(row1) 1440 self.assertEqual(cons.param, param1) 1441 self.assertEqual(cons.value, default_value1) 1442 cons = self.widget.getConstraintForRow(row2) 1443 self.assertEqual(cons.param, param2) 1444 self.assertEqual(cons.value, default_value2) 1418 1445 1419 1446 objects = self.widget.getConstraintObjectsForModel() 1420 1447 self.assertEqual(len(objects), 2) 1421 self.assertEqual(objects[1].value, '20') 1422 self.assertEqual(objects[0].param, 'background') 1448 self.assertEqual(objects[1].value, default_value2) 1449 self.assertEqual(objects[0].param, param1) 1450 1451 row = 0 1452 param = "scale" 1453 func = "5*sld" 1423 1454 1424 1455 # add complex constraint 1425 const = Constraint(parent=None, param='scale', func='5*sld') 1426 row = 0 1456 const = Constraint(parent=None, param=param, func=func) 1427 1457 self.widget.addConstraintToRow(constraint=const, row=row) 1428 1458 #self.assertEqual(self.widget.getConstraintsForModel(),[('scale', '5*sld'), ('background', '0.001'), ('radius', None)]) 1429 cons = self.widget.getConstraintForRow( 4) # 4 = radius1430 self.assertEqual(cons.param, "radius")1431 self.assertEqual(cons.value, "20")1459 cons = self.widget.getConstraintForRow(row2) 1460 self.assertEqual(cons.param, param2) 1461 self.assertEqual(cons.value, default_value2) 1432 1462 1433 1463 objects = self.widget.getConstraintObjectsForModel() 1434 1464 self.assertEqual(len(objects), 3) 1435 self.assertEqual(objects[0].func, '5*sld')1465 self.assertEqual(objects[0].func, func) 1436 1466 1437 1467 def testReplaceConstraintName(self):
Note: See TracChangeset
for help on using the changeset viewer.