Changes in src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py [3fbd77b:f712bf30] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py
r3fbd77b rf712bf30 18 18 from sas.qtgui.Perspectives.Fitting.FittingWidget import * 19 19 from sas.qtgui.Perspectives.Fitting.Constraint import Constraint 20 20 import sas.qtgui.Utilities.LocalConfig 21 21 from sas.qtgui.UnitTesting.TestUtils import QtSignalSpy 22 from sas.qtgui.Perspectives.Fitting.ModelThread import Calc1D 23 from sas.qtgui.Perspectives.Fitting.ModelThread import Calc2D 22 24 23 25 from sas.qtgui.Plotting.PlotterData import Data1D … … 260 262 self.widget.cbModel.setCurrentIndex(0) 261 263 262 # Observe factor reset to None263 self.assertEqual(self.widget.cbStructureFactor.currentText(), STRUCTURE_DEFAULT)264 # Observe factor doesn't reset to None 265 self.assertEqual(self.widget.cbStructureFactor.currentText(), 'squarewell') 264 266 265 267 # Switch category to structure factor … … 319 321 Check that the fitting 1D data object is ready 320 322 """ 321 # Mock the thread creation 322 threads.deferToThread = MagicMock() 323 # Model for theory 324 self.widget.SASModelToQModel("cylinder") 325 # Call the tested method 326 self.widget.calculateQGridForModel() 327 time.sleep(1) 328 # Test the mock 329 self.assertTrue(threads.deferToThread.called) 330 self.assertEqual(threads.deferToThread.call_args_list[0][0][0].__name__, "compute") 323 324 if LocalConfig.USING_TWISTED: 325 # Mock the thread creation 326 threads.deferToThread = MagicMock() 327 # Model for theory 328 self.widget.SASModelToQModel("cylinder") 329 # Call the tested method 330 self.widget.calculateQGridForModel() 331 time.sleep(1) 332 # Test the mock 333 self.assertTrue(threads.deferToThread.called) 334 self.assertEqual(threads.deferToThread.call_args_list[0][0][0].__name__, "compute") 335 else: 336 Calc2D.queue = MagicMock() 337 # Model for theory 338 self.widget.SASModelToQModel("cylinder") 339 # Call the tested method 340 self.widget.calculateQGridForModel() 341 time.sleep(1) 342 # Test the mock 343 self.assertTrue(Calc2D.queue.called) 331 344 332 345 def testCalculateResiduals(self): … … 417 430 index = self.widget._poly_model.index(0,0) 418 431 419 #self.widget.show()420 #QtWidgets.QApplication(sys.argv).exec_()421 422 432 # Set the checbox 423 433 self.widget._poly_model.item(0,0).setCheckState(2) … … 435 445 self.assertEqual(self.widget.kernel_module.details['radius_bell'][1], 1.0) 436 446 447 #self.widget.show() 448 #QtWidgets.QApplication.exec_() 449 437 450 # Change the number of points 438 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 35)451 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 35) 439 452 self.widget._poly_model.item(0,4).setText("22") 440 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 22)453 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 22) 441 454 # try something stupid 442 455 self.widget._poly_model.item(0,4).setText("butt") 443 456 # see that this didn't annoy the control at all 444 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 22)457 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 22) 445 458 446 459 # Change the number of sigmas 447 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 3)460 self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 3) 448 461 self.widget._poly_model.item(0,5).setText("222") 449 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 222)462 self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 222) 450 463 # try something stupid again 451 464 self.widget._poly_model.item(0,4).setText("beer") 452 465 # no efect 453 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 222)466 self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 222) 454 467 455 468 def testOnPolyComboIndexChange(self): … … 472 485 self.widget.onPolyComboIndexChange('rectangle', 0) 473 486 # check values 474 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 35)475 self.assertAlmostEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 1.73205, 5)487 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 35) 488 self.assertAlmostEqual(self.widget.poly_params['radius_bell.nsigmas'], 1.73205, 5) 476 489 # Change the index 477 490 self.widget.onPolyComboIndexChange('lognormal', 0) 478 491 # check values 479 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 80)480 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 8)492 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 80) 493 self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 8) 481 494 # Change the index 482 495 self.widget.onPolyComboIndexChange('schulz', 0) 483 496 # check values 484 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 80)485 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 8)497 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 80) 498 self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 8) 486 499 487 500 # mock up file load … … 600 613 601 614 # Check that the number of rows increased 615 # (note that n == 1 by default in core_multi_shell so this increases index by 2) 602 616 more_rows = self.widget._model_model.rowCount() - last_row 603 self.assertEqual(more_rows, 6) # 6new rows: 2 params per index604 605 # Backto 0617 self.assertEqual(more_rows, 4) # 4 new rows: 2 params per index 618 619 # Set to 0 606 620 self.widget.lstParams.indexWidget(func_index).setCurrentIndex(0) 607 self.assertEqual(self.widget._model_model.rowCount(), last_row )621 self.assertEqual(self.widget._model_model.rowCount(), last_row - 2) # 2 fewer rows than default 608 622 609 623 def testPlotTheory(self): … … 651 665 self.assertEqual(self.widget.cmdPlot.text(), 'Show Plot') 652 666 653 self.widget.show()654 655 667 # Set data 656 668 test_data = Data1D(x=[1,2], y=[1,2]) 657 669 item = QtGui.QStandardItem() 670 updateModelItem(item, test_data, "test") 658 671 # Force same data into logic 659 self.widget.logic.data = test_data 660 self.widget.data_is_loaded = True 672 self.widget.data = item 661 673 662 674 # Change the category index so we have a model available … … 704 716 self.widget.close() 705 717 718 def testOnEmptyFit2(self): 706 719 test_data = Data2D(image=[1.0, 2.0, 3.0], 707 720 err_image=[0.01, 0.02, 0.03], … … 714 727 item = QtGui.QStandardItem() 715 728 updateModelItem(item, test_data, "test") 729 716 730 # Force same data into logic 717 731 self.widget.data = item … … 731 745 self.widget.close() 732 746 733 734 def testOnFit1D(self): 747 def notestOnFit1D(self): 735 748 """ 736 749 Test the threaded fitting call … … 770 783 self.widget.close() 771 784 772 def testOnFit2D(self):785 def notestOnFit2D(self): 773 786 """ 774 787 Test the threaded fitting call … … 865 878 # Set data 866 879 test_data = Data1D(x=[1,2], y=[1,2]) 867 880 item = QtGui.QStandardItem() 881 updateModelItem(item, test_data, "test") 868 882 # Force same data into logic 869 self.widget.logic.data = test_data 870 self.widget.data_is_loaded = True 883 self.widget.data = item 884 885 # Force same data into logic 871 886 category_index = self.widget.cbCategory.findText('Sphere') 887 872 888 self.widget.cbCategory.setCurrentIndex(category_index) 873 889 self.widget.main_params_to_fit = ['scale'] … … 951 967 # Set data 952 968 test_data = Data1D(x=[1,2], y=[1,2]) 953 969 item = QtGui.QStandardItem() 970 updateModelItem(item, test_data, "test") 954 971 # Force same data into logic 955 self.widget.logic.data = test_data 956 self.widget.data_is_loaded = True 972 self.widget.data = item 957 973 category_index = self.widget.cbCategory.findText("Sphere") 958 974 self.widget.cbCategory.setCurrentIndex(category_index) … … 976 992 # Set data 977 993 test_data = Data1D(x=[1,2], y=[1,2]) 978 994 item = QtGui.QStandardItem() 995 updateModelItem(item, test_data, "test") 979 996 # Force same data into logic 980 self.widget.logic.data = test_data 981 self.widget.data_is_loaded = True 997 self.widget.data = item 982 998 category_index = self.widget.cbCategory.findText("Sphere") 983 999
Note: See TracChangeset
for help on using the changeset viewer.