Changeset d48cc19 in sasview for src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py
- Timestamp:
- May 2, 2017 9:04:48 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:
- 02ddfb4
- Parents:
- 0a6e097
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py
r83eb5208 rd48cc19 1 1 import sys 2 2 import unittest 3 import time 3 4 4 5 from PyQt4 import QtGui … … 21 22 22 23 class dummy_manager(object): 23 def communicate(self): 24 return Communicate() 24 communicate = Communicate() 25 25 26 26 class FittingWidgetTest(unittest.TestCase): … … 80 80 self.assertFalse(widget_with_data.acceptsData()) 81 81 82 def notestSelectModel(self):82 def testSelectModel(self): 83 83 """ 84 84 Test if models have been loaded properly 85 :return:86 85 """ 87 86 fittingWindow = self.widget … … 280 279 pass 281 280 282 def notestCreateTheoryIndex(self):281 def testCreateTheoryIndex(self): 283 282 """ 284 283 Test the data->QIndex conversion … … 292 291 293 292 # Create the index 294 self.widget.createTheoryIndex() 295 296 # Check the signal sent 297 print spy 298 299 # Check the index 293 self.widget.createTheoryIndex(Data1D(x=[1,2], y=[1,2])) 294 295 # Make sure the signal has been emitted 296 self.assertEqual(spy.count(), 1) 297 298 # Check the argument type 299 self.assertIsInstance(spy.called()[0]['args'][0], QtGui.QStandardItem) 300 300 301 301 def testCalculateQGridForModel(self): … … 305 305 # Mock the thread creation 306 306 threads.deferToThread = MagicMock() 307 # Model for theory 308 self.widget.SASModelToQModel("cylinder") 307 309 # Call the tested method 308 310 self.widget.calculateQGridForModel() 311 time.sleep(1) 309 312 # Test the mock 310 313 self.assertTrue(threads.deferToThread.called) 311 314 self.assertEqual(threads.deferToThread.call_args_list[0][0][0].__name__, "compute") 312 315 313 def testComplete1D(self): 314 """ 315 Check that a new 1D plot is generated 316 """ 317 # TODO when chisqr method coded 318 pass 319 320 def testComplete2D(self): 321 """ 322 Check that a new 2D plot is generated 323 """ 324 # TODO when chisqr method coded 325 pass 316 def testCalculateResiduals(self): 317 """ 318 Check that the residuals are calculated and plots updated 319 """ 320 test_data = Data1D(x=[1,2], y=[1,2]) 321 322 # Model for theory 323 self.widget.SASModelToQModel("cylinder") 324 # Invoke the tested method 325 self.widget.calculateResiduals(test_data) 326 # Check the Chi2 value - should be undetermined 327 self.assertEqual(self.widget.lblChi2Value.text(), '---') 328 329 # Force same data into logic 330 self.widget.logic.data = test_data 331 self.widget.calculateResiduals(test_data) 332 # Now, the difference is 0, as data is the same 333 self.assertEqual(self.widget.lblChi2Value.text(), '0') 334 335 # Change data 336 test_data_2 = Data1D(x=[1,2], y=[2.1,3.49]) 337 self.widget.logic.data = test_data_2 338 self.widget.calculateResiduals(test_data) 339 # Now, the difference is non-zero 340 self.assertEqual(float(self.widget.lblChi2Value.text()), 1.715) 326 341 327 342 def testSetPolyModel(self): … … 410 425 self.assertEqual(self.widget._model_model.rowCount(), last_row) 411 426 427 def testPlotTheory(self): 428 """ 429 See that theory item can produce a chart 430 """ 431 # By default, the compute/plot button is disabled 432 self.assertFalse(self.widget.cmdPlot.isEnabled()) 433 self.assertEqual(self.widget.cmdPlot.text(), 'Show Plot') 434 435 # Assign a model 436 self.widget.show() 437 # Change the category index so we have a model available 438 category_index = self.widget.cbCategory.findText("Sphere") 439 self.widget.cbCategory.setCurrentIndex(category_index) 440 441 # Check the enablement/text 442 self.assertTrue(self.widget.cmdPlot.isEnabled()) 443 self.assertEqual(self.widget.cmdPlot.text(), 'Calculate') 444 445 # Spying on plot update signal 446 spy = QtSignalSpy(self.widget, self.widget.communicate.plotRequestedSignal) 447 448 # Press Calculate 449 QtTest.QTest.mouseClick(self.widget.cmdPlot, QtCore.Qt.LeftButton) 450 451 # Observe cmdPlot caption change 452 self.assertEqual(self.widget.cmdPlot.text(), 'Show Plot') 453 454 # Make sure the signal has NOT been emitted 455 self.assertEqual(spy.count(), 0) 456 457 # Click again 458 QtTest.QTest.mouseClick(self.widget.cmdPlot, QtCore.Qt.LeftButton) 459 460 # This time, we got the update signal 461 self.assertEqual(spy.count(), 0) 462 463 def testPlotData(self): 464 """ 465 See that data item can produce a chart 466 """ 467 # By default, the compute/plot button is disabled 468 self.assertFalse(self.widget.cmdPlot.isEnabled()) 469 self.assertEqual(self.widget.cmdPlot.text(), 'Show Plot') 470 471 self.widget.show() 472 473 # Set data 474 test_data = Data1D(x=[1,2], y=[1,2]) 475 476 # Force same data into logic 477 self.widget.logic.data = test_data 478 self.widget.data_is_loaded = True 479 480 # Change the category index so we have a model available 481 category_index = self.widget.cbCategory.findText("Sphere") 482 self.widget.cbCategory.setCurrentIndex(category_index) 483 484 # Check the enablement/text 485 self.assertTrue(self.widget.cmdPlot.isEnabled()) 486 self.assertEqual(self.widget.cmdPlot.text(), 'Show Plot') 487 488 # Spying on plot update signal 489 spy = QtSignalSpy(self.widget, self.widget.communicate.plotRequestedSignal) 490 491 # Press Calculate 492 QtTest.QTest.mouseClick(self.widget.cmdPlot, QtCore.Qt.LeftButton) 493 494 # Observe cmdPlot caption did not change 495 self.assertEqual(self.widget.cmdPlot.text(), 'Show Plot') 496 497 # Make sure the signal has been emitted == new plot 498 self.assertEqual(spy.count(), 1) 499 412 500 413 501 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.