Changeset 3e8dee3 in sasview for src/sas/qtgui/MainWindow/UnitTesting/DataExplorerTest.py
- Timestamp:
- Nov 8, 2017 7:22:45 AM (6 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:
- 0e80658
- Parents:
- 412e069e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/MainWindow/UnitTesting/DataExplorerTest.py
r99ea1b0 r3e8dee3 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 def setData(self, data_item=None ):39 return True 40 def setData(self, data_item=None, is_batch=False): 40 41 return None 41 42 def title(self): … … 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 … … 181 182 item2 = self.form.model.item(1) 182 183 item3 = self.form.model.item(2) 183 self.assertTrue(item1.checkState() == Qt Core.Qt.Checked)184 self.assertTrue(item2.checkState() == Qt Core.Qt.Checked)185 self.assertTrue(item3.checkState() == Qt Core.Qt.Checked)184 self.assertTrue(item1.checkState() == Qt.Checked) 185 self.assertTrue(item2.checkState() == Qt.Checked) 186 self.assertTrue(item3.checkState() == Qt.Checked) 186 187 187 188 # Click on the delete button … … 189 190 190 191 # Test the warning dialog called once 191 self.assertTrue(Q tGui.QMessageBox.question.called)192 self.assertTrue(QMessageBox.question.called) 192 193 193 194 # Assure the model still contains the items … … 195 196 196 197 # Now, mock the confirmation dialog with return=Yes 197 Q tGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.Yes)198 QMessageBox.question = MagicMock(return_value=QMessageBox.Yes) 198 199 199 200 # Click on the delete button … … 201 202 202 203 # Test the warning dialog called once 203 self.assertTrue(Q tGui.QMessageBox.question.called)204 self.assertTrue(QMessageBox.question.called) 204 205 205 206 # Assure the model contains no items … … 216 217 217 218 # Mock the confirmation dialog with return=No 218 Q tGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.No)219 QMessageBox.question = MagicMock(return_value=QMessageBox.No) 219 220 220 221 # Populate the model 221 item1 = Q tGui.QStandardItem(True)222 item1 = QStandardItem(True) 222 223 item1.setCheckable(True) 223 item1.setCheckState(Qt Core.Qt.Checked)224 item1.setCheckState(Qt.Checked) 224 225 item1.setText("item 1") 225 226 self.form.theory_model.appendRow(item1) 226 item2 = Q tGui.QStandardItem(True)227 item2 = QStandardItem(True) 227 228 item2.setCheckable(True) 228 item2.setCheckState(Qt Core.Qt.Unchecked)229 item2.setCheckState(Qt.Unchecked) 229 230 item2.setText("item 2") 230 231 self.form.theory_model.appendRow(item2) … … 234 235 235 236 # Assure the checkboxes are on 236 self.assertTrue(item1.checkState() == Qt Core.Qt.Checked)237 self.assertTrue(item2.checkState() == Qt Core.Qt.Unchecked)237 self.assertTrue(item1.checkState() == Qt.Checked) 238 self.assertTrue(item2.checkState() == Qt.Unchecked) 238 239 239 240 # Click on the delete button … … 241 242 242 243 # Test the warning dialog called once 243 self.assertTrue(Q tGui.QMessageBox.question.called)244 self.assertTrue(QMessageBox.question.called) 244 245 245 246 # Assure the model still contains the items … … 247 248 248 249 # Now, mock the confirmation dialog with return=Yes 249 Q tGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.Yes)250 QMessageBox.question = MagicMock(return_value=QMessageBox.Yes) 250 251 251 252 # Click on the delete button … … 253 254 254 255 # Test the warning dialog called once 255 self.assertTrue(Q tGui.QMessageBox.question.called)256 self.assertTrue(QMessageBox.question.called) 256 257 257 258 # Assure the model contains 1 item … … 259 260 260 261 # Set the remaining item to checked 261 self.form.theory_model.item(0).setCheckState(Qt Core.Qt.Checked)262 self.form.theory_model.item(0).setCheckState(Qt.Checked) 262 263 263 264 # Click on the delete button again … … 307 308 308 309 # Mock the warning message 309 Q tGui.QMessageBox = MagicMock()310 QMessageBox = MagicMock() 310 311 311 312 # Click on the button … … 313 314 314 315 # Assure the message box popped up 315 Q tGui.QMessageBox.assert_called_once()316 QMessageBox.assert_called_once() 316 317 317 318 def testDataSelection(self): … … 326 327 self.form.cbSelect.setCurrentIndex(1) 327 328 328 self.form.show()329 app.exec_()330 331 329 # Test the current selection 332 330 item1D = self.form.model.item(0) 333 331 item2D = self.form.model.item(1) 334 self.assertTrue(item1D.checkState() == Qt Core.Qt.Unchecked)335 self.assertTrue(item2D.checkState() == Qt Core.Qt.Unchecked)332 self.assertTrue(item1D.checkState() == Qt.Unchecked) 333 self.assertTrue(item2D.checkState() == Qt.Unchecked) 336 334 337 335 # Select all data … … 339 337 340 338 # Test the current selection 341 self.assertTrue(item1D.checkState() == Qt Core.Qt.Checked)342 self.assertTrue(item2D.checkState() == Qt Core.Qt.Checked)339 self.assertTrue(item1D.checkState() == Qt.Checked) 340 self.assertTrue(item2D.checkState() == Qt.Checked) 343 341 344 342 # select 1d data … … 346 344 347 345 # Test the current selection 348 self.assertTrue(item1D.checkState() == Qt Core.Qt.Checked)349 self.assertTrue(item2D.checkState() == Qt Core.Qt.Unchecked)346 self.assertTrue(item1D.checkState() == Qt.Checked) 347 self.assertTrue(item2D.checkState() == Qt.Unchecked) 350 348 351 349 # unselect 1d data … … 353 351 354 352 # Test the current selection 355 self.assertTrue(item1D.checkState() == Qt Core.Qt.Unchecked)356 self.assertTrue(item2D.checkState() == Qt Core.Qt.Unchecked)353 self.assertTrue(item1D.checkState() == Qt.Unchecked) 354 self.assertTrue(item2D.checkState() == Qt.Unchecked) 357 355 358 356 # select 2d data … … 360 358 361 359 # Test the current selection 362 self.assertTrue(item1D.checkState() == Qt Core.Qt.Unchecked)363 self.assertTrue(item2D.checkState() == Qt Core.Qt.Checked)360 self.assertTrue(item1D.checkState() == Qt.Unchecked) 361 self.assertTrue(item2D.checkState() == Qt.Checked) 364 362 365 363 # unselect 2d data … … 367 365 368 366 # Test the current selection 369 self.assertTrue(item1D.checkState() == Qt Core.Qt.Unchecked)370 self.assertTrue(item2D.checkState() == Qt Core.Qt.Unchecked)367 self.assertTrue(item1D.checkState() == Qt.Unchecked) 368 self.assertTrue(item2D.checkState() == Qt.Unchecked) 371 369 372 370 # choose impossible index and assure the code raises … … 386 384 """ 387 385 # Create an item with several branches 388 item1 = Q tGui.QStandardItem()389 item2 = Q tGui.QStandardItem()390 item3 = Q tGui.QStandardItem()391 item4 = Q tGui.QStandardItem()392 item5 = Q tGui.QStandardItem()393 item6 = Q tGui.QStandardItem()386 item1 = QStandardItem() 387 item2 = QStandardItem() 388 item3 = QStandardItem() 389 item4 = QStandardItem() 390 item5 = QStandardItem() 391 item6 = QStandardItem() 394 392 395 393 item4.appendRow(item5) … … 433 431 # The 0th item header should be the name of the file 434 432 model_item = self.form.model.index(0,0) 435 model_name = s tr(self.form.model.data(model_item).toString())433 model_name = self.form.model.data(model_item) 436 434 self.assertEqual(model_name, filename[0]) 437 435 … … 446 444 # Click on the Help button 447 445 QTest.mouseClick(button1, Qt.LeftButton) 448 QtGui.qApp.processEvents()446 qApp.processEvents() 449 447 450 448 # Check the browser … … 455 453 # Click on the Help_2 button 456 454 QTest.mouseClick(button2, Qt.LeftButton) 457 QtGui.qApp.processEvents()455 qApp.processEvents() 458 456 # Check the browser 459 457 self.assertIn(partial_url, str(self.form._helpView.url())) … … 597 595 p_file="cyl_400_20.txt" 598 596 output_object = loader.load(p_file) 599 output_item = Q tGui.QStandardItem()597 output_item = QStandardItem() 600 598 new_data = [(output_item, manager.create_gui_data(output_object[0], p_file))] 601 599 … … 645 643 Assure the model update is correct 646 644 """ 647 good_item = Q tGui.QStandardItem()645 good_item = QStandardItem() 648 646 bad_item = "I'm so bad" 649 647 … … 670 668 671 669 # Pick up the treeview index corresponding to that file 672 index = self.form.treeView.indexAt(Q tCore.QPoint(5,5))670 index = self.form.treeView.indexAt(QPoint(5,5)) 673 671 self.form.show() 674 672
Note: See TracChangeset
for help on using the changeset viewer.