Changeset 53c771e in sasview for src/sas/qtgui/MainWindow/UnitTesting/DataExplorerTest.py
- Timestamp:
- Nov 9, 2017 8:45:20 AM (7 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:
- dd150ef
- Parents:
- d6b8a1d
- git-author:
- Piotr Rozyczko <rozyczko@…> (11/08/17 09:22:45)
- git-committer:
- Piotr Rozyczko <rozyczko@…> (11/09/17 08:45:20)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/MainWindow/UnitTesting/DataExplorerTest.py
r7fb471d r53c771e 2 2 import unittest 3 3 4 from PyQt4.QtGui import * 5 from PyQt4.QtTest import QTest 6 from PyQt4.QtCore import * 4 from PyQt5.QtGui import * 5 from PyQt5.QtWidgets import * 6 from PyQt5.QtTest import QTest 7 from PyQt5.QtCore import * 7 8 from unittest.mock import MagicMock 8 9 from unittest.mock import patch … … 36 37 return Communicate() 37 38 def allowBatch(self): 38 return False39 return True 39 40 def setData(self, data_item=None, is_batch=False): 40 41 return None … … 114 115 115 116 # Return no files. 116 Q tGui.QFileDialog.getOpenFileNames = MagicMock(return_value=None)117 QFileDialog.getOpenFileNames = MagicMock(return_value=('','')) 117 118 118 119 # Click on the Load button … … 120 121 121 122 # Test the getOpenFileName() dialog called once 122 self.assertTrue(Q tGui.QFileDialog.getOpenFileNames.called)123 Q tGui.QFileDialog.getOpenFileNames.assert_called_once()123 self.assertTrue(QFileDialog.getOpenFileNames.called) 124 QFileDialog.getOpenFileNames.assert_called_once() 124 125 125 126 # Make sure the signal has not been emitted … … 127 128 128 129 # Now, return a single file 129 Q tGui.QFileDialog.getOpenFileNames = MagicMock(return_value=filename)130 QFileDialog.getOpenFileNames = MagicMock(return_value=(filename,'')) 130 131 131 132 # Click on the Load button 132 133 QTest.mouseClick(loadButton, Qt.LeftButton) 133 QtGui.qApp.processEvents()134 qApp.processEvents() 134 135 135 136 # Test the getOpenFileName() dialog called once 136 self.assertTrue(Q tGui.QFileDialog.getOpenFileNames.called)137 Q tGui.QFileDialog.getOpenFileNames.assert_called_once()137 self.assertTrue(QFileDialog.getOpenFileNames.called) 138 QFileDialog.getOpenFileNames.assert_called_once() 138 139 139 140 # Expected one spy instance … … 167 168 168 169 # Mock the confirmation dialog with return=No 169 Q tGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.No)170 QMessageBox.question = MagicMock(return_value=QMessageBox.No) 170 171 171 172 # Populate the model … … 180 181 item2 = self.form.model.item(1) 181 182 item3 = self.form.model.item(2) 182 self.assertTrue(item1.checkState() == Qt Core.Qt.Checked)183 self.assertTrue(item2.checkState() == Qt Core.Qt.Checked)184 self.assertTrue(item3.checkState() == Qt Core.Qt.Checked)183 self.assertTrue(item1.checkState() == Qt.Checked) 184 self.assertTrue(item2.checkState() == Qt.Checked) 185 self.assertTrue(item3.checkState() == Qt.Checked) 185 186 186 187 # Click on the delete button … … 188 189 189 190 # Test the warning dialog called once 190 self.assertTrue(Q tGui.QMessageBox.question.called)191 self.assertTrue(QMessageBox.question.called) 191 192 192 193 # Assure the model still contains the items … … 194 195 195 196 # Now, mock the confirmation dialog with return=Yes 196 Q tGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.Yes)197 QMessageBox.question = MagicMock(return_value=QMessageBox.Yes) 197 198 198 199 # Click on the delete button … … 200 201 201 202 # Test the warning dialog called once 202 self.assertTrue(Q tGui.QMessageBox.question.called)203 self.assertTrue(QMessageBox.question.called) 203 204 204 205 # Assure the model contains no items … … 215 216 216 217 # Mock the confirmation dialog with return=No 217 Q tGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.No)218 QMessageBox.question = MagicMock(return_value=QMessageBox.No) 218 219 219 220 # Populate the model 220 item1 = Q tGui.QStandardItem(True)221 item1 = QStandardItem(True) 221 222 item1.setCheckable(True) 222 item1.setCheckState(Qt Core.Qt.Checked)223 item1.setCheckState(Qt.Checked) 223 224 item1.setText("item 1") 224 225 self.form.theory_model.appendRow(item1) 225 item2 = Q tGui.QStandardItem(True)226 item2 = QStandardItem(True) 226 227 item2.setCheckable(True) 227 item2.setCheckState(Qt Core.Qt.Unchecked)228 item2.setCheckState(Qt.Unchecked) 228 229 item2.setText("item 2") 229 230 self.form.theory_model.appendRow(item2) … … 233 234 234 235 # Assure the checkboxes are on 235 self.assertTrue(item1.checkState() == Qt Core.Qt.Checked)236 self.assertTrue(item2.checkState() == Qt Core.Qt.Unchecked)236 self.assertTrue(item1.checkState() == Qt.Checked) 237 self.assertTrue(item2.checkState() == Qt.Unchecked) 237 238 238 239 # Click on the delete button … … 240 241 241 242 # Test the warning dialog called once 242 self.assertTrue(Q tGui.QMessageBox.question.called)243 self.assertTrue(QMessageBox.question.called) 243 244 244 245 # Assure the model still contains the items … … 246 247 247 248 # Now, mock the confirmation dialog with return=Yes 248 Q tGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.Yes)249 QMessageBox.question = MagicMock(return_value=QMessageBox.Yes) 249 250 250 251 # Click on the delete button … … 252 253 253 254 # Test the warning dialog called once 254 self.assertTrue(Q tGui.QMessageBox.question.called)255 self.assertTrue(QMessageBox.question.called) 255 256 256 257 # Assure the model contains 1 item … … 258 259 259 260 # Set the remaining item to checked 260 self.form.theory_model.item(0).setCheckState(Qt Core.Qt.Checked)261 self.form.theory_model.item(0).setCheckState(Qt.Checked) 261 262 262 263 # Click on the delete button again … … 306 307 307 308 # Mock the warning message 308 Q tGui.QMessageBox = MagicMock()309 QMessageBox = MagicMock() 309 310 310 311 # Click on the button … … 312 313 313 314 # Assure the message box popped up 314 Q tGui.QMessageBox.assert_called_once()315 QMessageBox.assert_called_once() 315 316 316 317 def testDataSelection(self): … … 325 326 self.form.cbSelect.setCurrentIndex(1) 326 327 327 self.form.show()328 app.exec_()329 330 328 # Test the current selection 331 329 item1D = self.form.model.item(0) 332 330 item2D = self.form.model.item(1) 333 self.assertTrue(item1D.checkState() == Qt Core.Qt.Unchecked)334 self.assertTrue(item2D.checkState() == Qt Core.Qt.Unchecked)331 self.assertTrue(item1D.checkState() == Qt.Unchecked) 332 self.assertTrue(item2D.checkState() == Qt.Unchecked) 335 333 336 334 # Select all data … … 338 336 339 337 # Test the current selection 340 self.assertTrue(item1D.checkState() == Qt Core.Qt.Checked)341 self.assertTrue(item2D.checkState() == Qt Core.Qt.Checked)338 self.assertTrue(item1D.checkState() == Qt.Checked) 339 self.assertTrue(item2D.checkState() == Qt.Checked) 342 340 343 341 # select 1d data … … 345 343 346 344 # Test the current selection 347 self.assertTrue(item1D.checkState() == Qt Core.Qt.Checked)348 self.assertTrue(item2D.checkState() == Qt Core.Qt.Unchecked)345 self.assertTrue(item1D.checkState() == Qt.Checked) 346 self.assertTrue(item2D.checkState() == Qt.Unchecked) 349 347 350 348 # unselect 1d data … … 352 350 353 351 # Test the current selection 354 self.assertTrue(item1D.checkState() == Qt Core.Qt.Unchecked)355 self.assertTrue(item2D.checkState() == Qt Core.Qt.Unchecked)352 self.assertTrue(item1D.checkState() == Qt.Unchecked) 353 self.assertTrue(item2D.checkState() == Qt.Unchecked) 356 354 357 355 # select 2d data … … 359 357 360 358 # Test the current selection 361 self.assertTrue(item1D.checkState() == Qt Core.Qt.Unchecked)362 self.assertTrue(item2D.checkState() == Qt Core.Qt.Checked)359 self.assertTrue(item1D.checkState() == Qt.Unchecked) 360 self.assertTrue(item2D.checkState() == Qt.Checked) 363 361 364 362 # unselect 2d data … … 366 364 367 365 # Test the current selection 368 self.assertTrue(item1D.checkState() == Qt Core.Qt.Unchecked)369 self.assertTrue(item2D.checkState() == Qt Core.Qt.Unchecked)366 self.assertTrue(item1D.checkState() == Qt.Unchecked) 367 self.assertTrue(item2D.checkState() == Qt.Unchecked) 370 368 371 369 # choose impossible index and assure the code raises … … 385 383 """ 386 384 # Create an item with several branches 387 item1 = Q tGui.QStandardItem()388 item2 = Q tGui.QStandardItem()389 item3 = Q tGui.QStandardItem()390 item4 = Q tGui.QStandardItem()391 item5 = Q tGui.QStandardItem()392 item6 = Q tGui.QStandardItem()385 item1 = QStandardItem() 386 item2 = QStandardItem() 387 item3 = QStandardItem() 388 item4 = QStandardItem() 389 item5 = QStandardItem() 390 item6 = QStandardItem() 393 391 394 392 item4.appendRow(item5) … … 432 430 # The 0th item header should be the name of the file 433 431 model_item = self.form.model.index(0,0) 434 model_name = s tr(self.form.model.data(model_item).toString())432 model_name = self.form.model.data(model_item) 435 433 self.assertEqual(model_name, filename[0]) 436 434 … … 445 443 # Click on the Help button 446 444 QTest.mouseClick(button1, Qt.LeftButton) 447 QtGui.qApp.processEvents()445 qApp.processEvents() 448 446 449 447 # Check the browser … … 454 452 # Click on the Help_2 button 455 453 QTest.mouseClick(button2, Qt.LeftButton) 456 QtGui.qApp.processEvents()454 qApp.processEvents() 457 455 # Check the browser 458 456 self.assertIn(partial_url, str(self.form._helpView.url())) … … 596 594 p_file="cyl_400_20.txt" 597 595 output_object = loader.load(p_file) 598 output_item = Q tGui.QStandardItem()596 output_item = QStandardItem() 599 597 new_data = [(output_item, manager.create_gui_data(output_object[0], p_file))] 600 598 … … 644 642 Assure the model update is correct 645 643 """ 646 good_item = Q tGui.QStandardItem()644 good_item = QStandardItem() 647 645 bad_item = "I'm so bad" 648 646 … … 669 667 670 668 # Pick up the treeview index corresponding to that file 671 index = self.form.treeView.indexAt(Q tCore.QPoint(5,5))669 index = self.form.treeView.indexAt(QPoint(5,5)) 672 670 self.form.show() 673 671
Note: See TracChangeset
for help on using the changeset viewer.