Changeset 481ff26 in sasview for src/sas/qtgui/UnitTesting/DataExplorerTest.py
- Timestamp:
- Jul 4, 2016 5:32:49 AM (8 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- f0f309d
- Parents:
- f82ab8c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/UnitTesting/DataExplorerTest.py
rf82ab8c r481ff26 49 49 def testDefaults(self): 50 50 '''Test the GUI in its default state''' 51 # Tab widget 51 52 self.assertIsInstance(self.form, QTabWidget) 52 self.assertIsInstance(self.form.treeView, QTreeView)53 self.assertIsInstance(self.form.freezeView, QTreeView)54 53 self.assertEqual(self.form.count(), 2) 55 54 55 # Buttons - data tab 56 56 self.assertEqual(self.form.cmdLoad.text(), "Load") 57 57 self.assertEqual(self.form.cmdDeleteData.text(), "Delete") 58 58 self.assertEqual(self.form.cmdDeleteTheory.text(), "Delete") 59 self.assertEqual(self.form.cmdFreeze.text(), "Freeze") 60 self.assertEqual(self.form.cmdSendTo.text(), "Send to") 59 self.assertEqual(self.form.cmdFreeze.text(), "Freeze Theory") 60 self.assertEqual(self.form.cmdSendTo.text(), "...") 61 self.assertEqual(self.form.cmdSendTo.iconSize(), QSize(32, 32)) 62 self.assertIsInstance(self.form.cmdSendTo.icon(), QIcon) 61 63 self.assertEqual(self.form.chkBatch.text(), "Batch mode") 62 64 self.assertFalse(self.form.chkBatch.isChecked()) 63 65 66 # Buttons - theory tab 67 68 # Combo boxes 64 69 self.assertEqual(self.form.cbSelect.count(), 6) 65 70 self.assertEqual(self.form.cbSelect.currentIndex(), 0) 66 71 67 # Class is in the default state even without pressing OK 72 # Models - data 73 self.assertIsInstance(self.form.model, QStandardItemModel) 68 74 self.assertEqual(self.form.treeView.model().rowCount(), 0) 69 75 self.assertEqual(self.form.treeView.model().columnCount(), 0) 70 76 self.assertEqual(self.form.model.rowCount(), 0) 71 77 self.assertEqual(self.form.model.columnCount(), 0) 78 self.assertIsInstance(self.form.data_proxy, QSortFilterProxyModel) 79 self.assertEqual(self.form.data_proxy.sourceModel(), self.form.model) 80 self.assertEqual("[^()]", str(self.form.data_proxy.filterRegExp().pattern())) 81 self.assertIsInstance(self.form.treeView, QTreeView) 82 83 # Models - theory 84 self.assertIsInstance(self.form.theory_model, QStandardItemModel) 85 self.assertEqual(self.form.freezeView.model().rowCount(), 0) 86 self.assertEqual(self.form.freezeView.model().columnCount(), 0) 87 self.assertEqual(self.form.theory_model.rowCount(), 0) 88 self.assertEqual(self.form.theory_model.columnCount(), 0) 89 self.assertIsInstance(self.form.theory_proxy, QSortFilterProxyModel) 90 self.assertEqual(self.form.theory_proxy.sourceModel(), self.form.theory_model) 91 self.assertEqual("[^()]", str(self.form.theory_proxy.filterRegExp().pattern())) 92 self.assertIsInstance(self.form.freezeView, QTreeView) 93 72 94 73 95 def testLoadButton(self): … … 153 175 QTest.mouseClick(deleteButton, Qt.LeftButton) 154 176 177 def testDeleteTheory(self): 178 """ 179 Test that clicking "Delete" in theories tab removes selected indices 180 """ 181 deleteButton = self.form.cmdDeleteTheory 182 183 # Mock the confirmation dialog with return=No 184 QtGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.No) 185 186 # Populate the model 187 item1 = QtGui.QStandardItem(True) 188 item1.setCheckable(True) 189 item1.setCheckState(QtCore.Qt.Checked) 190 item1.setText("item 1") 191 self.form.theory_model.appendRow(item1) 192 item2 = QtGui.QStandardItem(True) 193 item2.setCheckable(True) 194 item2.setCheckState(QtCore.Qt.Unchecked) 195 item2.setText("item 2") 196 self.form.theory_model.appendRow(item2) 197 198 # Assure the model contains two items 199 self.assertEqual(self.form.theory_model.rowCount(), 2) 200 201 # Assure the checkboxes are on 202 self.assertTrue(item1.checkState() == QtCore.Qt.Checked) 203 self.assertTrue(item2.checkState() == QtCore.Qt.Unchecked) 204 205 # Click on the delete button 206 QTest.mouseClick(deleteButton, Qt.LeftButton) 207 208 # Test the warning dialog called once 209 self.assertTrue(QtGui.QMessageBox.question.called) 210 211 # Assure the model still contains the items 212 self.assertEqual(self.form.theory_model.rowCount(), 2) 213 214 # Now, mock the confirmation dialog with return=Yes 215 QtGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.Yes) 216 217 # Click on the delete button 218 QTest.mouseClick(deleteButton, Qt.LeftButton) 219 220 # Test the warning dialog called once 221 self.assertTrue(QtGui.QMessageBox.question.called) 222 223 # Assure the model contains 1 item 224 self.assertEqual(self.form.theory_model.rowCount(), 1) 225 226 # Set the remaining item to checked 227 self.form.theory_model.item(0).setCheckState(QtCore.Qt.Checked) 228 229 # Click on the delete button again 230 QTest.mouseClick(deleteButton, Qt.LeftButton) 231 232 # Assure the model contains no items 233 self.assertEqual(self.form.theory_model.rowCount(), 0) 234 235 # Click delete once again to assure no nasty behaviour on empty model 236 QTest.mouseClick(deleteButton, Qt.LeftButton) 237 238 155 239 def testSendToButton(self): 156 240 """ … … 253 337 # self.form.cbSelect.setCurrentIndex(6) 254 338 339 def testFreezeTheory(self): 340 """ 341 Assure theory freeze functionality works 342 """ 343 # Not yet tested - agree on design first. 344 pass 345 346 def testRecursivelyCloneItem(self): 347 """ 348 Test the rescursive QAbstractItem/QStandardItem clone 349 """ 350 # Create an item with several branches 351 item1 = QtGui.QStandardItem() 352 item2 = QtGui.QStandardItem() 353 item3 = QtGui.QStandardItem() 354 item4 = QtGui.QStandardItem() 355 item5 = QtGui.QStandardItem() 356 item6 = QtGui.QStandardItem() 357 358 item4.appendRow(item5) 359 item2.appendRow(item4) 360 item2.appendRow(item6) 361 item1.appendRow(item2) 362 item1.appendRow(item3) 363 364 # Clone 365 new_item = self.form.recursivelyCloneItem(item1) 366 367 # assure the trees look identical 368 self.assertEqual(item1.rowCount(), new_item.rowCount()) 369 self.assertEqual(item1.child(0).rowCount(), new_item.child(0).rowCount()) 370 self.assertEqual(item1.child(1).rowCount(), new_item.child(1).rowCount()) 371 self.assertEqual(item1.child(0).child(0).rowCount(), new_item.child(0).child(0).rowCount()) 372 255 373 def testReadData(self): 256 374 """ … … 281 399 self.assertEqual(model_name, filename[0]) 282 400 401 def testDisplayHelp(self): 402 """ 403 Test that the Help window gets shown correctly 404 """ 405 partial_url = "sasgui/guiframe/data_explorer_help.html" 406 button1 = self.form.cmdHelp 407 button2 = self.form.cmdHelp_2 408 409 # Click on the Help button 410 QTest.mouseClick(button1, Qt.LeftButton) 411 qApp.processEvents() 412 413 # Check the browser 414 self.assertIn(partial_url, str(self.form._helpView.url())) 415 # Close the browser 416 self.form._helpView.close() 417 418 # Click on the Help_2 button 419 QTest.mouseClick(button2, Qt.LeftButton) 420 qApp.processEvents() 421 # Check the browser 422 self.assertIn(partial_url, str(self.form._helpView.url())) 423 283 424 def testLoadFile(self): 284 425 """ … … 292 433 Test the list of known extensions 293 434 """ 294 list = self.form.getWlist() 435 w_list = self.form.getWlist() 436 295 437 defaults = 'All (*.*);;canSAS files (*.xml);;SESANS files' +\ 296 438 ' (*.ses);;ASCII files (*.txt);;IGOR 2D files (*.asc);;' +\ 297 439 'IGOR/DAT 2D Q_map files (*.dat);;IGOR 1D files (*.abs);;'+\ 298 440 'HFIR 1D files (*.d1d);;DANSE files (*.sans);;NXS files (*.nxs)' 299 self.assertEqual(defaults, list) 441 default_list = defaults.split(';;') 442 443 for format in default_list: 444 self.assertIn(format, w_list) 300 445 301 446 def testLoadComplete(self):
Note: See TracChangeset
for help on using the changeset viewer.